-
Notifications
You must be signed in to change notification settings - Fork 205
/
index.ts
64 lines (56 loc) · 2.38 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { SuccessResponse, TokenHolder, TornadoCashDepositor } from "./types";
import { RestProvider } from "@group-generators/helpers/data-providers/rest-api";
export class TransposeProvider {
restProvider: RestProvider;
url: string;
headers: {
"X-API-KEY": string;
};
public constructor() {
this.restProvider = new RestProvider();
this.url = "https://sql.transpose.io/";
this.headers = {
"X-API-KEY": process.env.TRANSPOSE_API_KEY as string
}
}
public async getQuery(sqlQuery: string): Promise<SuccessResponse> {
const executeQuery = async (): Promise<SuccessResponse> => {
const res = await this.restProvider.fetchData({
url: this.url,
method: "post",
headers: this.headers,
data : {"sql":sqlQuery}
});
let response : SuccessResponse;
if(Object(res).status == "success") {
response = {
status: Object(res).status,
stats: Object(res).stats,
results: Object(res).results
}
}
else {
response = {
status: "error",
stats: {count: 0, size: 0, time: 0},
results: []
}
}
return response;
}
return await executeQuery();
}
public async getTokenHolders(tokenAddress: string, balanceMin: number, balanceMax: number): Promise<TokenHolder[]> {
const data: SuccessResponse = await this.getQuery(`SELECT owner_address, balance FROM ethereum.token_owners WHERE contract_address = '${tokenAddress}' AND balance > ${balanceMin} AND balance <= ${balanceMax} ORDER BY balance ASC`)
return data.results as TokenHolder[];
}
/**
*
* @param tokenAddress The token deposited to Tornado Cash. For ETH the tokenAddress to use is 0x0000000000000000000000000000000000000000.
* @returns
*/
public async getTornadoCashDepositors(tokenAddress : string): Promise<TornadoCashDepositor[]> {
const data: SuccessResponse = await this.getQuery(`SELECT from_address, quantity/1000000000000000000 AS quantity FROM ethereum.tornado_cash_deposits WHERE token_address = '${tokenAddress}'`)
return data.results as TornadoCashDepositor[];
}
}