1- /**
2- * Saber Volume Adapter
3- *
4- * This adapter fetches and processes the previous day's volume data for Saber pools.
5- * It retrieves volume data and pool information, then calculates the adjusted volume
6- * based on token decimals. The adjusted volume is used to provide accurate volume
7- * metrics for each token in the pool.
8- *
9- */
10-
111import { CHAIN } from '../../helpers/chains' ;
12- import { ChainBlocks , FetchOptions } from '../../adapters/types' ;
13- import { httpGet } from "../../utils/fetchURL" ;
14-
15-
16- async function fetchLast24hVolume ( timestamp : number , _ : ChainBlocks , { createBalances } : FetchOptions ) {
17- const [ volumeData , poolsData ] = await Promise . all ( [
18- httpGet ( 'https://raw.githubusercontent.com/saberdao/birdeye-data/refs/heads/main/volume.json' ) ,
19- httpGet ( 'https://raw.githubusercontent.com/saberdao/saber-registry-dist/master/data/pools-info.mainnet.json' )
20- ] ) ;
21-
22- const dailyVolume = createBalances ( )
23-
24- // Create map of tokenA mint addresses and decimals by swap account
25- const poolTokens = new Map (
26- poolsData . pools . map ( ( pool : any ) => [
27- pool . swap . config . swapAccount ,
28- {
29- mint : pool . swap . state . tokenA . mint . toString ( ) ,
30- decimals : pool . tokens . find ( ( token : any ) => token . address === pool . swap . state . tokenA . mint . toString ( ) ) ?. decimals
31- }
32- ] )
33- )
34-
35- Object . entries ( volumeData ) . forEach ( ( [ swapAccount , pool ] : [ string , any ] ) => {
36- if ( ! pool . v ) return ;
37-
38- const tokenInfo = poolTokens . get ( swapAccount ) ;
39- if ( ! tokenInfo ) return ;
40-
41- const { mint, decimals } = tokenInfo as { mint : string ; decimals : number } ;
42- const adjustedVolume = pool . v * Math . pow ( 10 , decimals || 0 ) ;
43-
44- dailyVolume . add ( mint , adjustedVolume ) ;
45- } )
46-
47- return { dailyVolume, timestamp : Math . floor ( Date . now ( ) / 1e3 ) }
2+ import { Dependencies , FetchOptions , SimpleAdapter } from '../../adapters/types' ;
3+ import { queryAllium } from '../../helpers/allium'
4+
5+ async function fetch ( _t : any , _a : any , options : FetchOptions ) {
6+ const query = `
7+ select
8+ sum(usd_amount) as volume
9+ from solana.dex.trades
10+ where project='saber'
11+ and block_timestamp >= TO_TIMESTAMP_NTZ('${ options . startTimestamp } ')
12+ and block_timestamp < TO_TIMESTAMP_NTZ('${ options . endTimestamp } ')
13+ `
14+ const data = await queryAllium ( query )
15+ const dailyVolume = data [ 0 ] . volume
16+
17+ return { dailyVolume }
4818}
4919
20+ const adapter : SimpleAdapter = {
21+ version : 1 ,
22+ fetch,
23+ chains : [ CHAIN . SOLANA ] ,
24+ start : "2021-05-28" ,
25+ dependencies : [ Dependencies . ALLIUM ] ,
26+ isExpensiveAdapter : true
27+ }
5028
51- export default {
52- adapter : {
53- [ CHAIN . SOLANA ] : {
54- fetch : fetchLast24hVolume ,
55- runAtCurrTime : true ,
56- }
57- }
58- }
29+ export default adapter
0 commit comments