@@ -25,27 +25,49 @@ const CBBTC = {
2525 arbitrum : '0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf' ,
2626} ;
2727
28+ const fetchQueuedWithdrawalsAbi = "function fetchQueuedWithdrawals(address staker) view returns (tuple(address staker, address delegatedTo, uint256 nonce, uint256 start, tuple(address[] vaults, uint256[] shares, address withdrawer) request)[] queuedWithdrawals)"
29+ const isWithdrawPendingAbi = "function isWithdrawPending(tuple(address staker, address delegatedTo, uint256 nonce, uint256 start, tuple(address[] vaults, uint256[] shares, address withdrawer) request) withdrawal) view returns (bool)"
30+
31+ async function get_karak_btc_withdrawals ( timestamp ) {
32+ const api = new sdk . ChainApi ( { timestamp, chain : 'ethereum' } )
33+ const karak_btc = await api . call ( { target : '0xAfa904152E04aBFf56701223118Be2832A4449E0' , abi : fetchQueuedWithdrawalsAbi , params : [ '0x657e8C867D8B37dCC18fA4Caead9C45EB088C642' ] } )
34+ let total_btc_in_queued_withdrawals = 0
35+ for ( const withdrawal of karak_btc ) {
36+ const isWithdrawPending = await api . call ( { target : '0xAfa904152E04aBFf56701223118Be2832A4449E0' , abi : isWithdrawPendingAbi , params : [ withdrawal ] } )
37+ if ( isWithdrawPending ) {
38+ for ( const share of withdrawal . request . shares ) {
39+ total_btc_in_queued_withdrawals += Number ( share )
40+ }
41+ }
42+ }
43+ return total_btc_in_queued_withdrawals
44+ }
45+
2846async function ebtc_staking ( timestamp ) {
2947 if ( timestamp < 1746507563 ) return [ 0n , 0n , 0n ] ;
3048
3149 const EBTC = '0x657e8C867D8B37dCC18fA4Caead9C45EB088C642' ;
3250 let wbtc_held = 0n , lbtc_held = 0n , cbbtc_held = 0n ;
3351
3452 const collectBalances = async ( tokens , accumulator ) => {
53+ let sum = accumulator ;
3554 for ( const [ chain , token ] of Object . entries ( tokens ) ) {
3655 const result = await sdk . api . erc20 . balanceOf ( {
3756 target : token ,
3857 owner : EBTC ,
3958 chain,
4059 timestamp,
4160 } ) ;
42- accumulator += BigInt ( result . output ) ;
61+ sum += BigInt ( result . output ) ;
4362 }
63+ return sum ;
4464 } ;
65+
66+ wbtc_held = await collectBalances ( WBTC , wbtc_held ) ;
67+ lbtc_held = await collectBalances ( LBTC , lbtc_held ) ;
68+ cbbtc_held = await collectBalances ( CBBTC , cbbtc_held ) ;
4569
46- await collectBalances ( WBTC , wbtc_held ) ;
47- await collectBalances ( LBTC , lbtc_held ) ;
48- await collectBalances ( CBBTC , cbbtc_held ) ;
70+ console . log ( wbtc_held , lbtc_held , cbbtc_held ) ;
4971
5072 const getEthBalance = async ( token , owner ) => {
5173 const result = await sdk . api . erc20 . balanceOf ( {
@@ -65,7 +87,9 @@ async function ebtc_staking(timestamp) {
6587 getEthBalance ( LBTC . ethereum , '0xd4E20ECA1f996Dab35883dC0AD5E3428AF888D45' ) ,
6688 ] ) ;
6789
68- lbtc_held += ethExtras [ 0 ] + ethExtras [ 2 ] + ethExtras [ 4 ] ;
90+ const karak_btc_withdrawals = await get_karak_btc_withdrawals ( timestamp ) ;
91+
92+ lbtc_held += ethExtras [ 0 ] + ethExtras [ 2 ] + ethExtras [ 4 ] + BigInt ( karak_btc_withdrawals ) ;
6993 wbtc_held += ethExtras [ 1 ] + ethExtras [ 3 ] ;
7094
7195 return [ lbtc_held , wbtc_held , cbbtc_held ] ;
0 commit comments