-
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
Open
anch09
wants to merge
7
commits into
DefiLlama:main
Choose a base branch
from
hermetica-fi:hermetica-hbtc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+38
−45
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a0a398c
feat: add hermetica hbtc token and adapter
anch09 0ceaa0d
fix: delete unused import
anch09 5288679
fix: update methodology
anch09 b334c22
fix: use call helper
anch09 cf7d91f
fix: update hermetica usdh
anch09 71a9cea
fix: extract value from clarity value
anch09 c3abd92
fix: update micro share price value
anch09 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| const hBTCSupplyStacks = Number(microhBTCSupplyStacks.value) / (10 ** 8); | ||
|
|
||
| return { bitcoin: hBTCSupplyStacks * sharePrice }; | ||
| } | ||
| }, | ||
| misrepresentedTokens: false | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you remove
.valuehere, get-share-price returns only a numberUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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
callfunction will work. Looking at the main branch's package.json file doesn't contain the dependencies that the stackscallfunction wrapper need.