Skip to content

Commit 8cf70c7

Browse files
committed
fix superchain
1 parent e9dd6cf commit 8cf70c7

File tree

3 files changed

+92
-91
lines changed

3 files changed

+92
-91
lines changed

fees/superchain.ts

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
11
import { FetchOptions, SimpleAdapter } from "../adapters/types"
22
import { CHAIN } from "../helpers/chains"
3-
import ADDRESSES from '../helpers/coreAssets.json'
43

54
const fees: any = {
65
[CHAIN.BASE]: ['0x9c3631dDE5c8316bE5B7554B0CcD2631C15a9A05'],
76
[CHAIN.ETHEREUM]: [
87
'0xa3d596eafab6b13ab18d40fae1a962700c84adea',
9-
'0x793e01dCf6F9759Bf26dd7869b03129e64217537',
10-
'0x4a4962275DF8C60a80d3a25faEc5AA7De116A746',
11-
'0xe900b3Edc1BA0430CFa9a204A1027B90825ac951',
12-
'0xed4811010a86f7c39134fbc20206d906ad1176b6',
13-
'0x13f37e6b638ca83e7090bb3722b3ae04bf884019',
14-
'0x99c9fc46f92e8a1c0dec1b1747d010903e884be1',
15-
'0xC2eC5Dd60CBD5242b8cdeB9d0d37Ff6024584631',
8+
// '0xC2eC5Dd60CBD5242b8cdeB9d0d37Ff6024584631',
169
]
1710
}
18-
const fetchFees = async (options: FetchOptions) => {
19-
const { api, fromApi, createBalances } = options;
20-
await api.sumTokens({ owners: fees[options.chain], tokens: [ADDRESSES.null] })
21-
await fromApi.sumTokens({ owners: fees[options.chain], tokens: [ADDRESSES.null] })
22-
const balances = createBalances()
23-
balances.addBalances(api.getBalancesV2())
24-
balances.subtract(fromApi.getBalancesV2())
25-
const dailyFees = balances.clone()
11+
const fetchFees = async (_: any, _1: any, options: FetchOptions) => {
12+
const logs = await options.getLogs({
13+
targets: fees[options.chain],
14+
eventAbi: 'event SafeReceived (address indexed sender, uint256 value)',
15+
})
16+
const logs2 = await options.getLogs({
17+
targets: fees[options.chain],
18+
eventAbi: 'event Deposited (address from, uint256 value, bytes data)',
19+
})
20+
const dailyFees = options.createBalances()
21+
for (const log of logs) dailyFees.addGasToken(log.value)
22+
for (const log of logs2) dailyFees.addGasToken(log.value)
23+
2624
return {
2725
dailyFees,
26+
dailyRevenue: dailyFees,
2827
}
2928
}
3029

3130
const adapter: SimpleAdapter = {
32-
version: 2,
3331
adapter: {
3432
[CHAIN.BASE]: {
3533
fetch: fetchFees,
36-
},
34+
},
3735
[CHAIN.ETHEREUM]: {
3836
fetch: fetchFees,
39-
},
37+
},
4038
}
4139
}
4240

helpers/token.ts

+74-71
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function addGasTokensReceived(params: {
3030
const fromBlock = (await options.getFromBlock()) - 200
3131
const toBlock = (await options.getToBlock()) - 200
3232

33-
for (;;) {
33+
for (; ;) {
3434
batchLogs = await sdk.indexer.getLogs({
3535
chain: options.chain,
3636
targets: multisigs,
@@ -153,7 +153,7 @@ export async function addTokensReceived(params: AddTokensReceivedParams) {
153153
}
154154

155155
async function _addTokensReceivedIndexer(params: AddTokensReceivedParams) {
156-
let { balances, fromAddressFilter, target, targets, options, fromAdddesses, tokenTransform = (i: string) => i, tokens, logFilter = () => true, } = params
156+
let { balances, fromAddressFilter, target, targets, options, fromAdddesses, tokenTransform = (i: string) => i, tokens, logFilter = () => true, } = params
157157
const { createBalances, chain, getFromBlock, getToBlock } = options
158158
if (!balances) balances = createBalances()
159159
if (fromAdddesses && fromAdddesses.length) (fromAddressFilter as any) = fromAdddesses
@@ -329,10 +329,10 @@ export const evmReceivedGasAndTokens = (receiverWallet: string, tokens: string[]
329329
if (tokens.length > 0) {
330330
await addTokensReceived({ options, tokens: tokens, target: receiverWallet, balances: dailyFees })
331331
}
332-
// const nativeTransfers = await queryDuneSql(options, `select sum(value) as received from CHAIN.traces
333-
// where to = ${receiverWallet} AND tx_success = TRUE
334-
// AND TIME_RANGE`)
335-
// dailyFees.add(nullAddress, nativeTransfers[0].received)
332+
// const nativeTransfers = await queryDuneSql(options, `select sum(value) as received from CHAIN.traces
333+
// where to = ${receiverWallet} AND tx_success = TRUE
334+
// AND TIME_RANGE`)
335+
// dailyFees.add(nullAddress, nativeTransfers[0].received)
336336
await getETHReceived({ options, balances: dailyFees, target: receiverWallet })
337337

338338
return {
@@ -341,53 +341,53 @@ export const evmReceivedGasAndTokens = (receiverWallet: string, tokens: string[]
341341
}
342342
}
343343

344-
/**
345-
* Retrieves the total value of tokens received by a Solana address or addresses within a specified time period
346-
*
347-
* @param options - FetchOptions containing timestamp range and other configuration
348-
* @param balances - Optional sdk.Balances object to add the results to
349-
* @param target - Single Solana address to query
350-
* @param targets - Array of Solana addresses to query (alternative to target)
351-
* @param blacklists - Optional array of addresses to exclude from the sender side
352-
* @param blacklist_signers - Optional array of transaction signers to exclude
353-
* @returns The balances object with added USD value from received tokens
354-
*/
355-
export async function getSolanaReceived({ options, balances, target, targets, blacklists, blacklist_signers }: {
356-
options: FetchOptions;
357-
balances?: sdk.Balances;
358-
target?: string;
359-
targets?: string[];
360-
blacklists?: string[];
361-
blacklist_signers?: string[];
362-
}) {
363-
// Initialize balances if not provided
364-
if (!balances) balances = options.createBalances();
365-
366-
// If targets is provided, use that instead of single target
367-
const addresses = targets?.length ? targets : target ? [target] : [];
368-
if (addresses.length === 0) return balances;
369-
370-
// Build SQL condition to exclude blacklisted sender addresses
371-
let blacklistCondition = '';
372-
373-
if (blacklists && blacklists.length > 0) {
374-
const formattedBlacklist = blacklists.map(addr => `'${addr}'`).join(', ');
375-
blacklistCondition = `AND from_address NOT IN (${formattedBlacklist})`;
376-
}
377-
378-
// Build SQL condition to exclude blacklisted transaction signers
379-
let blacklist_signersCondition = '';
380-
381-
if (blacklist_signers && blacklist_signers.length > 0) {
382-
const formattedBlacklist = blacklist_signers.map(addr => `'${addr}'`).join(', ');
383-
blacklist_signersCondition = `AND signer NOT IN (${formattedBlacklist})`;
384-
}
344+
/**
345+
* Retrieves the total value of tokens received by a Solana address or addresses within a specified time period
346+
*
347+
* @param options - FetchOptions containing timestamp range and other configuration
348+
* @param balances - Optional sdk.Balances object to add the results to
349+
* @param target - Single Solana address to query
350+
* @param targets - Array of Solana addresses to query (alternative to target)
351+
* @param blacklists - Optional array of addresses to exclude from the sender side
352+
* @param blacklist_signers - Optional array of transaction signers to exclude
353+
* @returns The balances object with added USD value from received tokens
354+
*/
355+
export async function getSolanaReceived({ options, balances, target, targets, blacklists, blacklist_signers }: {
356+
options: FetchOptions;
357+
balances?: sdk.Balances;
358+
target?: string;
359+
targets?: string[];
360+
blacklists?: string[];
361+
blacklist_signers?: string[];
362+
}) {
363+
// Initialize balances if not provided
364+
if (!balances) balances = options.createBalances();
365+
366+
// If targets is provided, use that instead of single target
367+
const addresses = targets?.length ? targets : target ? [target] : [];
368+
if (addresses.length === 0) return balances;
369+
370+
// Build SQL condition to exclude blacklisted sender addresses
371+
let blacklistCondition = '';
372+
373+
if (blacklists && blacklists.length > 0) {
374+
const formattedBlacklist = blacklists.map(addr => `'${addr}'`).join(', ');
375+
blacklistCondition = `AND from_address NOT IN (${formattedBlacklist})`;
376+
}
377+
378+
// Build SQL condition to exclude blacklisted transaction signers
379+
let blacklist_signersCondition = '';
380+
381+
if (blacklist_signers && blacklist_signers.length > 0) {
382+
const formattedBlacklist = blacklist_signers.map(addr => `'${addr}'`).join(', ');
383+
blacklist_signersCondition = `AND signer NOT IN (${formattedBlacklist})`;
384+
}
385385

386-
// Format addresses for IN clause
387-
const formattedAddresses = addresses.map(addr => `'${addr}'`).join(', ');
388-
389-
// Construct SQL query to get sum of received token values in USD and native amount
390-
const query = `
386+
// Format addresses for IN clause
387+
const formattedAddresses = addresses.map(addr => `'${addr}'`).join(', ');
388+
389+
// Construct SQL query to get sum of received token values in USD and native amount
390+
const query = `
391391
SELECT mint as token, SUM(raw_amount) as amount
392392
FROM solana.assets.transfers
393393
WHERE to_address IN (${formattedAddresses})
@@ -396,28 +396,27 @@ export const evmReceivedGasAndTokens = (receiverWallet: string, tokens: string[]
396396
${blacklist_signersCondition}
397397
GROUP BY mint
398398
`;
399-
400-
// Execute query against Allium database
401-
const res = await queryAllium(query);
402-
403-
// Add the USD value to the balances object (defaulting to 0 if no results)
404-
res.forEach((row: any) => {
405-
balances!.add(row.token, row.amount)
406-
})
407-
return balances;
408-
}
409-
410399

411-
export async function getETHReceived({ options, balances, target, targets }: { options: FetchOptions, balances?: sdk.Balances, target?: string, targets?: string[] }) {
400+
// Execute query against Allium database
401+
const res = await queryAllium(query);
402+
403+
// Add the USD value to the balances object (defaulting to 0 if no results)
404+
res.forEach((row: any) => {
405+
balances!.add(row.token, row.amount)
406+
})
407+
return balances;
408+
}
409+
410+
411+
export async function getETHReceived({ options, balances, target, targets = [] }: { options: FetchOptions, balances?: sdk.Balances, target?: string, targets?: string[] }) {
412412
if (!balances) balances = options.createBalances()
413413

414-
if (targets?.length) {
415-
for (const target of targets)
416-
await getETHReceived({ options, balances, target })
417-
return balances
418-
}
414+
if (!target && !targets?.length) return balances
419415

420-
target = target?.toLowerCase()
416+
if (target) targets.push(target)
417+
418+
targets = targets.map(i => i.toLowerCase())
419+
targets = [...new Set(targets)]
421420

422421
// you can find the supported chains and the documentation here: https://docs.allium.so/historical-chains/supported-blockchains/evm/ethereum
423422
const chainMap: any = {
@@ -461,13 +460,17 @@ export async function getETHReceived({ options, balances, target, targets }: { o
461460
const chainKey = chainMap[options.chain]
462461
if (!chainKey) throw new Error('[Pull eth transfers] Chain not supported: ' + options.chain)
463462

463+
const targetList = '( ' + targets.map(i => `'${i}'`).join(', ') + ' )'
464+
464465
const query = `
465466
SELECT SUM(raw_amount) as value
466467
FROM ${chainKey}.assets.${tableMap[options.chain] ?? 'eth_token_transfers'}
467-
WHERE to_address = '${target}'
468+
WHERE to_address in ${targetList}
469+
${targets.length > 1 ? `AND from_Address not in ${targetList} ` : ' '}
468470
AND transfer_type = 'value_transfer'
469471
AND block_timestamp BETWEEN TO_TIMESTAMP_NTZ(${options.startTimestamp}) AND TO_TIMESTAMP_NTZ(${options.endTimestamp})
470472
`
473+
471474
const res = await queryAllium(query)
472475
balances.add(nullAddress, res[0].value)
473476
return balances

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
}
66
},
77
"compilerOptions": {
8-
"target": "es2019",
8+
"target": "ES2020",
99
"skipLibCheck": true,
1010
"esModuleInterop": true,
1111
"allowSyntheticDefaultImports": true,

0 commit comments

Comments
 (0)