/
ethena.ts
71 lines (66 loc) · 2.32 KB
/
ethena.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
65
66
67
68
69
70
71
import { FetchOptions, SimpleAdapter } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
import { queryIndexer } from "../helpers/indexer";
const mint_event = 'event Mint( address indexed minter,address indexed benefactor,address indexed beneficiary,address collateral_asset,uint256 collateral_amount,uint256 usde_amount)';
const fetch = async (options: FetchOptions) => {
const logs = await options.getLogs({
eventAbi: mint_event,
target: '0x2cc440b721d2cafd6d64908d6d8c4acc57f8afc3',
});
const in_flow = await queryIndexer(`
SELECT
'0x' || encode(data, 'hex') AS data,
'0x' || encode(contract_address, 'hex') AS token
FROM
ethereum.event_logs
WHERE
block_number > 18637861
AND topic_0 = '\\xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
AND topic_2 in ('\\x00000000000000000000000071e4f98e8f20c88112489de3dded4489802a3a87', '\\x0000000000000000000000002b5ab59163a6e93b4486f6055d33ca4a115dd4d5')
AND block_time BETWEEN llama_replace_date_range;
`, options);
const out_flow = await queryIndexer(`
SELECT
'0x' || encode(data, 'hex') AS data,
'0x' || encode(contract_address, 'hex') AS token
FROM
ethereum.event_logs
WHERE
block_number > 18637861
AND topic_0 = '\\xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
AND topic_2 in ('\\x000000000000000000000000f2fa332bd83149c66b09b45670bce64746c6b439')
AND block_time BETWEEN llama_replace_date_range;
`, options);
const dailyFeesInflow = options.createBalances();
const supplyRewards = options.createBalances();
in_flow.map((log: any) => {
const amount = Number(log.data);
dailyFeesInflow.add(log.token, amount);
});
out_flow.map((log: any) => {
const amount = Number(log.data);
supplyRewards.add(log.token, amount);
});
const dailyFeesMint = options.createBalances();
logs.map((log) => {
dailyFeesMint.add(log.collateral_asset, log.collateral_amount);
});
dailyFeesMint.resizeBy(0.001)
dailyFeesMint.addBalances(dailyFeesInflow);
const revenue = dailyFeesMint.clone()
revenue.subtract(supplyRewards)
return {
dailyFees: dailyFeesMint,
dailyRevenue: revenue,
}
}
const adapters: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.ETHEREUM]: {
fetch: fetch,
start: 1700784000
}
}
}
export default adapters