Skip to content

Commit

Permalink
feat: added support of DCA action with Swapped events
Browse files Browse the repository at this point in the history
  • Loading branch information
mckrava committed Jan 14, 2025
1 parent c7705f7 commit bafb0b8
Show file tree
Hide file tree
Showing 29 changed files with 13,569 additions and 3,263 deletions.
10 changes: 7 additions & 3 deletions indexers/liquidity-pools/.env.hydration-paseo-next.local
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ PROCESS_STABLEPOOLS=true
PROCESS_DCA=true
PROCESS_OTC=true

PROCESS_FROM_BLOCK=65721
#PROCESS_FROM_BLOCK=31268
PROCESS_TO_BLOCK=65821
#PROCESS_FROM_BLOCK=65721 # OTC
##PROCESS_FROM_BLOCK=31268
#PROCESS_TO_BLOCK=65821

PROCESS_FROM_BLOCK=73838 # DCA
PROCESS_FROM_BLOCK=101356 # DCA omnipool
##PROCESS_TO_BLOCK=74000

OMNIPOOL_ADDRESS=0x6d6f646c6f6d6e69706f6f6c0000000000000000000000000000000000000000

Expand Down
25 changes: 25 additions & 0 deletions indexers/liquidity-pools/db/migrations/1736694847383-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = class Data1736694847383 {
name = 'Data1736694847383'

async up(db) {
await db.query(`ALTER TABLE "chain_activity_trace" DROP CONSTRAINT "FK_26c2eb8e87337934308e440e2de"`)
await db.query(`DROP INDEX "public"."IDX_26c2eb8e87337934308e440e2d"`)
await db.query(`CREATE TABLE "chain_activity_trace_relation" ("id" character varying NOT NULL, "created_at_para_chain_block_height" integer NOT NULL, "child_trace_id" character varying, "parent_trace_id" character varying, CONSTRAINT "PK_a5284175c0ed2afaf3703b9cd07" PRIMARY KEY ("id"))`)
await db.query(`CREATE INDEX "IDX_6be7f6950fe25222e68a9ccde4" ON "chain_activity_trace_relation" ("child_trace_id") `)
await db.query(`CREATE INDEX "IDX_e140c24845ed82e99ec4a65c15" ON "chain_activity_trace_relation" ("parent_trace_id") `)
await db.query(`ALTER TABLE "chain_activity_trace" DROP COLUMN "root_trace_id"`)
await db.query(`ALTER TABLE "chain_activity_trace_relation" ADD CONSTRAINT "FK_6be7f6950fe25222e68a9ccde4e" FOREIGN KEY ("child_trace_id") REFERENCES "chain_activity_trace"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
await db.query(`ALTER TABLE "chain_activity_trace_relation" ADD CONSTRAINT "FK_e140c24845ed82e99ec4a65c155" FOREIGN KEY ("parent_trace_id") REFERENCES "chain_activity_trace"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
}

async down(db) {
await db.query(`ALTER TABLE "chain_activity_trace" ADD CONSTRAINT "FK_26c2eb8e87337934308e440e2de" FOREIGN KEY ("root_trace_id") REFERENCES "chain_activity_trace"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
await db.query(`CREATE INDEX "IDX_26c2eb8e87337934308e440e2d" ON "chain_activity_trace" ("root_trace_id") `)
await db.query(`DROP TABLE "chain_activity_trace_relation"`)
await db.query(`DROP INDEX "public"."IDX_6be7f6950fe25222e68a9ccde4"`)
await db.query(`DROP INDEX "public"."IDX_e140c24845ed82e99ec4a65c15"`)
await db.query(`ALTER TABLE "chain_activity_trace" ADD "root_trace_id" character varying`)
await db.query(`ALTER TABLE "chain_activity_trace_relation" DROP CONSTRAINT "FK_6be7f6950fe25222e68a9ccde4e"`)
await db.query(`ALTER TABLE "chain_activity_trace_relation" DROP CONSTRAINT "FK_e140c24845ed82e99ec4a65c155"`)
}
}
25 changes: 25 additions & 0 deletions indexers/liquidity-pools/db/migrations/1736702149041-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = class Data1736702149041 {
name = 'Data1736702149041'

async up(db) {
await db.query(`ALTER TABLE "swap" DROP CONSTRAINT "FK_cdeb57fc49ab9df38808386f1fa"`)
await db.query(`DROP INDEX "public"."IDX_cdeb57fc49ab9df38808386f1f"`)
await db.query(`ALTER TABLE "swap" RENAME COLUMN "dca_schedule_execution_id" TO "dca_schedule_execution_action_id"`)
await db.query(`ALTER TABLE "dca_schedule_execution_action" ADD "swap_id" character varying`)
await db.query(`CREATE INDEX "IDX_2ea29fabaf7e05c3546723086e" ON "dca_schedule_execution_action" ("swap_id") `)
await db.query(`CREATE INDEX "IDX_01a8428ecd73bbd9809d8b243a" ON "swap" ("dca_schedule_execution_action_id") `)
await db.query(`ALTER TABLE "dca_schedule_execution_action" ADD CONSTRAINT "FK_2ea29fabaf7e05c3546723086e2" FOREIGN KEY ("swap_id") REFERENCES "swap"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
await db.query(`ALTER TABLE "swap" ADD CONSTRAINT "FK_01a8428ecd73bbd9809d8b243ad" FOREIGN KEY ("dca_schedule_execution_action_id") REFERENCES "dca_schedule_execution_action"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
}

async down(db) {
await db.query(`ALTER TABLE "swap" ADD CONSTRAINT "FK_cdeb57fc49ab9df38808386f1fa" FOREIGN KEY ("dca_schedule_execution_id") REFERENCES "dca_schedule_execution"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
await db.query(`CREATE INDEX "IDX_cdeb57fc49ab9df38808386f1f" ON "swap" ("dca_schedule_execution_id") `)
await db.query(`ALTER TABLE "swap" RENAME COLUMN "dca_schedule_execution_action_id" TO "dca_schedule_execution_id"`)
await db.query(`ALTER TABLE "dca_schedule_execution_action" DROP COLUMN "swap_id"`)
await db.query(`DROP INDEX "public"."IDX_2ea29fabaf7e05c3546723086e"`)
await db.query(`DROP INDEX "public"."IDX_01a8428ecd73bbd9809d8b243a"`)
await db.query(`ALTER TABLE "dca_schedule_execution_action" DROP CONSTRAINT "FK_2ea29fabaf7e05c3546723086e2"`)
await db.query(`ALTER TABLE "swap" DROP CONSTRAINT "FK_01a8428ecd73bbd9809d8b243ad"`)
}
}
21 changes: 21 additions & 0 deletions indexers/liquidity-pools/db/migrations/1736784159931-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = class Data1736784159931 {
name = 'Data1736784159931'

async up(db) {
await db.query(`ALTER TABLE "dca_schedule_execution_action" DROP CONSTRAINT "FK_2ea29fabaf7e05c3546723086e2"`)
await db.query(`DROP INDEX "public"."IDX_b5e76a3b57e6d4ce71262668c7"`)
await db.query(`DROP INDEX "public"."IDX_2ea29fabaf7e05c3546723086e"`)
await db.query(`ALTER TABLE "dca_schedule_execution_action" DROP COLUMN "swap_id"`)
await db.query(`ALTER TABLE "dca_schedule_execution_action" DROP COLUMN "operation_id"`)
await db.query(`ALTER TABLE "dca_schedule_execution_action" ADD "operation_ids" text array`)
}

async down(db) {
await db.query(`ALTER TABLE "dca_schedule_execution_action" ADD CONSTRAINT "FK_2ea29fabaf7e05c3546723086e2" FOREIGN KEY ("swap_id") REFERENCES "swap"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
await db.query(`CREATE INDEX "IDX_b5e76a3b57e6d4ce71262668c7" ON "dca_schedule_execution_action" ("operation_id") `)
await db.query(`CREATE INDEX "IDX_2ea29fabaf7e05c3546723086e" ON "dca_schedule_execution_action" ("swap_id") `)
await db.query(`ALTER TABLE "dca_schedule_execution_action" ADD "swap_id" character varying`)
await db.query(`ALTER TABLE "dca_schedule_execution_action" ADD "operation_id" text`)
await db.query(`ALTER TABLE "dca_schedule_execution_action" DROP COLUMN "operation_ids"`)
}
}
11 changes: 11 additions & 0 deletions indexers/liquidity-pools/db/migrations/1736875670868-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = class Data1736875670868 {
name = 'Data1736875670868'

async up(db) {
await db.query(`ALTER TABLE "chain_activity_trace" ADD "associated_accounts_flat" text array NOT NULL`)
}

async down(db) {
await db.query(`ALTER TABLE "chain_activity_trace" DROP COLUMN "associated_accounts_flat"`)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ scale:
dedicated: false
addons:
postgres:
profile: large
profile: small
storage: 50G
processor:
profile: large
50 changes: 50 additions & 0 deletions indexers/liquidity-pools/deployment-hydration-testnet-indexer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
manifestVersion: subsquid.io/v0.1
name: hydration-testnet-pools
slot: 103
description: Hydration Testnet pools indexer
build:
deploy:
addons:
postgres:
config:
statement_timeout: 360000
log_min_duration_statement: 60000
processor:
env:
CHAIN: 'hydration_paseo_next'
RPC_URL: 'wss://max.lark.hydration.cloud'
PROCESS_LBP_POOLS: true
PROCESS_XYK_POOLS: true
PROCESS_OMNIPOOLS: true
PROCESS_STABLEPOOLS: true
PROCESS_DCA: true
PROCESS_OTC: true
GQL_PORT: 8080
NODE_ENV: 'production'
OMNIPOOL_ADDRESS: '0x6d6f646c6f6d6e69706f6f6c0000000000000000000000000000000000000000'
PROCESS_FROM_BLOCK: 1000

USE_STORAGE_DICTIONARY: false
STORAGE_DICTIONARY_LBPPOOL_URL: 'https://galacticcouncil.squids.live/hydration-storage-dictionary:lbppool/api/graphql'
STORAGE_DICTIONARY_XYKPOOL_URL: 'https://galacticcouncil.squids.live/hydration-storage-dictionary:xykpool/api/graphql'
STORAGE_DICTIONARY_OMNIPOOL_URL: 'https://galacticcouncil.squids.live/hydration-storage-dictionary:omnipool/api/graphql'
STORAGE_DICTIONARY_STABLEPOOL_URL: 'https://galacticcouncil.squids.live/hydration-storage-dictionary:stablepool/api/graphql'
cmd:
- sqd
- process:prod
api:
env:
CHAIN: 'hydration_paseo_next'
GQL_PORT: 8080
NODE_ENV: 'production'
cmd:
- sqd
- api:prod
scale:
dedicated: false
addons:
postgres:
profile: small
storage: 50G
processor:
profile: large
25 changes: 17 additions & 8 deletions indexers/liquidity-pools/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ type DispatchError {
# *** Chain Activity Tracing ***
# ======================================================================================================================


enum TraceEntityType {
SWAP
TRANSFER
Expand Down Expand Up @@ -209,9 +208,11 @@ type ChainActivityTrace @entity {
# account who signed initial call of the extrinsic
originator: Account

rootTrace: ChainActivityTrace
# Scope of all accounts involved into particular activity trace. Required for easier filtering on API side.
associatedAccountsFlat: [String!]!

relatedTraces: [ChainActivityTrace] @derivedFrom(field: "rootTrace")
childTraces: [ChainActivityTraceRelation] @derivedFrom(field: "parentTrace")
parentTraces: [ChainActivityTraceRelation] @derivedFrom(field: "childTrace")

createdAtParaChainBlockHeight: Int! @index
createdAtBlock: Block!
Expand All @@ -224,6 +225,14 @@ type AccountChainActivityTrace @entity {
chainActivityTrace: ChainActivityTrace!
}

type ChainActivityTraceRelation @entity {
# <child_trace_id>-<parent_trace_id>
id: ID!
childTrace: ChainActivityTrace!
parentTrace: ChainActivityTrace!
createdAtParaChainBlockHeight: Int!
}

# ======================================================================================================================
# *** Swapped - Unified Trade event ***
# ======================================================================================================================
Expand Down Expand Up @@ -355,7 +364,7 @@ type Swap @entity {
eventIndex: Int!
extrinsicHash: String!
relayChainBlockHeight: Int!
dcaScheduleExecution: DcaScheduleExecution
dcaScheduleExecutionAction: DcaScheduleExecutionAction
otcOrderFulfilment: OtcOrderAction
paraChainBlockHeight: Int! @index
paraChainTimestamp: DateTime! @index
Expand Down Expand Up @@ -765,15 +774,15 @@ type DcaScheduleExecution @entity {
status: DcaScheduleExecutionStatus @index
amountOut: BigInt
amountIn: BigInt
swaps: [Swap] @derivedFrom(field: "dcaScheduleExecution")
actions: [DcaScheduleExecutionAction] @derivedFrom(field: "scheduleExecution")
}

type DcaScheduleExecutionAction @entity {
"<dca_schedule_execution_id>-<dca_schedule_execution_status>"
id: ID!
operationId: String @index
operationIds: [String]
traceIds: [String!]
swaps: [Swap] @derivedFrom(field: "dcaScheduleExecutionAction")
scheduleExecution: DcaScheduleExecution!
status: DcaScheduleExecutionStatus @index
statusMemo: DispatchError
Expand All @@ -796,7 +805,7 @@ type DcaRandomnessGenerationFailedError @entity {
# *** OTC ***
# ======================================================================================================================

enum OtcScheduleStatus {
enum OtcOrderStatus {
OPEN
CANCELED
FILLED
Expand All @@ -819,7 +828,7 @@ type OtcOrder @entity {
amountOut: BigInt!
amountIn: BigInt!
partiallyFillable: Boolean
status: OtcScheduleStatus @index
status: OtcOrderStatus @index
createdAtRelayBlockHeight: Int!
createdAtParaBlockHeight: Int! @index

Expand Down
Loading

0 comments on commit bafb0b8

Please sign in to comment.