Skip to content

OUSG: Adding XRP Balance Pull #15043

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions projects/ondofinance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@ const { getTokenSupplies } = require("../helper/solana");
const sui = require("../helper/chain/sui");
const { aQuery } = require("../helper/chain/aptos");
const { get } = require("../helper/http");
const {post} = require("../helper/http");

const RIPPLE_ENDPOINT = 'https://s1.ripple.com:51234';

async function getXrplTokenBalances(issuer_acct, currency_code) {
const body = {
method: 'gateway_balances',
params: [{ account: issuer_acct, ledger_index: 'validated' }]
};
const res = await post(RIPPLE_ENDPOINT, body);

const obligations = res.result.obligations?.[currency_code] ?? "0";

let frozenAmount = 0;
if (res.result.frozen_balances) {
const frozenBalances = Object.values(res.result.frozen_balances)
.flat() // Flatten the balances for each user into a single array
.filter((balance) => balance.currency === currency_code) // Filter for OUSG currency
frozenBalances.forEach((balance) => {
frozenAmount = frozenAmount + parseFloat(balance.value)
});
}

const totalAmount = (parseFloat(obligations) + frozenAmount);

return totalAmount;
}

module.exports = {
methodology: "Sums the total supplies of Ondo's issued tokens.",
Expand Down Expand Up @@ -36,6 +63,9 @@ const config = {
arbitrum: {
USDY: "0x35e050d3C0eC2d29D269a8EcEa763a183bDF9A9D",
},
ripple: {
OUSG: "4F55534700000000000000000000000000000000.rHuiXXjHLpMP8ZE9sSQU5aADQVWDwv6h5p",
},
};

async function getUSDYTotalSupplySUI() {
Expand Down Expand Up @@ -72,6 +102,12 @@ Object.keys(config).forEach((chain) => {
} else if (chain === "noble") {
const res = await get(`https://rest.cosmos.directory/noble/cosmos/bank/v1beta1/supply/by_denom?denom=ausdy`);
api.addTokens(config.noble.USDY, parseInt(res.amount.amount));
} else if (chain === "ripple") {
const split = config.ripple.OUSG.split('.');
const XRPL_OUSG_CURRENCY = split[0];
const XRPL_OUSG_ISSUER = split[1];
const ousgSupply = await getXrplTokenBalances(XRPL_OUSG_ISSUER, XRPL_OUSG_CURRENCY);
api.addTokens(config.ripple.OUSG, ousgSupply);
} else {
supplies = await api.multiCall({ abi: "erc20:totalSupply", calls: fundAddresses, })
api.addTokens(fundAddresses, supplies);
Expand Down
Loading