Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion projects/helper/coreAssets.json
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,8 @@
"aeUSDC": "SP3Y2ZSH8P7D50B0VBTSX11S7XSG24M1VB9YFQA4K.token-aeusdc",
"aBTC": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-abtc::bridged-btc",
"USDCx": "SP120SBRBQJ00MCWS7TM5R8WJNTTKD5K0HFRC2CNE.usdcx",
"USDh": "SPN5AKG35QZSK2M8GAMR4AFX45659RJHDW353HSG.usdh-token-v1"
"USDh": "SPN5AKG35QZSK2M8GAMR4AFX45659RJHDW353HSG.usdh-token-v1",
"hBTC": "SP1S1HSFH0SQQGWKB69EYFNY0B1MHRMGXR3J1FH4D.token-hbtc"
},
"neon_evm": {
"WNEON": "0xb14760c064a1b9eaf9ec5a8a421971e40a51b59c"
Expand Down
24 changes: 24 additions & 0 deletions projects/hermetica-hbtc/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const ADDRESSES = require('../helper/coreAssets.json')
const { call } = require('../helper/chain/stacks-api')

const hBTCContract = ADDRESSES.stacks.hBTC;
const hBTCStateContract = 'SP1S1HSFH0SQQGWKB69EYFNY0B1MHRMGXR3J1FH4D.state-hbtc-v1';

module.exports = {
methodology: 'TVL is calculated as total hBTC minted on Stacks multiplied by the current share price, expressed in BTC.',
timetravel: false,
stacks: {
tvl: async () => {
const [microhBTCSupplyStacks, microSharePrice] = await Promise.all([
call({ target: hBTCContract, abi: 'get-total-supply' }),
call({ target: hBTCStateContract, abi: 'get-share-price' })
]);

const sharePrice = Number(microSharePrice.value) / (10 ** 8);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove .value here, get-share-price returns only a number

Copy link
Copy Markdown
Contributor Author

@anch09 anch09 Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just removed this. But I'm still not fully convinced that the call function will work. Looking at the main branch's package.json file doesn't contain the dependencies that the stacks call function wrapper need.

const stacks = require('@stacks/transactions')
const { STACKS_MAINNET, } = require('@stacks/network')
const { createApiKeyMiddleware, createFetchFn } = require('@stacks/common')

const hBTCSupplyStacks = Number(microhBTCSupplyStacks.value) / (10 ** 8);

return { bitcoin: hBTCSupplyStacks * sharePrice };
}
},
misrepresentedTokens: false
}
56 changes: 12 additions & 44 deletions projects/hermetica/index.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,32 @@
const ADDRESSES = require('../helper/coreAssets.json')
const { get, post } = require('../helper/http')
const { get } = require('../helper/http')
const { call } = require('../helper/chain/stacks-api')

const USDhContract = ADDRESSES.stacks.USDh;

function parseClarityInt(hexString) {
// Remove "0x" prefix
let hex = hexString.startsWith("0x") ? hexString.slice(2) : hexString;

// Skip the first two bytes (Clarity type and metadata)
let numberHex = hex.slice(4); // Remove first 2 bytes (4 hex characters)

// Convert hex to BigInt
let bigIntValue = BigInt("0x" + numberHex);

// Handle two’s complement for negative numbers
if (bigIntValue > BigInt("0x7ffffffffffffffffffffffffffffffff")) {
bigIntValue = bigIntValue - BigInt("0x100000000000000000000000000000000");
}

return bigIntValue.toString(); // Return as a readable decimal string
}

module.exports = {
methodology: 'Counts the number of USDh tokens on Stacks and Bitcoin (Runes).',
timetravel: false,
bitcoin: {
tvl: async () => {
const { result: totalSupply } = await get('https://app.hermetica.fi/api/v1/usdh/supply');

const [contract_address, contract_name] = USDhContract.split('.');
const supplyResponse = await post(`https://api.mainnet.hiro.so/v2/contracts/call-read/${contract_address}/${contract_name}/get-total-supply`,
{
sender: contract_address,
arguments: []
}
);
const uUSDhSupplyStacks = Number(parseClarityInt(supplyResponse.result));
const [supply, uUSDhSupplyStacks] = await Promise.all([
get('https://app.hermetica.fi/api/v1/usdh/supply'),
call({ target: USDhContract, abi: 'get-total-supply' })
]);

const cleanUsdhSupply = totalSupply.replace(/[^\d.]/g, '');
const totalUsdhSupply = Number(cleanUsdhSupply);
const totaluUSDhSupply = totalUsdhSupply * (10 ** 8);

const sUSDhSupplyRunes = totaluUSDhSupply - uUSDhSupplyStacks;
const cleanUsdhSupply = supply.result.replace(/[^\d.]/g, '');
const totaluUSDhSupply = Number(cleanUsdhSupply) * (10 ** 8);
const sUSDhSupplyRunes = totaluUSDhSupply - Number(uUSDhSupplyStacks.value);

return { 'hermetica-usdh': sUSDhSupplyRunes / (10 ** 8) }
}
},
stacks: {
tvl: async () => {
const [contract_address, contract_name] = USDhContract.split('.');
const supplyResponse = await post(`https://api.mainnet.hiro.so/v2/contracts/call-read/${contract_address}/${contract_name}/get-total-supply`,
{
sender: contract_address,
arguments: []
}
);
const supplyOnStacksuUsdh = Number(parseClarityInt(supplyResponse.result));
const supplyOnStacksuUsdh = await call({ target: USDhContract, abi: 'get-total-supply' });

return { 'hermetica-usdh': supplyOnStacksuUsdh / (10 ** 8) }
return { 'hermetica-usdh': Number(supplyOnStacksuUsdh.value) / (10 ** 8) }
}
},
misrepresentedTokens: true
}
}
Loading