@@ -30,7 +30,7 @@ export async function addGasTokensReceived(params: {
30
30
const fromBlock = ( await options . getFromBlock ( ) ) - 200
31
31
const toBlock = ( await options . getToBlock ( ) ) - 200
32
32
33
- for ( ; ; ) {
33
+ for ( ; ; ) {
34
34
batchLogs = await sdk . indexer . getLogs ( {
35
35
chain : options . chain ,
36
36
targets : multisigs ,
@@ -153,7 +153,7 @@ export async function addTokensReceived(params: AddTokensReceivedParams) {
153
153
}
154
154
155
155
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
157
157
const { createBalances, chain, getFromBlock, getToBlock } = options
158
158
if ( ! balances ) balances = createBalances ( )
159
159
if ( fromAdddesses && fromAdddesses . length ) ( fromAddressFilter as any ) = fromAdddesses
@@ -329,10 +329,10 @@ export const evmReceivedGasAndTokens = (receiverWallet: string, tokens: string[]
329
329
if ( tokens . length > 0 ) {
330
330
await addTokensReceived ( { options, tokens : tokens , target : receiverWallet , balances : dailyFees } )
331
331
}
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)
336
336
await getETHReceived ( { options, balances : dailyFees , target : receiverWallet } )
337
337
338
338
return {
@@ -341,53 +341,53 @@ export const evmReceivedGasAndTokens = (receiverWallet: string, tokens: string[]
341
341
}
342
342
}
343
343
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
+ }
385
385
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 = `
391
391
SELECT mint as token, SUM(raw_amount) as amount
392
392
FROM solana.assets.transfers
393
393
WHERE to_address IN (${ formattedAddresses } )
@@ -396,28 +396,27 @@ export const evmReceivedGasAndTokens = (receiverWallet: string, tokens: string[]
396
396
${ blacklist_signersCondition }
397
397
GROUP BY mint
398
398
` ;
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
-
410
399
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 [ ] } ) {
412
412
if ( ! balances ) balances = options . createBalances ( )
413
413
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
419
415
420
- target = target ?. toLowerCase ( )
416
+ if ( target ) targets . push ( target )
417
+
418
+ targets = targets . map ( i => i . toLowerCase ( ) )
419
+ targets = [ ...new Set ( targets ) ]
421
420
422
421
// you can find the supported chains and the documentation here: https://docs.allium.so/historical-chains/supported-blockchains/evm/ethereum
423
422
const chainMap : any = {
@@ -461,13 +460,17 @@ export async function getETHReceived({ options, balances, target, targets }: { o
461
460
const chainKey = chainMap [ options . chain ]
462
461
if ( ! chainKey ) throw new Error ( '[Pull eth transfers] Chain not supported: ' + options . chain )
463
462
463
+ const targetList = '( ' + targets . map ( i => `'${ i } '` ) . join ( ', ' ) + ' )'
464
+
464
465
const query = `
465
466
SELECT SUM(raw_amount) as value
466
467
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 } ` : ' ' }
468
470
AND transfer_type = 'value_transfer'
469
471
AND block_timestamp BETWEEN TO_TIMESTAMP_NTZ(${ options . startTimestamp } ) AND TO_TIMESTAMP_NTZ(${ options . endTimestamp } )
470
472
`
473
+
471
474
const res = await queryAllium ( query )
472
475
balances . add ( nullAddress , res [ 0 ] . value )
473
476
return balances
0 commit comments