Skip to content

Commit

Permalink
Upgrade for zeitgeist-v0.3.4 (#138)
Browse files Browse the repository at this point in the history
* Generate metadata for v37 & v38

* Get changes to events from metadata

* Accomodate null value for max_price

* Accomodate market mdm change to disputeMechanism

* Debug specVersion
  • Loading branch information
saboonikhil committed Jul 29, 2022
1 parent 5f66851 commit 267514a
Show file tree
Hide file tree
Showing 6 changed files with 334 additions and 19 deletions.
7 changes: 6 additions & 1 deletion src/processor/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,10 +845,15 @@ function getCreatedEvent(ctx: EventHandlerContext): CreatedEvent {
const accountId = ""
const market = param1.value as t_Market
return { marketId, accountId, market }
} else {
} else if (ctx.block.runtimeVersion.specVersion < 38 ) {
const accountId = param1.value as String
const market = param2.value as t_Market
return { marketId, accountId, market }
} else {
const accountId = param1.value as String
var market = param2.value as any
market.mdm = market.disputeMechanism
return { marketId, accountId, market }
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/processor/swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,8 @@ export async function swapExactAmountIn(ctx: EventHandlerContext) {
newAssetQty = oldAssetQty + BigInt(swapEvent.assetAmountIn.toString())
} else if (extrinsic?.args[0].name === "calls") {
for (var ext of extrinsic.args[0].value as Array<{ args: { pool_id: number, asset_in: string, max_price: number }}> ) {
const { args: { asset_in, pool_id, max_price } } = ext;
if (pool_id == +swapEvent.cpep.poolId.toString() && wt!.assetId == JSON.stringify(asset_in)
&& max_price == +swapEvent.maxPrice.toString()) {
const { args: { asset_in, pool_id } } = ext;
if (pool_id == +swapEvent.cpep.poolId.toString() && wt!.assetId == JSON.stringify(asset_in)) {
newAssetQty = oldAssetQty + BigInt(swapEvent.assetAmountIn.toString())
break
}
Expand Down Expand Up @@ -328,9 +327,8 @@ export async function swapExactAmountOut(ctx: EventHandlerContext) {
newAssetQty = oldAssetQty - BigInt(swapEvent.assetAmountOut.toString())
} else if (extrinsic?.args[0].name === "calls") {
for (var ext of extrinsic.args[0].value as Array<{ args: { pool_id: number, asset_out: string, max_price: number }}> ) {
const { args: { asset_out, pool_id, max_price } } = ext;
if (pool_id == +swapEvent.cpep.poolId.toString() && wt!.assetId == JSON.stringify(asset_out)
&& max_price == +swapEvent.maxPrice.toString()) {
const { args: { asset_out, pool_id } } = ext;
if (pool_id == +swapEvent.cpep.poolId.toString() && wt!.assetId == JSON.stringify(asset_out)) {
newAssetQty = oldAssetQty - BigInt(swapEvent.assetAmountOut.toString())
break
}
Expand Down
86 changes: 74 additions & 12 deletions src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import * as v33 from './v33'
import * as v34 from './v34'
import * as v35 from './v35'
import * as v36 from './v36'
import * as v37 from './v37'
import * as v38 from './v38'

export class BalancesBalanceSetEvent {
constructor(private ctx: EventContext) {
Expand Down Expand Up @@ -705,14 +707,29 @@ export class PredictionMarketsMarketCreatedEvent {
return this.ctx._chain.decodeEvent(this.ctx.event)
}

/**
* A market has been created \[market_id, market_account, creator\]
*/
get isV38(): boolean {
return this.ctx._chain.getEventHash('predictionMarkets.MarketCreated') === '488c431f3ef8fe03fd2416a52daf8f4e3d1110218007b6732ba0744f05c3d887'
}

/**
* A market has been created \[market_id, market_account, creator\]
*/
get asV38(): [bigint, v38.AccountId32, v38.Market] {
assert(this.isV38)
return this.ctx._chain.decodeEvent(this.ctx.event)
}

get isLatest(): boolean {
deprecateLatest()
return this.isV36
return this.isV38
}

get asLatest(): [bigint, v36.AccountId32, v36.Market] {
get asLatest(): [bigint, v38.AccountId32, v38.Market] {
deprecateLatest()
return this.asV36
return this.asV38
}
}

Expand Down Expand Up @@ -1121,14 +1138,29 @@ export class SwapsPoolCreateEvent {
return this.ctx._chain.decodeEvent(this.ctx.event)
}

/**
* A new pool has been created. \[CommonPoolEventParams, pool, pool_amount, pool_account\]
*/
get isV37(): boolean {
return this.ctx._chain.getEventHash('swaps.PoolCreate') === 'e1ae211df35be8d001750987f0bbbe15272a62749a5327048eb46ae20f7c3089'
}

/**
* A new pool has been created. \[CommonPoolEventParams, pool, pool_amount, pool_account\]
*/
get asV37(): [v37.CommonPoolEventParams, v37.Pool, bigint, v37.AccountId32] {
assert(this.isV37)
return this.ctx._chain.decodeEvent(this.ctx.event)
}

get isLatest(): boolean {
deprecateLatest()
return this.isV36
return this.isV37
}

get asLatest(): [v36.CommonPoolEventParams, v36.Pool, bigint, v36.AccountId32] {
get asLatest(): [v37.CommonPoolEventParams, v37.Pool, bigint, v37.AccountId32] {
deprecateLatest()
return this.asV36
return this.asV37
}
}

Expand Down Expand Up @@ -1289,14 +1321,29 @@ export class SwapsSwapExactAmountInEvent {
return this.ctx._chain.decodeEvent(this.ctx.event)
}

/**
* An exact amount of an asset is entering the pool. \[SwapEvent\]
*/
get isV37(): boolean {
return this.ctx._chain.getEventHash('swaps.SwapExactAmountIn') === '06fe2e32873a59e751b617c21a3b9e60e7846f1d65de4b22e2494c006b11352e'
}

/**
* An exact amount of an asset is entering the pool. \[SwapEvent\]
*/
get asV37(): v37.SwapEvent {
assert(this.isV37)
return this.ctx._chain.decodeEvent(this.ctx.event)
}

get isLatest(): boolean {
deprecateLatest()
return this.isV32
return this.isV37
}

get asLatest(): v32.SwapEvent {
get asLatest(): v37.SwapEvent {
deprecateLatest()
return this.asV32
return this.asV37
}
}

Expand Down Expand Up @@ -1335,14 +1382,29 @@ export class SwapsSwapExactAmountOutEvent {
return this.ctx._chain.decodeEvent(this.ctx.event)
}

/**
* An exact amount of an asset is leaving the pool. \[SwapEvent\]
*/
get isV37(): boolean {
return this.ctx._chain.getEventHash('swaps.SwapExactAmountOut') === 'ed8ebcec20259e81859ebfe9d4501c49ce0f02e81d7ac4fea993e62e8646987d'
}

/**
* An exact amount of an asset is leaving the pool. \[SwapEvent\]
*/
get asV37(): v37.SwapEvent {
assert(this.isV37)
return this.ctx._chain.decodeEvent(this.ctx.event)
}

get isLatest(): boolean {
deprecateLatest()
return this.isV32
return this.isV37
}

get asLatest(): v32.SwapEvent {
get asLatest(): v37.SwapEvent {
deprecateLatest()
return this.asV32
return this.asV37
}
}

Expand Down
95 changes: 95 additions & 0 deletions src/types/v37.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import type {Result} from './support'

export interface CommonPoolEventParams {
poolId: bigint
who: AccountId32
}

export interface Pool {
assets: Asset[]
baseAsset: Asset
marketId: bigint
poolStatus: PoolStatus
scoringRule: ScoringRule
swapFee: (bigint | undefined)
totalSubsidy: (bigint | undefined)
totalWeight: (bigint | undefined)
weights: ([Asset, bigint][] | undefined)
}

export type AccountId32 = Uint8Array

export interface SwapEvent {
assetAmountIn: bigint
assetAmountOut: bigint
assetBound: (bigint | undefined)
assetIn: Asset
assetOut: Asset
cpep: CommonPoolEventParams
maxPrice: (bigint | undefined)
}

export type Asset = Asset_CategoricalOutcome | Asset_ScalarOutcome | Asset_CombinatorialOutcome | Asset_PoolShare | Asset_Ztg

export interface Asset_CategoricalOutcome {
__kind: 'CategoricalOutcome'
value: [bigint, number]
}

export interface Asset_ScalarOutcome {
__kind: 'ScalarOutcome'
value: [bigint, ScalarPosition]
}

export interface Asset_CombinatorialOutcome {
__kind: 'CombinatorialOutcome'
}

export interface Asset_PoolShare {
__kind: 'PoolShare'
value: SerdeWrapper
}

export interface Asset_Ztg {
__kind: 'Ztg'
}

export type PoolStatus = PoolStatus_Active | PoolStatus_CollectingSubsidy | PoolStatus_Closed | PoolStatus_Clean

export interface PoolStatus_Active {
__kind: 'Active'
}

export interface PoolStatus_CollectingSubsidy {
__kind: 'CollectingSubsidy'
}

export interface PoolStatus_Closed {
__kind: 'Closed'
}

export interface PoolStatus_Clean {
__kind: 'Clean'
}

export type ScoringRule = ScoringRule_CPMM | ScoringRule_RikiddoSigmoidFeeMarketEma

export interface ScoringRule_CPMM {
__kind: 'CPMM'
}

export interface ScoringRule_RikiddoSigmoidFeeMarketEma {
__kind: 'RikiddoSigmoidFeeMarketEma'
}

export type ScalarPosition = ScalarPosition_Long | ScalarPosition_Short

export interface ScalarPosition_Long {
__kind: 'Long'
}

export interface ScalarPosition_Short {
__kind: 'Short'
}

export type SerdeWrapper = bigint
Loading

0 comments on commit 267514a

Please sign in to comment.