/
sudoswap-v2.ts
63 lines (60 loc) · 2.11 KB
/
sudoswap-v2.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
import { Adapter, FetchOptions, FetchResultFees } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
import { queryIndexer } from "../helpers/indexer";
const fetch = async (timestamp: number, _: any, options: FetchOptions): Promise<FetchResultFees> => {
const dailyFees = options.createBalances();
const dailyRevenue = options.createBalances();
const eth_transfer_logs: any = await queryIndexer(`
SELECT
sum("value") AS eth_value
FROM
ethereum.traces
WHERE
block_number > 17309203
AND to_address = '\\xA020d57aB0448Ef74115c112D18a9C231CC86000'
AND block_time BETWEEN llama_replace_date_range;
`, options);
const royalties: any = await queryIndexer(`
WITH MinValues AS (
SELECT
transaction_hash,
from_address,
MIN("value") AS min_value
FROM
ethereum.traces
WHERE
block_number > 17309203
AND block_time BETWEEN llama_replace_date_range
AND from_address IN (
SELECT
SUBSTRING(topic_1 FROM 13 FOR 20)::bytea AS extracted_bytea
FROM
ethereum.event_logs
WHERE
block_number > 17309203
AND contract_address = '\\xA020d57aB0448Ef74115c112D18a9C231CC86000'
AND topic_0 = '\\xe8e1cee58c33f242c87d563bbc00f2ac82eb90f10a252b0ba8498ae6c1dc241a'
)
AND to_address != '\\xA020d57aB0448Ef74115c112D18a9C231CC86000'
and value > 0
GROUP BY transaction_hash, from_address
HAVING COUNT(transaction_hash) > 1
)
SELECT
SUM(min_value) AS royalties_fees
FROM MinValues;
`, options);
dailyFees.addGasToken(eth_transfer_logs[0].eth_value)
dailyFees.addGasToken(royalties[0].royalties_fees)
dailyRevenue.addGasToken(eth_transfer_logs[0].eth_value)
return { dailyFees, dailyRevenue, timestamp }
}
const adapter: Adapter = {
adapter: {
[CHAIN.ETHEREUM]: {
fetch: fetch as any,
start: 1684627200
},
},
};
export default adapter;