Skip to content

Commit

Permalink
fix(#patch); uniswap-v3-forks; create, update account entity on Swap (#…
Browse files Browse the repository at this point in the history
…2386)

Co-authored-by: Dhruv Chauhan <[email protected]>
  • Loading branch information
dhruv-chauhan and Dhruv Chauhan authored Sep 27, 2023
1 parent f961697 commit b6321f6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
10 changes: 5 additions & 5 deletions deployment/deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -4292,7 +4292,7 @@
"status": "prod",
"versions": {
"schema": "4.0.0",
"subgraph": "1.0.0",
"subgraph": "1.0.1",
"methodology": "1.0.0"
},
"files": {
Expand All @@ -4314,7 +4314,7 @@
"status": "prod",
"versions": {
"schema": "4.0.0",
"subgraph": "1.0.0",
"subgraph": "1.0.1",
"methodology": "1.0.0"
},
"files": {
Expand Down Expand Up @@ -4344,7 +4344,7 @@
"status": "prod",
"versions": {
"schema": "4.0.0",
"subgraph": "1.0.1",
"subgraph": "1.0.2",
"methodology": "1.0.0"
},
"files": {
Expand All @@ -4366,7 +4366,7 @@
"status": "prod",
"versions": {
"schema": "4.0.1",
"subgraph": "1.0.1",
"subgraph": "1.0.2",
"methodology": "1.0.0"
},
"files": {
Expand Down Expand Up @@ -4396,7 +4396,7 @@
"status": "prod",
"versions": {
"schema": "4.0.0",
"subgraph": "1.0.0",
"subgraph": "1.0.1",
"methodology": "1.0.0"
},
"files": {
Expand Down
9 changes: 9 additions & 0 deletions subgraphs/uniswap-v3-forks-swap/src/common/dexEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,6 +31,7 @@ export class RawDeltas {
export class DexEventHandler {
event: ethereum.Event;
eventType: i32;
account: Account;
protocol: DexAmmProtocol;
pool: LiquidityPool;
poolTokens: Token[];
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions subgraphs/uniswap-v3-forks-swap/src/common/entities/account.ts
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions subgraphs/uniswap-v3-forks-swap/src/mappings/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export function handleSwap(event: SwapEvent): void {
BigInt.fromI32(event.params.tick)
);
dexEventHandler.updateAndSaveLiquidityPoolEntity();
dexEventHandler.updateAndSaveAccountEntity();
}

0 comments on commit b6321f6

Please sign in to comment.