@@ -33,32 +33,13 @@ export async function latest(
3333 return res ;
3434}
3535
36- async function getStoredEmissions ( adapter : string , sectionKey : string ) : Promise < CliffAdapterResult [ ] > {
37- try {
38- const r = await fetch ( `https://api.llama.fi/emission/${ adapter } ` ) . then ( ( r ) => r . json ( ) ) ;
39- if ( ! r . body ) return [ ] ;
40- const data = JSON . parse ( r . body ) ;
41- const section = data . documentedData ?. data ?. find ( ( s : any ) => s . label === sectionKey ) ;
42- if ( ! section ?. data ) return [ ] ;
43-
44- return section . data . map ( ( d : any ) => ( {
45- type : "cliff" as const ,
46- start : d . timestamp ,
47- amount : d . rawEmission || d . unlocked || 0
48- } ) ) ;
49- } catch {
50- return [ ] ;
51- }
52- }
53-
5436export async function balance (
5537 owners : string [ ] ,
5638 target : string ,
5739 chain : any ,
5840 adapter : string ,
5941 timestampDeployed : number ,
60- backfill : boolean = false ,
61- sectionKey ?: string
42+ backfill : boolean = false
6243) : Promise < CliffAdapterResult [ ] > {
6344 let trackedTimestamp : number ;
6445 let decimals : number ;
@@ -74,48 +55,41 @@ export async function balance(
7455 } ) ,
7556 ] ) ;
7657
77- try {
78- const chainData = await findBlockHeightArray ( trackedTimestamp , chain ) ;
58+ const chainData = await findBlockHeightArray ( trackedTimestamp , chain ) ;
7959
80- await PromisePool . withConcurrency ( 10 )
81- . for ( Object . keys ( chainData ) )
82- . process ( async ( block ) =>
83- target == GAS_TOKEN
84- ? await PromisePool . withConcurrency ( 10 )
85- . for ( owners )
86- . process ( async ( target ) => {
87- getBalance ( {
88- target,
89- block : Number ( block ) ,
90- chain,
91- } ) . then ( ( r : any ) => {
92- if ( ! r . output )
93- throw new Error ( `balance call failed for ${ adapter } ` ) ;
94- if ( ! chainData [ block ] . result ) chainData [ block ] . result = 0 ;
95- chainData [ block ] . result += Number ( r . output ) ;
96- } ) ;
97- } )
98- : await multiCall ( {
99- calls : owners . map ( ( o : string ) => ( { target, params : [ o ] } ) ) ,
100- abi : "erc20:balanceOf" ,
101- chain,
102- block,
103- requery : true ,
104- } ) . then ( ( r : ( number | null ) [ ] ) => {
105- if ( r . includes ( null ) )
106- throw new Error ( `balance call failed for ${ adapter } ` ) ;
107- chainData [ block ] . result = r . reduce (
108- ( p : number , c : any ) => Number ( p ) + Number ( c ) ,
109- 0 ,
110- ) ;
111- } ) ,
112- ) ;
60+ await PromisePool . withConcurrency ( 10 )
61+ . for ( Object . keys ( chainData ) )
62+ . process ( async ( block ) =>
63+ target == GAS_TOKEN
64+ ? await PromisePool . withConcurrency ( 10 )
65+ . for ( owners )
66+ . process ( async ( target ) => {
67+ getBalance ( {
68+ target,
69+ block : Number ( block ) ,
70+ chain,
71+ } ) . then ( ( r : any ) => {
72+ if ( ! r . output )
73+ throw new Error ( `balance call failed for ${ adapter } ` ) ;
74+ if ( ! chainData [ block ] . result ) chainData [ block ] . result = 0 ;
75+ chainData [ block ] . result += Number ( r . output ) ;
76+ } ) ;
77+ } )
78+ : await multiCall ( {
79+ calls : owners . map ( ( o : string ) => ( { target, params : [ o ] } ) ) ,
80+ abi : "erc20:balanceOf" ,
81+ chain,
82+ block,
83+ requery : true ,
84+ } ) . then ( ( r : ( number | null ) [ ] ) => {
85+ if ( r . includes ( null ) )
86+ throw new Error ( `balance call failed for ${ adapter } ` ) ;
87+ chainData [ block ] . result = r . reduce (
88+ ( p : number , c : any ) => Number ( p ) + Number ( c ) ,
89+ 0 ,
90+ ) ;
91+ } ) ,
92+ ) ;
11393
114- return filterRawAmounts ( chainData , decimals ) ;
115- } catch {
116- if ( sectionKey ) {
117- return await getStoredEmissions ( adapter , sectionKey ) ;
118- }
119- return [ ] ;
120- }
94+ return filterRawAmounts ( chainData , decimals ) ;
12195}
0 commit comments