From 88cf52a7f41d22a179103ff62b1e7a96ed712764 Mon Sep 17 00:00:00 2001 From: nathanielfsn Date: Thu, 13 Nov 2025 10:28:13 +0700 Subject: [PATCH 1/2] feat: enhance Udon integration with new query functions and staking support --- projects/udon/index.js | 54 ++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/projects/udon/index.js b/projects/udon/index.js index 2e9ca7c6528..d8008f1d6c6 100644 --- a/projects/udon/index.js +++ b/projects/udon/index.js @@ -1,19 +1,46 @@ const { sumTokens2 } = require('../helper/unwrapLPs'); -const { fetchURL } = require('../helper/utils') +const { fetchURL } = require('../helper/utils'); + +const BASE_URL = 'https://mainnet-dapp1.sunube.net:7740/query'; +const BLOCKCHAIN_RID = 'F4E33267A8FF1ACCE3C6D7B441B8542FB84FF6DAA5114105563D2AA34979BEF6'; +const STCHR_ASSET_ID = '56A3ADCFF347A2D52972C390928966733E72D2189B018CB284D8C99098C6B00F'; +const STCHR_DECIMALS = 6; + +function buildQueryUrl(queryType, params = {}) { + const url = `${BASE_URL}/${BLOCKCHAIN_RID}?type=${queryType}`; + const queryParams = new URLSearchParams(params).toString(); + return queryParams ? `${url}&${queryParams}` : url; +} async function tvl(api, isBorrows) { - const { data } = await fetchURL("https://mainnet-dapp1.sunube.net:7740/query/F4E33267A8FF1ACCE3C6D7B441B8542FB84FF6DAA5114105563D2AA34979BEF6?type=get_stats_supply_deposit"); - - data.map(({ asset_id, total_borrow, total_deposit, price, decimals }) => { - // const multiplier = price/10 **decimals - // total_borrow = total_borrow * multiplier - // total_deposit = total_deposit * multiplier - // const balance = isBorrows ? total_borrow : total_deposit - total_borrow - // api.addUSDValue(balance) - const balance = isBorrows ? total_borrow : total_deposit - total_borrow - api.add(asset_id, balance) - }) - return sumTokens2({ api }) + const { data } = await fetchURL( + buildQueryUrl('get_stats_supply_deposit') + ); + + console.log("data", data); + + data.forEach(({ asset_id, total_borrow, total_deposit }) => { + const balance = isBorrows ? total_borrow : total_deposit - total_borrow; + api.add(asset_id, balance); + }); + + return sumTokens2({ api }); +} + +async function staking(api) { + const { data: totalStakeRaw } = await fetchURL( + buildQueryUrl('get_total_stake_all_users') + ); + + const { data: price } = await fetchURL( + buildQueryUrl('get_latest_price_by_asset_id', { asset_id: STCHR_ASSET_ID }) + ); + + const totalStake = Number(totalStakeRaw) / 10 ** STCHR_DECIMALS; + const tvlUsd = totalStake * price; + + api.addUSDValue(tvlUsd); + return api.getBalances(); } module.exports = { @@ -21,5 +48,6 @@ module.exports = { chromia: { tvl: (api) => tvl(api, false), borrowed: (api) => tvl(api, true), + staking: (api) => staking(api), }, } \ No newline at end of file From 02c0942b36136fae771b6e9b49030cfe41821102 Mon Sep 17 00:00:00 2001 From: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com> Date: Mon, 24 Nov 2025 22:44:05 +0100 Subject: [PATCH 2/2] refactor --- projects/udon-staking/index.js | 23 +++++++++++++++++++++++ projects/udon/index.js | 20 -------------------- 2 files changed, 23 insertions(+), 20 deletions(-) create mode 100644 projects/udon-staking/index.js diff --git a/projects/udon-staking/index.js b/projects/udon-staking/index.js new file mode 100644 index 00000000000..78c06031d0a --- /dev/null +++ b/projects/udon-staking/index.js @@ -0,0 +1,23 @@ +const { fetchURL } = require('../helper/utils'); + +const BASE_URL = 'https://mainnet-dapp1.sunube.net:7740/query'; +const BLOCKCHAIN_RID = 'F4E33267A8FF1ACCE3C6D7B441B8542FB84FF6DAA5114105563D2AA34979BEF6'; + +function buildQueryUrl(queryType, params = {}) { + const url = `${BASE_URL}/${BLOCKCHAIN_RID}?type=${queryType}`; + const queryParams = new URLSearchParams(params).toString(); + return queryParams ? `${url}&${queryParams}` : url; +} + +async function tvl(api) { + const { data: totalStakeRaw } = await fetchURL(buildQueryUrl('get_total_stake_all_users')); + + api.add('5F16D1545A0881F971B164F1601CBBF51C29EFD0633B2730DA18C403C3B428B5', totalStakeRaw); +} + +module.exports = { + timetravel: false, + chromia: { + tvl + }, +} \ No newline at end of file diff --git a/projects/udon/index.js b/projects/udon/index.js index d8008f1d6c6..3293a8f6e1f 100644 --- a/projects/udon/index.js +++ b/projects/udon/index.js @@ -3,8 +3,6 @@ const { fetchURL } = require('../helper/utils'); const BASE_URL = 'https://mainnet-dapp1.sunube.net:7740/query'; const BLOCKCHAIN_RID = 'F4E33267A8FF1ACCE3C6D7B441B8542FB84FF6DAA5114105563D2AA34979BEF6'; -const STCHR_ASSET_ID = '56A3ADCFF347A2D52972C390928966733E72D2189B018CB284D8C99098C6B00F'; -const STCHR_DECIMALS = 6; function buildQueryUrl(queryType, params = {}) { const url = `${BASE_URL}/${BLOCKCHAIN_RID}?type=${queryType}`; @@ -17,7 +15,6 @@ async function tvl(api, isBorrows) { buildQueryUrl('get_stats_supply_deposit') ); - console.log("data", data); data.forEach(({ asset_id, total_borrow, total_deposit }) => { const balance = isBorrows ? total_borrow : total_deposit - total_borrow; @@ -27,27 +24,10 @@ async function tvl(api, isBorrows) { return sumTokens2({ api }); } -async function staking(api) { - const { data: totalStakeRaw } = await fetchURL( - buildQueryUrl('get_total_stake_all_users') - ); - - const { data: price } = await fetchURL( - buildQueryUrl('get_latest_price_by_asset_id', { asset_id: STCHR_ASSET_ID }) - ); - - const totalStake = Number(totalStakeRaw) / 10 ** STCHR_DECIMALS; - const tvlUsd = totalStake * price; - - api.addUSDValue(tvlUsd); - return api.getBalances(); -} - module.exports = { timetravel: false, chromia: { tvl: (api) => tvl(api, false), borrowed: (api) => tvl(api, true), - staking: (api) => staking(api), }, } \ No newline at end of file