Skip to content
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

added bitcoin #12560

Open
wants to merge 6 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
91 changes: 33 additions & 58 deletions projects/fluidtokens/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,95 +9,70 @@ const { get } = require("../helper/http");
const smartContractAddress =
"addr1wxzqzlncct5g0686c07lyuq3q3j2a0t8l88uwdznw99k9asz6z0hq";

const tvl_onchain = async () => {
let utxos = await getAddressesUTXOs(smartContractAddress);

let utxosWithRedeemer = []; // Only the UTXO with redeemer have actually been taken and are and active loan

const { errors } = await PromisePool.withConcurrency(10)
.for(utxos)
.process(async (utxo) => {
const redeemer = await getTxsRedeemers(utxo.tx_hash);
if (redeemer.length > 0) utxosWithRedeemer.push(utxo);
});

if (errors && errors.length) throw errors[0];

let loanDetails = [];

const { errors: errors1 } = await PromisePool.withConcurrency(10)
.for(utxosWithRedeemer)
.process(async (utxo) => {
const details = await getTxsMetadata(utxo.tx_hash);
loanDetails.push(details[0].json_metadata);
});

if (errors1 && errors1.length) throw errors1[0];

const TVL = loanDetails.reduce((x, y) => {
return x + parseInt(y.AMOUNT);
}, 0);
return {
cardano: TVL / 1e6,
};
};

async function tvl() {
// Function to calculate Cardano TVL
async function cardanoTvl() {
const dataOffers = await get("https://api.fluidtokens.com/get-available-collection-offers");
let SC_offers_tvl = 0;

dataOffers.forEach((i) => {
SC_offers_tvl += parseInt(i.offerData.loanAmnt);
});
SC_offers_tvl += parseInt(i.offerData.loanAmnt);
});

const repay_tvl = parseInt(await get("https://api.fluidtokens.com/get-total-available-repayments"));
const pools_tvl = parseInt(await get("https://api.fluidtokens.com/get-total-available-pools"));

const boosted_tvl = await get("https://api.fluidtokens.com/get-ft-stats");
const boosted = parseInt(boosted_tvl.bs_available_volume) + parseInt(boosted_tvl.bs_active_volume);

const pools_tvl= parseInt(await get("https://api.fluidtokens.com/get-total-available-pools"));
// Summing relevant TVL sources for Cardano
return (SC_offers_tvl + pools_tvl + boosted) / 1e6;
}

const boosted_tvl= await get("https://api.fluidtokens.com/get-ft-stats");
// Function to calculate Bitcoin TVL
async function bitcoinTvl() {
const btc_staking = await get("https://api2.fluidtokens.com/get-staking-stats");
const btc_satoshi = parseInt(btc_staking.totalTvl);

const boosted=parseInt(boosted_tvl.bs_available_volume)+parseInt(boosted_tvl.bs_active_volume);

return {
// cardano: (SC_offers_tvl+repay_tvl+pools_tvl+boosted) / 1e6,
cardano: (SC_offers_tvl+pools_tvl+boosted) / 1e6,
};
// Convert Satoshis to Bitcoin
return btc_satoshi / 1e8;
}

async function staking() {
const data = await get("https://api.fluidtokens.com/get-ft-stats");
let staking = parseInt(data.staking_tvl);

return {
cardano: (staking) / 1e6,
cardano: staking / 1e6 ,
};
}

async function borrowed() {
const data = await get("https://api.fluidtokens.com/get-ft-stats");
let SC_tvl = parseInt(data.active_loans_volume);


const dataOffers = await get("https://api.fluidtokens.com/get-available-collection-offers");
let SC_offers_tvl = 0;

dataOffers.forEach((i) => {
SC_offers_tvl += parseInt(i.offerData.loanAmnt);
});
SC_offers_tvl += parseInt(i.offerData.loanAmnt);
});

return {
cardano: (SC_tvl) / 1e6,
cardano: SC_tvl / 1e6,
};
}


// Updated exports
module.exports = {
methodology: "Count active loaned out ADA as tvl",
methodology: "Count active liquidity as TVL",
timetravel: false,
cardano: {
tvl,
tvl: async () => ({ cardano: await cardanoTvl() }),
borrowed,
staking
staking,
},
bitcoin: {
tvl: async () => ({ bitcoin: await bitcoinTvl() }),
},
hallmarks: [
[Math.floor(new Date("2023-01-01") / 1e3), "Count only active loans"],
Expand Down
Loading