Skip to content

Commit 0596fc1

Browse files
feat: add staking support to Udon protocol on Chromia (#17031)
Co-authored-by: g1nt0ki <[email protected]>
1 parent 839889b commit 0596fc1

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

projects/udon-staking/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { fetchURL } = require('../helper/utils');
2+
3+
const BASE_URL = 'https://mainnet-dapp1.sunube.net:7740/query';
4+
const BLOCKCHAIN_RID = 'F4E33267A8FF1ACCE3C6D7B441B8542FB84FF6DAA5114105563D2AA34979BEF6';
5+
6+
function buildQueryUrl(queryType, params = {}) {
7+
const url = `${BASE_URL}/${BLOCKCHAIN_RID}?type=${queryType}`;
8+
const queryParams = new URLSearchParams(params).toString();
9+
return queryParams ? `${url}&${queryParams}` : url;
10+
}
11+
12+
async function tvl(api) {
13+
const { data: totalStakeRaw } = await fetchURL(buildQueryUrl('get_total_stake_all_users'));
14+
15+
api.add('5F16D1545A0881F971B164F1601CBBF51C29EFD0633B2730DA18C403C3B428B5', totalStakeRaw);
16+
}
17+
18+
module.exports = {
19+
timetravel: false,
20+
chromia: {
21+
tvl
22+
},
23+
}

projects/udon/index.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
const { sumTokens2 } = require('../helper/unwrapLPs');
2-
const { fetchURL } = require('../helper/utils')
2+
const { fetchURL } = require('../helper/utils');
3+
4+
const BASE_URL = 'https://mainnet-dapp1.sunube.net:7740/query';
5+
const BLOCKCHAIN_RID = 'F4E33267A8FF1ACCE3C6D7B441B8542FB84FF6DAA5114105563D2AA34979BEF6';
6+
7+
function buildQueryUrl(queryType, params = {}) {
8+
const url = `${BASE_URL}/${BLOCKCHAIN_RID}?type=${queryType}`;
9+
const queryParams = new URLSearchParams(params).toString();
10+
return queryParams ? `${url}&${queryParams}` : url;
11+
}
312

413
async function tvl(api, isBorrows) {
5-
const { data } = await fetchURL("https://mainnet-dapp1.sunube.net:7740/query/F4E33267A8FF1ACCE3C6D7B441B8542FB84FF6DAA5114105563D2AA34979BEF6?type=get_stats_supply_deposit");
14+
const { data } = await fetchURL(
15+
buildQueryUrl('get_stats_supply_deposit')
16+
);
17+
18+
19+
data.forEach(({ asset_id, total_borrow, total_deposit }) => {
20+
const balance = isBorrows ? total_borrow : total_deposit - total_borrow;
21+
api.add(asset_id, balance);
22+
});
623

7-
data.map(({ asset_id, total_borrow, total_deposit, price, decimals }) => {
8-
// const multiplier = price/10 **decimals
9-
// total_borrow = total_borrow * multiplier
10-
// total_deposit = total_deposit * multiplier
11-
// const balance = isBorrows ? total_borrow : total_deposit - total_borrow
12-
// api.addUSDValue(balance)
13-
const balance = isBorrows ? total_borrow : total_deposit - total_borrow
14-
api.add(asset_id, balance)
15-
})
16-
return sumTokens2({ api })
24+
return sumTokens2({ api });
1725
}
1826

1927
module.exports = {

0 commit comments

Comments
 (0)