-
Notifications
You must be signed in to change notification settings - Fork 7k
feat: add hermetica hbtc token and adapter #18479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
a0a398c
0ceaa0d
5288679
b334c22
cf7d91f
71a9cea
c3abd92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| const ADDRESSES = require('../helper/coreAssets.json') | ||
| const { makeReadOnlyContractCall } = require('../hermetica/stacks-call') | ||
|
|
||
| const hBTCContract = ADDRESSES.stacks.hBTC; | ||
| const hBTCStateContract = 'SP1S1HSFH0SQQGWKB69EYFNY0B1MHRMGXR3J1FH4D.state-hbtc-v1'; | ||
|
|
||
| module.exports = { | ||
| methodology: 'Counts the number of hBTC tokens on Stacks.', | ||
| timetravel: false, | ||
| stacks: { | ||
| tvl: async () => { | ||
| const [microhBTCSupplyStacks, microSharePrice] = await Promise.all([ | ||
| makeReadOnlyContractCall({ contract: hBTCContract, function_name: 'get-total-supply' }), | ||
| makeReadOnlyContractCall({ contract: hBTCStateContract, function_name: 'get-share-price' }) | ||
|
||
| ]); | ||
|
|
||
| const sharePrice = microSharePrice / (10 ** 8); | ||
| const hBTCSupplyStacks = microhBTCSupplyStacks / (10 ** 8); | ||
|
|
||
| return { bitcoin: hBTCSupplyStacks * sharePrice }; | ||
| } | ||
| }, | ||
| misrepresentedTokens: false | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,64 +1,35 @@ | ||
| const ADDRESSES = require('../helper/coreAssets.json') | ||
| const { get, post } = require('../helper/http') | ||
| const { get } = require('../helper/http') | ||
| const { makeReadOnlyContractCall } = require('./stacks-call') | ||
|
|
||
| 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 cleanUsdhSupply = totalSupply.replace(/[^\d.]/g, ''); | ||
| const totalUsdhSupply = Number(cleanUsdhSupply); | ||
| const totaluUSDhSupply = totalUsdhSupply * (10 ** 8); | ||
| const [supply, uUSDhSupplyStacks] = await Promise.all([ | ||
| get('https://app.hermetica.fi/api/v1/usdh/supply'), | ||
| makeReadOnlyContractCall({ contract: USDhContract, function_name: 'get-total-supply' }) | ||
| ]); | ||
|
|
||
| const cleanUsdhSupply = supply.result.replace(/[^\d.]/g, ''); | ||
| const totaluUSDhSupply = Number(cleanUsdhSupply) * (10 ** 8); | ||
| const sUSDhSupplyRunes = totaluUSDhSupply - uUSDhSupplyStacks; | ||
|
|
||
| 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 makeReadOnlyContractCall({ | ||
| contract: USDhContract, | ||
| function_name: 'get-total-supply' | ||
| }); | ||
anch09 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return { 'hermetica-usdh': supplyOnStacksuUsdh / (10 ** 8) } | ||
| } | ||
| }, | ||
| misrepresentedTokens: true | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| const { post } = require('../helper/http') | ||
|
|
||
| function parseClarityInt(hexString) { | ||
|
||
| let hex = hexString.startsWith("0x") ? hexString.slice(2) : hexString; | ||
| let numberHex = hex.slice(4); | ||
| let bigIntValue = BigInt("0x" + numberHex); | ||
| if (bigIntValue > BigInt("0x7ffffffffffffffffffffffffffffffff")) { | ||
| bigIntValue = bigIntValue - BigInt("0x100000000000000000000000000000000"); | ||
| } | ||
| return bigIntValue.toString(); | ||
| } | ||
|
|
||
| async function makeReadOnlyContractCall({ contract, function_name }) { | ||
| const [contract_address, contract_name] = contract.split('.'); | ||
| const response = await post( | ||
| `https://api.mainnet.hiro.so/v2/contracts/call-read/${contract_address}/${contract_name}/${function_name}`, | ||
| { sender: contract_address, arguments: [] } | ||
| ); | ||
| return Number(parseClarityInt(response.result)); | ||
| } | ||
|
|
||
| module.exports = { makeReadOnlyContractCall } | ||
Uh oh!
There was an error while loading. Please reload this page.