Skip to content

Commit 73c61c3

Browse files
authored
Merge pull request #1 from DefiLlama/main (DefiLlama#14757)
1 parent 634aca9 commit 73c61c3

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

projects/ether-fi/index.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
2846
async 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

Comments
 (0)