From 52eb659c5a622b650822abc2336f44bde7e15320 Mon Sep 17 00:00:00 2001 From: MadReza Date: Wed, 25 Dec 2024 17:23:30 +0330 Subject: [PATCH] feat: add Pryzm Protocol tvl adapter --- projects/helper/chain/cosmos.js | 3 +- projects/helper/chains.json | 1 + projects/helper/tokenMapping.js | 2 +- projects/pryzm/index.js | 87 +++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 projects/pryzm/index.js diff --git a/projects/helper/chain/cosmos.js b/projects/helper/chain/cosmos.js index a315e9bb129c..70ca3bc69ba8 100644 --- a/projects/helper/chain/cosmos.js +++ b/projects/helper/chain/cosmos.js @@ -43,7 +43,8 @@ const endPoints = { nibiru: "https://lcd.nibiru.fi", bostrom: "https://lcd.bostrom.cybernode.ai", joltify: "https://lcd.joltify.io", - noble: "https://noble-api.polkachu.com" + noble: "https://noble-api.polkachu.com", + pryzm: "https://api.pryzm.zone" }; const chainSubpaths = { diff --git a/projects/helper/chains.json b/projects/helper/chains.json index 81a6e959c201..11846b417192 100644 --- a/projects/helper/chains.json +++ b/projects/helper/chains.json @@ -263,6 +263,7 @@ "pool2", "posi", "proton", + "pryzm", "pulse", "q", "quasar", diff --git a/projects/helper/tokenMapping.js b/projects/helper/tokenMapping.js index 970173165969..ad06490f1181 100644 --- a/projects/helper/tokenMapping.js +++ b/projects/helper/tokenMapping.js @@ -18,7 +18,7 @@ coreAssets = JSON.parse(JSON.stringify(coreAssets)) // orbit brige: https://bridge.orbitchain.io/open/v1/api/monitor/rawTokenList -const ibcChains = ['ibc', 'terra', 'terra2', 'crescent', 'osmosis', 'kujira', 'stargaze', 'juno', 'injective', 'cosmos', 'comdex', 'umee', 'orai', 'persistence', 'fxcore', 'neutron', 'quasar', 'chihuahua', 'sei', 'archway', 'migaloo', 'secret', 'aura', 'xpla', 'bostrom', 'joltify', 'nibiru'] +const ibcChains = ['ibc', 'terra', 'terra2', 'crescent', 'osmosis', 'kujira', 'stargaze', 'juno', 'injective', 'cosmos', 'comdex', 'umee', 'orai', 'persistence', 'fxcore', 'neutron', 'quasar', 'chihuahua', 'sei', 'archway', 'migaloo', 'secret', 'aura', 'xpla', 'bostrom', 'joltify', 'nibiru', "pryzm"] const caseSensitiveChains = [...ibcChains, 'solana', 'tezos', 'ton', 'algorand', 'aptos', 'near', 'bitcoin', 'waves', 'tron', 'litecoin', 'polkadot', 'ripple', 'elrond', 'cardano', 'stacks', 'sui', 'ergo', 'mvc', 'renec', 'doge', 'stellar', 'massa', 'eclipse', ] diff --git a/projects/pryzm/index.js b/projects/pryzm/index.js new file mode 100644 index 000000000000..de3b85b3dd45 --- /dev/null +++ b/projects/pryzm/index.js @@ -0,0 +1,87 @@ +const { get } = require('../helper/http') +const sdk = require("@defillama/sdk"); +const { endPoints, sumTokens, getBalance2 } = require('../helper/chain/cosmos'); + +const host_chains = { + cosmos: { + hostChainId: "uatom", + coinGeckoId: "cosmos", + decimals: 1e6, + }, + + injective: { + hostChainId: "inj", + coinGeckoId: "injective-protocol", + decimals: 1e18, + }, + + osmosis: { + hostChainId: "uosmo", + coinGeckoId: "osmosis", + decimals: 1e6, + }, + + terra2: { + hostChainId: "uluna", + coinGeckoId: "terra-luna-2", + decimals: 1e6, + }, + + celestia: { + hostChainId: "utia", + coinGeckoId: "celestia", + decimals: 1e6, + }, +}; + +const endpoint = endPoints["pryzm"] +const amm_vault_address = "pryzm1y7d08j5uy7kgurnv4pwag8h34m2cgptcwe75wn"; + +function tvlOnChain(chain) { + return async () => { + const [{ amount: coin }, { host_chain_state: state }] = + await Promise.all([ + await get(`${endpoint}/cosmos/bank/v1beta1/supply/by_denom?denom=c:${chain.hostChainId}`), + await get(`${endpoint}/pryzm/icstaking/v1/host_chain_state/${chain.hostChainId}`), + ]); + + const balance = coin.amount * state.exchange_rate / chain.decimals; + + const balances = {}; + + sdk.util.sumSingleBalance( + balances, + chain.coinGeckoId, + balance + ); + + return balances; + }; +} + +async function tvl(api) { + const { balances: data } = + await get(`${endpoint}/cosmos/bank/v1beta1/balances/${amm_vault_address}?pagination.limit=1000`); + + for (const { denom, amount } of data) { + if (denom.startsWith("c:") || + denom.startsWith("p:") || + denom.startsWith("y:") || + denom.startsWith("lp:") + ) { + continue + } + api.add(denom, amount); + } +} + +module.exports = { + methodology: "Counts the liquidity on liquid staking module and all AMM pools", + pryzm: { + tvl + }, +}; + +for (const chainName of Object.keys(host_chains)) { + module.exports[chainName] = { tvl: tvlOnChain(host_chains[chainName]) }; +} \ No newline at end of file