@@ -25,27 +25,49 @@ const CBBTC = {
25
25
arbitrum : '0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf' ,
26
26
} ;
27
27
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
+
28
46
async function ebtc_staking ( timestamp ) {
29
47
if ( timestamp < 1746507563 ) return [ 0n , 0n , 0n ] ;
30
48
31
49
const EBTC = '0x657e8C867D8B37dCC18fA4Caead9C45EB088C642' ;
32
50
let wbtc_held = 0n , lbtc_held = 0n , cbbtc_held = 0n ;
33
51
34
52
const collectBalances = async ( tokens , accumulator ) => {
53
+ let sum = accumulator ;
35
54
for ( const [ chain , token ] of Object . entries ( tokens ) ) {
36
55
const result = await sdk . api . erc20 . balanceOf ( {
37
56
target : token ,
38
57
owner : EBTC ,
39
58
chain,
40
59
timestamp,
41
60
} ) ;
42
- accumulator += BigInt ( result . output ) ;
61
+ sum += BigInt ( result . output ) ;
43
62
}
63
+ return sum ;
44
64
} ;
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 ) ;
45
69
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 ) ;
49
71
50
72
const getEthBalance = async ( token , owner ) => {
51
73
const result = await sdk . api . erc20 . balanceOf ( {
@@ -65,7 +87,9 @@ async function ebtc_staking(timestamp) {
65
87
getEthBalance ( LBTC . ethereum , '0xd4E20ECA1f996Dab35883dC0AD5E3428AF888D45' ) ,
66
88
] ) ;
67
89
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 ) ;
69
93
wbtc_held += ethExtras [ 1 ] + ethExtras [ 3 ] ;
70
94
71
95
return [ lbtc_held , wbtc_held , cbbtc_held ] ;
0 commit comments