Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions db/migrations/1660901233635-issueAmountChange.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = class issueAmountChange1660901233635 {
name = 'issueAmountChange1660901233635'
Comment thread
nud3l marked this conversation as resolved.

async up(db) {
Comment thread
nud3l marked this conversation as resolved.
await db.query(`CREATE TABLE "issue_amount_change" ("id" character varying NOT NULL, "amount_wrapped" numeric NOT NULL, "bridge_fee_wrapped" numeric NOT NULL, "confiscated_griefing_collateral" numeric NOT NULL, "issue_id" character varying NOT NULL, "height_id" character varying NOT NULL, CONSTRAINT "REL_21486353e717585b8cc4f7a24f" UNIQUE ("issue_id"), CONSTRAINT "PK_1c925ed7ba22247dc6dee12d177" PRIMARY KEY ("id"))`)
await db.query(`CREATE UNIQUE INDEX "IDX_21486353e717585b8cc4f7a24f" ON "issue_amount_change" ("issue_id") `)
Comment thread
nud3l marked this conversation as resolved.
await db.query(`CREATE INDEX "IDX_ff4351c8e40604805832e15fdb" ON "issue_amount_change" ("height_id") `)
Comment thread
nud3l marked this conversation as resolved.
await db.query(`ALTER TABLE "issue_amount_change" ADD CONSTRAINT "FK_21486353e717585b8cc4f7a24fc" FOREIGN KEY ("issue_id") REFERENCES "issue"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
await db.query(`ALTER TABLE "issue_amount_change" ADD CONSTRAINT "FK_ff4351c8e40604805832e15fdbb" FOREIGN KEY ("height_id") REFERENCES "height"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
Comment thread
nud3l marked this conversation as resolved.
}
Comment thread
nud3l marked this conversation as resolved.

async down(db) {
await db.query(`DROP TABLE "issue_amount_change"`)
Comment thread
nud3l marked this conversation as resolved.
await db.query(`DROP INDEX "public"."IDX_21486353e717585b8cc4f7a24f"`)
Comment thread
nud3l marked this conversation as resolved.
await db.query(`DROP INDEX "public"."IDX_ff4351c8e40604805832e15fdb"`)
Comment thread
nud3l marked this conversation as resolved.
await db.query(`ALTER TABLE "issue_amount_change" DROP CONSTRAINT "FK_21486353e717585b8cc4f7a24fc"`)
Comment thread
nud3l marked this conversation as resolved.
await db.query(`ALTER TABLE "issue_amount_change" DROP CONSTRAINT "FK_ff4351c8e40604805832e15fdbb"`)
Comment thread
nud3l marked this conversation as resolved.
}
}
6 changes: 6 additions & 0 deletions indexer/kintsugi.chainVersions.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion kintsugi.typegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"issue.CancelIssue",
"issue.ExecuteIssue",
"issue.IssuePeriodChange",
"issue.IssueAmountChange",
"issue.RequestIssue",
"oracle.FeedValues",
"redeem.CancelRedeem",
Expand All @@ -28,4 +29,4 @@
"Issue.IssuePeriod",
"Redeem.RedeemPeriod"
]
}
}
9 changes: 9 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type Issue @entity {
backingPayment: IssuePayment @derivedFrom(field: "issue")
status: IssueStatus @index # TODO: find a way to optimise queries by status
execution: IssueExecution @derivedFrom(field: "issue")
amountChange: IssueAmountChange @derivedFrom(field: "issue")
cancellation: IssueCancellation @derivedFrom(field: "issue")
refund: Refund @derivedFrom(field: "issue")
}
Expand Down Expand Up @@ -102,6 +103,14 @@ type IssueExecution @entity {
timestamp: DateTime!
}

type IssueAmountChange @entity {
issue: Issue! @unique
amountWrapped: BigInt!
bridgeFeeWrapped: BigInt!
confiscatedGriefingCollateral: BigInt!
height: Height!
}

type IssueCancellation @entity {
issue: Issue! @unique
height: Height!
Expand Down
31 changes: 31 additions & 0 deletions src/mappings/event/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Issue,
IssueCancellation,
IssueExecution,
IssueAmountChange,
IssuePeriod,
IssueRequest,
IssueStatus,
Expand All @@ -16,6 +17,7 @@ import {
IssueCancelIssueEvent,
IssueExecuteIssueEvent,
IssueIssuePeriodChangeEvent,
IssueIssueAmountChangeEvent,
IssueRequestIssueEvent,
RefundExecuteRefundEvent,
RefundRequestRefundEvent,
Expand Down Expand Up @@ -304,3 +306,32 @@ export async function issuePeriodChange(

await ctx.store.save(issuePeriod);
}

export async function issueAmountChange(ctx: EventHandlerContext): Promise<void> {
const rawEvent = new IssueIssueAmountChangeEvent(ctx);
const e = rawEvent.asLatest;

const id = toHex(e.issueId);

const issue = await ctx.store.get(Issue, { where: { id } });
if (issue === undefined) {
debug(
"WARNING: IssueAmountChange event did not match any existing issue requests! Skipping."
);
return;
}
const height = await blockToHeight(
ctx.store,
ctx.block.height,
"IssueAmountChange"
);
const amountChanged = new IssueAmountChange({
id: issue.id,
issue,
amountWrapped: e.amount,
bridgeFeeWrapped: e.fee,
height,
});
await ctx.store.save(amountChanged);
await ctx.store.save(issue);
}
2 changes: 1 addition & 1 deletion src/model/generated/_nativeToken.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "assert"
import * as marshal from "./marshal"
import {Token} from "./_token"
import { Token } from "./_token"

export class NativeToken {
public readonly isTypeOf = 'NativeToken'
Expand Down
1 change: 1 addition & 0 deletions src/model/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from "./_issueRequest"
export * from "./_issueStatus"
export * from "./issuePayment.model"
export * from "./issueExecution.model"
export * from "./issueAmountChange.model"
export * from "./issueCancellation.model"
export * from "./refund.model"
export * from "./redeem.model"
Expand Down
4 changes: 4 additions & 0 deletions src/model/generated/issue.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {IssuePeriod} from "./issuePeriod.model"
import {IssuePayment} from "./issuePayment.model"
import {IssueStatus} from "./_issueStatus"
import {IssueExecution} from "./issueExecution.model"
import {IssueAmountChange} from "./issueAmountChange.model"
import {IssueCancellation} from "./issueCancellation.model"
import {Refund} from "./refund.model"

Expand Down Expand Up @@ -51,6 +52,9 @@ export class Issue {
@OneToOne_(() => IssueExecution)
execution!: IssueExecution | undefined | null

@OneToOne_(() => IssueAmountChange)
amountChange!: IssueAmountChange | undefined | null

@OneToOne_(() => IssueCancellation)
cancellation!: IssueCancellation | undefined | null

Expand Down
32 changes: 32 additions & 0 deletions src/model/generated/issueAmountChange.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, OneToOne as OneToOne_, Index as Index_, JoinColumn as JoinColumn_, ManyToOne as ManyToOne_} from "typeorm"
import * as marshal from "./marshal"
import {Issue} from "./issue.model"
import {Height} from "./height.model"
Comment thread
nud3l marked this conversation as resolved.

@Entity_()
export class IssueAmountChange {
constructor(props?: Partial<IssueAmountChange>) {
Object.assign(this, props)
Comment thread
nud3l marked this conversation as resolved.
}
Comment thread
nud3l marked this conversation as resolved.

@PrimaryColumn_()
id!: string

@Index_({unique: true})
@OneToOne_(() => Issue, {nullable: false})
@JoinColumn_()
Comment thread
nud3l marked this conversation as resolved.
issue!: Issue
Comment thread
nud3l marked this conversation as resolved.

@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
Comment thread
nud3l marked this conversation as resolved.
amountWrapped!: bigint
Comment thread
nud3l marked this conversation as resolved.

@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
bridgeFeeWrapped!: bigint
Comment thread
nud3l marked this conversation as resolved.

@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
confiscatedGriefingCollateral!: bigint
Comment thread
nud3l marked this conversation as resolved.

@Index_()
@ManyToOne_(() => Height, {nullable: false})
Comment thread
nud3l marked this conversation as resolved.
height!: Height
Comment thread
nud3l marked this conversation as resolved.
}
2 changes: 2 additions & 0 deletions src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
findAndUpdateExpiredRequests,
increaseLockedCollateral,
issuePeriodChange,
issueAmountChange,
redeemPeriodChange,
registerVault,
requestIssue,
Expand Down Expand Up @@ -48,6 +49,7 @@ processor.addEventHandler("issue.CancelIssue", cancelIssue);
processor.addEventHandler("issue.ExecuteIssue", executeIssue);
processor.addEventHandler("issue.RequestIssue", requestIssue);
processor.addEventHandler("issue.IssuePeriodChange", issuePeriodChange);
processor.addEventHandler("issue.IssueAmountChange", issueAmountChange);
processor.addEventHandler("oracle.FeedValues", feedValues);
processor.addEventHandler("redeem.CancelRedeem", cancelRedeem);
processor.addEventHandler("redeem.ExecuteRedeem", executeRedeem);
Expand Down
34 changes: 34 additions & 0 deletions src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,40 @@ export class IssueExecuteIssueEvent {
}
}

export class IssueIssueAmountChangeEvent {
constructor(private ctx: EventContext) {
assert(this.ctx.event.name === 'issue.IssueAmountChange')
}

get isV1(): boolean {
return this.ctx._chain.getEventHash('issue.IssueAmountChange') === '426271b0ff71255c125e9a4ea897d86d39682c8454bbff4c6c9a8d50e0d966a4'
}

get asV1(): [Uint8Array, bigint, bigint, bigint] {
assert(this.isV1)
return this.ctx._chain.decodeEvent(this.ctx.event)
}

get isV4(): boolean {
return this.ctx._chain.getEventHash('issue.IssueAmountChange') === 'd4db9e803afab73bfc3e51de57bb3cab34cbb49ee15550d4984bcbe248bb76fc'
}

get asV4(): {issueId: v4.H256, amount: bigint, fee: bigint, confiscatedGriefingCollateral: bigint} {
assert(this.isV4)
return this.ctx._chain.decodeEvent(this.ctx.event)
}

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

get asLatest(): {issueId: v4.H256, amount: bigint, fee: bigint, confiscatedGriefingCollateral: bigint} {
deprecateLatest()
return this.asV4
}
}

export class IssueIssuePeriodChangeEvent {
constructor(private ctx: EventContext) {
assert(this.ctx.event.name === 'issue.IssuePeriodChange')
Expand Down
3 changes: 2 additions & 1 deletion testnet.typegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"issue.CancelIssue",
"issue.ExecuteIssue",
"issue.IssuePeriodChange",
"issue.IssueAmountChange",
"issue.RequestIssue",
"oracle.FeedValues",
"redeem.CancelRedeem",
Expand All @@ -28,4 +29,4 @@
"Issue.IssuePeriod",
"Redeem.RedeemPeriod"
]
}
}