-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
148 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Responsible for handling all the queries – can be split based on models | ||
*/ | ||
import { GqlPoolJoinExit, QueryPoolGetJoinExitsArgs } from '../../schema'; | ||
import { prisma } from '../../prisma/prisma-client'; | ||
import { Chain } from '@prisma/client'; | ||
|
||
export function QueriesController(tracer?: any) { | ||
return { | ||
// TODO: I'd like to merge it with the swaps and return all as pool events | ||
getJoinExits: async ({ first, skip, where }: QueryPoolGetJoinExitsArgs): Promise<GqlPoolJoinExit[]> => { | ||
// Setting default values | ||
first = first ?? 5; | ||
skip = skip ?? 0; | ||
where = where ?? {}; | ||
let { chainIn, poolIdIn } = where; | ||
chainIn = chainIn ?? []; // 🤔 when no chain, shouldn't we be returning all the chains? | ||
poolIdIn = poolIdIn ?? []; | ||
|
||
const conditions: { poolId?: { in: string[] }; chain?: { in: Chain[] } } = {}; | ||
if (chainIn.length) { | ||
conditions.chain = { | ||
in: chainIn, | ||
}; | ||
} | ||
if (poolIdIn.length) { | ||
conditions.poolId = { | ||
in: poolIdIn, | ||
}; | ||
} | ||
|
||
const dbJoinExists = await prisma.poolEvent.findMany({ | ||
where: conditions, | ||
take: first, | ||
skip, | ||
orderBy: [ | ||
{ | ||
blockNumber: 'desc', | ||
}, | ||
{ | ||
logPosition: 'desc', | ||
}, | ||
], | ||
}); | ||
|
||
const results: GqlPoolJoinExit[] = dbJoinExists.map((joinExit) => { | ||
const payload = joinExit.payload as { | ||
tokens: { address: string; amount: string; amountUsd: string }[]; | ||
}; | ||
|
||
return { | ||
__typename: 'GqlPoolJoinExit', | ||
amounts: payload.tokens.map((token: any) => ({ | ||
address: token.address, | ||
amount: token.amount, | ||
valueUsd: token.amountUsd, | ||
})), | ||
chain: joinExit.chain, | ||
id: joinExit.id, | ||
poolId: joinExit.poolId, | ||
sender: joinExit.userAddress, | ||
timestamp: joinExit.blockTimestamp, | ||
tx: joinExit.tx, | ||
type: joinExit.type === 'JOIN' ? 'Join' : 'Exit', | ||
valueUSD: String(joinExit.amountUsd), | ||
}; | ||
}); | ||
|
||
return results; | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { getVaultSubgraphClient } from './balancer-v3-vault'; | ||
import { getPoolsSubgraphClient } from './balancer-v3-pools'; | ||
import { BalancerSubgraphService } from '../../subgraphs/balancer-subgraph/balancer-subgraph.service'; | ||
|
||
export const getBalancerUniversalSubgraphClient = async ( | ||
vaultSubgraphUrl: string, | ||
poolsSubgraphUrl: string, | ||
v2SubgraphUrl: string, | ||
chainId: number, | ||
) => { | ||
const vaultSubgraphClient = getVaultSubgraphClient(vaultSubgraphUrl); | ||
const poolsSubgraphClient = getPoolsSubgraphClient(poolsSubgraphUrl); | ||
const v2SubgraphClient = new BalancerSubgraphService(v2SubgraphUrl, chainId); | ||
|
||
return { | ||
getEvents: async () => {}, | ||
}; | ||
}; |
18 changes: 0 additions & 18 deletions
18
prisma/migrations/20240229152312_add_pool_events/migration.sql
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
prisma/migrations/20240304114442_add_pool_events/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
-- CreateEnum | ||
CREATE TYPE "PoolEventType" AS ENUM ('JOIN', 'EXIT', 'SWAP'); | ||
|
||
-- CreateTable | ||
CREATE TABLE "PoolEvent" ( | ||
"id" TEXT NOT NULL, | ||
"tx" TEXT NOT NULL, | ||
"type" "PoolEventType" NOT NULL, | ||
"chain" "Chain" NOT NULL, | ||
"poolId" TEXT NOT NULL, | ||
"userAddress" TEXT NOT NULL, | ||
"blockNumber" INTEGER NOT NULL, | ||
"blockTimestamp" INTEGER NOT NULL, | ||
"logPosition" INTEGER NOT NULL, | ||
"amountUsd" DOUBLE PRECISION NOT NULL, | ||
"payload" JSONB NOT NULL, | ||
|
||
CONSTRAINT "PoolEvent_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "PoolEvent_type_idx" ON "PoolEvent"("type"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "PoolEvent_chain_idx" ON "PoolEvent"("chain"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "PoolEvent_chain_poolId_idx" ON "PoolEvent"("chain", "poolId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "PoolEvent_userAddress_idx" ON "PoolEvent"("userAddress"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "PoolEvent_blockNumber_idx" ON "PoolEvent"("blockNumber"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "PoolEvent_logPosition_idx" ON "PoolEvent"("logPosition"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters