-
Notifications
You must be signed in to change notification settings - Fork 825
/
op-bnb.ts
59 lines (48 loc) · 2.07 KB
/
op-bnb.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
import ADDRESSES from '../helpers/coreAssets.json'
import { CHAIN } from "../helpers/chains";
import { Adapter, ChainBlocks, FetchOptions, FetchResultFees, ProtocolType } from "../adapters/types";
import { queryFlipside } from "../helpers/flipsidecrypto";
async function getFees(options: FetchOptions) {
const feeWallet = '0x4200000000000000000000000000000000000011';
const l1FeeVault = '0x420000000000000000000000000000000000001a';
const baseFeeVault = '0x4200000000000000000000000000000000000019';
const feeVaults = [l1FeeVault, baseFeeVault, feeWallet];
const { api, fromApi, createBalances, getLogs } = options;
const balances = createBalances();
const eventAbi = 'event Withdrawal (uint256 value, address to, address from, uint8 withdrawalNetwork)'
await api.sumTokens({ owners: feeVaults, tokens: [ADDRESSES.null] })
await fromApi.sumTokens({ owners: feeVaults, tokens: [ADDRESSES.null] })
const logs = await getLogs({ targets: feeVaults, eventAbi, })
logs.map((log) => balances.addGasToken(log.value))
balances.addBalances(api.getBalancesV2())
balances.subtract(fromApi.getBalancesV2())
return balances
}
const fetch = async (timestamp: number, _chainBlocks: ChainBlocks, options: FetchOptions): Promise<FetchResultFees> => {
const { getFromBlock, getToBlock, } = options
const query = `
select
SUM(TX_FEE)
from
bsc.core.fact_transactions
WHERE (to_address = '0x153cab79f4767e2ff862c94aa49573294b13d169')
and BLOCK_NUMBER > ${await getFromBlock()} AND BLOCK_NUMBER < ${await getToBlock()}
`
const cost_to_l1: number[] = (await queryFlipside(query, 260)).flat();
const dailyFees = await getFees(options)
const dailyRevenue = dailyFees.clone();
dailyRevenue.addGasToken((cost_to_l1[0] ?? 0) * 1e18 * -1)
return { timestamp, dailyFees, dailyRevenue }
}
const adapter: Adapter = {
adapter: {
[CHAIN.OP_BNB]: {
fetch: fetch as any,
start: 1691971200,
runAtCurrTime: true,
},
},
isExpensiveAdapter: true,
protocolType: ProtocolType.CHAIN
}
export default adapter;