From 22675e22ee5863405684b44a334e2db592e135e3 Mon Sep 17 00:00:00 2001 From: Dhruv Chauhan Date: Wed, 27 Sep 2023 23:08:30 +0530 Subject: [PATCH] create, update account entity on Swap --- deployment/deployment.json | 10 +++++----- .../src/common/dexEventHandler.ts | 9 +++++++++ .../src/common/entities/account.ts | 20 +++++++++++++++++++ .../src/mappings/core.ts | 1 + 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 subgraphs/uniswap-v3-forks-swap/src/common/entities/account.ts diff --git a/deployment/deployment.json b/deployment/deployment.json index a8f4fc8d71..173f1fdd48 100644 --- a/deployment/deployment.json +++ b/deployment/deployment.json @@ -4292,7 +4292,7 @@ "status": "prod", "versions": { "schema": "4.0.0", - "subgraph": "1.0.0", + "subgraph": "1.0.1", "methodology": "1.0.0" }, "files": { @@ -4314,7 +4314,7 @@ "status": "prod", "versions": { "schema": "4.0.0", - "subgraph": "1.0.0", + "subgraph": "1.0.1", "methodology": "1.0.0" }, "files": { @@ -4344,7 +4344,7 @@ "status": "prod", "versions": { "schema": "4.0.0", - "subgraph": "1.0.1", + "subgraph": "1.0.2", "methodology": "1.0.0" }, "files": { @@ -4366,7 +4366,7 @@ "status": "prod", "versions": { "schema": "4.0.1", - "subgraph": "1.0.1", + "subgraph": "1.0.2", "methodology": "1.0.0" }, "files": { @@ -4396,7 +4396,7 @@ "status": "prod", "versions": { "schema": "4.0.0", - "subgraph": "1.0.0", + "subgraph": "1.0.1", "methodology": "1.0.0" }, "files": { diff --git a/subgraphs/uniswap-v3-forks-swap/src/common/dexEventHandler.ts b/subgraphs/uniswap-v3-forks-swap/src/common/dexEventHandler.ts index 0efa06e4d1..f1cea1849b 100644 --- a/subgraphs/uniswap-v3-forks-swap/src/common/dexEventHandler.ts +++ b/subgraphs/uniswap-v3-forks-swap/src/common/dexEventHandler.ts @@ -10,8 +10,10 @@ import { sumBigIntListByIndex } from "./utils"; import { getLiquidityPool } from "./entities/pool"; import { getOrCreateProtocol } from "./entities/protocol"; import { getOrCreateToken } from "./entities/token"; +import { getOrCreateAccount } from "./entities/account"; import { + Account, DexAmmProtocol, LiquidityPool, Swap, @@ -29,6 +31,7 @@ export class RawDeltas { export class DexEventHandler { event: ethereum.Event; eventType: i32; + account: Account; protocol: DexAmmProtocol; pool: LiquidityPool; poolTokens: Token[]; @@ -41,6 +44,7 @@ export class DexEventHandler { constructor(event: ethereum.Event, pool: LiquidityPool, deltas: RawDeltas) { this.event = event; this.eventType = EventType.UNKNOWN; + this.account = getOrCreateAccount(event.transaction.from); this.protocol = getOrCreateProtocol(); this.pool = pool; this.poolTokens = getTokens(pool); @@ -119,6 +123,11 @@ export class DexEventHandler { this.pool.save(); } + + updateAndSaveAccountEntity(): void { + this.account.swapCount += INT_ONE; + this.account.save(); + } } // Return all tokens given a pool diff --git a/subgraphs/uniswap-v3-forks-swap/src/common/entities/account.ts b/subgraphs/uniswap-v3-forks-swap/src/common/entities/account.ts new file mode 100644 index 0000000000..6b18c293a2 --- /dev/null +++ b/subgraphs/uniswap-v3-forks-swap/src/common/entities/account.ts @@ -0,0 +1,20 @@ +import { Address } from "@graphprotocol/graph-ts"; +import { Account } from "../../../generated/schema"; +import { INT_ZERO } from "../constants"; + +export function getOrCreateAccount(address: Address): Account { + let account = Account.load(address); + if (!account) { + account = new Account(address); + account.positionCount = INT_ZERO; + account.openPositionCount = INT_ZERO; + account.closedPositionCount = INT_ZERO; + account.depositCount = INT_ZERO; + account.withdrawCount = INT_ZERO; + account.swapCount = INT_ZERO; + + return account; + } + + return account; +} diff --git a/subgraphs/uniswap-v3-forks-swap/src/mappings/core.ts b/subgraphs/uniswap-v3-forks-swap/src/mappings/core.ts index 2a912c5602..0fe5dc00e3 100644 --- a/subgraphs/uniswap-v3-forks-swap/src/mappings/core.ts +++ b/subgraphs/uniswap-v3-forks-swap/src/mappings/core.ts @@ -33,4 +33,5 @@ export function handleSwap(event: SwapEvent): void { BigInt.fromI32(event.params.tick) ); dexEventHandler.updateAndSaveLiquidityPoolEntity(); + dexEventHandler.updateAndSaveAccountEntity(); }