-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Add ZigChain TVL for DeFa , as DeFa is live on zigchain is well now #18706
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
strugglingfrfr
wants to merge
5
commits into
DefiLlama:main
Choose a base branch
from
strugglingfrfr:defa-stats-update
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.
+43
−37
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3468c32
Add ZigChain TVL support for DeFa protocol
strugglingfrfr 1a30d39
Merge branch 'main' into defa-stats-update
strugglingfrfr 41a555d
fix: use callSoroban for structured ScVal parsing, add misrepresented…
strugglingfrfr ffafbac
remove stale tvl() helper referencing removed getActiveTvl()
strugglingfrfr 4b074b4
validate TVL numeric coercion, fix zigchain typo
strugglingfrfr 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,51 +1,55 @@ | ||
| const axios = require("axios"); | ||
| const { callSoroban } = require("../helper/chain/stellar"); | ||
| const { queryContract } = require("../helper/chain/cosmos"); | ||
|
|
||
| const RPC_URL = "https://soroban-rpc.mainnet.stellar.gateway.fm"; | ||
| // ============================================================ | ||
| // Stellar — Soroban TVL Logger (get_active_tvl) | ||
| // Queries the on-chain Logger contract via Soroban RPC simulation. | ||
| // The contract returns active vault liquidity denominated in USD | ||
| // with 7 decimal places. | ||
| // ============================================================ | ||
|
|
||
| const SIM_TX = | ||
| "AAAAAgAAAABInMr//HjTQ5mfaqRBHzYCJKEHrM2r8m9/4lm9PBoMVgABhqAAAAAAAAAAAgAAAAEAAAAAAAAAAAAAAABpkzaBAAAAAAAAAAEAAAAAAAAAGAAAAAAAAAAB61PtVr2XWjuuWsIcyFlAq888asA0bR8BnY/AeIm0wxQAAAAOZ2V0X2FjdGl2ZV90dmwAAAAAAAAAAAAAAAAAAAAAAAA="; | ||
| const STELLAR_CONTRACT = "CDVVH3KWXWLVUO5OLLBBZSCZICV46PDKYA2G2HYBTWH4A6EJWTBRIXRK"; | ||
|
|
||
| async function getActiveTvl() { | ||
| const body = { | ||
| jsonrpc: "2.0", | ||
| id: 1, | ||
| method: "simulateTransaction", | ||
| params: { | ||
| transaction: SIM_TX, | ||
| }, | ||
| }; | ||
| async function stellarTvl(api) { | ||
| const activeTvl = await callSoroban(STELLAR_CONTRACT, "get_active_tvl"); | ||
|
|
||
| const { data: json } = await axios.post(RPC_URL, body, { | ||
| headers: { "Content-Type": "application/json" }, | ||
| }); | ||
| if (!activeTvl) throw new Error("Stellar TVL is zero"); | ||
|
|
||
| api.addCGToken("usd-coin", Number(activeTvl) / 1e7); | ||
| return api.getBalances(); | ||
| } | ||
|
|
||
| const xdr = json?.result?.results?.[0]?.xdr; | ||
| if (!xdr) throw new Error("TVL value not returned from Soroban simulation"); | ||
| // ============================================================ | ||
| // ZigChain — CosmWasm TVL Logger (active_tvl) | ||
| // Queries the on-chain Logger contract via LCD REST endpoint. | ||
| // The contract returns active liquidity in DeFa zigchian contracts denominated in USD | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // with 6 decimal places. | ||
| // ============================================================ | ||
|
|
||
| const ZIGCHAIN_TVL_CONTRACT = "zig19pp9rxhqktgpf2yqkwwx6yekmgvnu3hvj0c4e5rlpw88l0shh3qs9qcdyg"; | ||
|
|
||
| async function zigchainTvl(api) { | ||
| const activeTvl = await queryContract({ | ||
| contract: ZIGCHAIN_TVL_CONTRACT, | ||
| chain: "zigchain", | ||
| data: { active_tvl: {} }, | ||
| }); | ||
|
|
||
| // Decode u128 from last 16 bytes (matches your SIM_TX output) | ||
| const buffer = Buffer.from(xdr, "base64"); | ||
| const value = BigInt("0x" + buffer.slice(-16).toString("hex")); | ||
| if (!activeTvl || activeTvl === "0") throw new Error("ZigChain TVL is zero"); | ||
|
|
||
| return value; | ||
| api.addCGToken("usd-coin", Number(activeTvl) / 1e6); | ||
| return api.getBalances(); | ||
| } | ||
|
|
||
| async function tvl(api) { | ||
| const activeTvl = await getActiveTvl(); | ||
|
|
||
| if (activeTvl === 0n) throw new Error("TVL is zero"); | ||
|
|
||
| const normalized = Number(activeTvl) / 1e7; | ||
| api.addCGToken("usd-coin", normalized); | ||
|
|
||
| return api.getBalances(); | ||
| } | ||
|
|
||
| // ============================================================ | ||
| // Export | ||
| // ============================================================ | ||
|
|
||
| module.exports = { | ||
| timetravel: false, | ||
| misrepresentedTokens: true, | ||
| methodology: | ||
| "TVL represents the total active liquidity across invoice-backed pools as reported directly by the on-chain Logger contract via Soroban simulation (get_active_tvl).", | ||
| stellar: { | ||
| tvl, | ||
| }, | ||
| "TVL is the total active liquidity across invoice-backed pools, reported by on-chain Logger contracts on Stellar (Soroban) and ZigChain (CosmWasm).", | ||
| stellar: { tvl: stellarTvl }, | ||
| zigchain: { tvl: zigchainTvl }, | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.