-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: change get tokens query logic
- Loading branch information
Showing
3 changed files
with
62 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { DbSchema } from '../../common/types'; | ||
import { dbConnection } from '../../database/connectToDatabase'; | ||
|
||
export default async function getTokens(dbSchema: DbSchema): Promise<string[]> { | ||
const distinctGivenTokens = ( | ||
await dbConnection.query( | ||
` | ||
SELECT DISTINCT ON ("erc20") "erc20" | ||
FROM "${dbSchema}"."GivenEvents" | ||
`, | ||
) | ||
)[0] as { erc20: string }[]; | ||
|
||
const distinctSplitTokens = ( | ||
await dbConnection.query( | ||
` | ||
SELECT DISTINCT ON ("erc20") "erc20" | ||
FROM "${dbSchema}"."SplitEvents" | ||
`, | ||
) | ||
)[0] as { erc20: string }[]; | ||
|
||
const distinctStreamSetTokens = ( | ||
await dbConnection.query( | ||
` | ||
SELECT DISTINCT ON ("erc20") "erc20" | ||
FROM "${dbSchema}"."StreamsSetEvents" | ||
`, | ||
) | ||
)[0] as { erc20: string }[]; | ||
|
||
const distinctSqueezedStreamsTokens = ( | ||
await dbConnection.query( | ||
` | ||
SELECT DISTINCT ON ("erc20") "erc20" | ||
FROM "${dbSchema}"."SqueezedStreamsEvents" | ||
`, | ||
) | ||
)[0] as { erc20: string }[]; | ||
|
||
return [ | ||
...new Set([ | ||
...distinctGivenTokens.map((row: any) => row.erc20), | ||
...distinctSplitTokens.map((row: any) => row.erc20), | ||
...distinctStreamSetTokens.map((row: any) => row.erc20), | ||
...distinctSqueezedStreamsTokens.map((row: any) => row.erc20), | ||
]), | ||
]; | ||
} |
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