Skip to content

Commit

Permalink
Scallop: add borrow reward apy (#1668)
Browse files Browse the repository at this point in the history
* feat: add scallop lend adaptor

* fix: tvl and apy calculation

* fix: tvl calculation and add addtional fields

* feat: add borrow reward

* refactor: minor

* feat: add ltv
  • Loading branch information
nicetomeetyou1 authored Dec 27, 2024
1 parent 313e082 commit b441084
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions src/adaptors/scallop-lend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,51 @@ const axios = require('axios');
const utils = require('../utils')

const baseUrl = 'https://sdk.api.scallop.io/api';
const marketEndpoint = `${baseUrl}/market`;
const spoolsEndpoint = `${baseUrl}/spools`;
const marketEndpoint = `${baseUrl}/market/migrate`;
const spoolsEndpoint = `${baseUrl}/spools/migrate`;
const borrowIncentiveEndpoint = `${baseUrl}/borrowIncentivePools`;

const main = async () => {
let [market, spools] = await Promise.all([axios.get(marketEndpoint), axios.get(spoolsEndpoint)]);
let [market, spools, borrowIncentive] = await Promise.all([axios.get(marketEndpoint), axios.get(spoolsEndpoint), axios.get(borrowIncentiveEndpoint)]);

const supplyRewards = {};
const rewardTokenPool = {};
spools.data.spools.forEach((spool) => {
if(spool.rewardApr <= 0) {
return;
}
supplyRewards[spool.coinType] = {
rewardApr: spool.rewardApr,
rewardCoinType: spool.rewardCoinType,
};
if(rewardTokenPool[spool.coinType] === undefined) {
rewardTokenPool[spool.coinType] = [];
}
rewardTokenPool[spool.coinType].push(spool.rewardCoinType);
});

const borrowRewards = {};
borrowIncentive.data.forEach((borrow) => {
borrow.rewards.forEach((reward) => {
if (borrowRewards[borrow.coinType] === undefined) {
borrowRewards[borrow.coinType] = [];
}
borrowRewards[borrow.coinType].push({
rewardApr: reward.rewardApr,
rewardCoinType: reward.coinType,
});
if(rewardTokenPool[borrow.coinType] === undefined) {
rewardTokenPool[borrow.coinType] = [];
}
rewardTokenPool[borrow.coinType].push(reward.coinType);
});
});

const arr = [];
market.data.pools.forEach((pool) => {
const supplyUsd = parseFloat(pool.supplyCoin) * parseFloat(pool.coinPrice);
const borrowUsd = parseFloat(pool.borrowCoin) * parseFloat(pool.coinPrice);
const collateralFactor = market.data.collaterals.find((collateral) => collateral.coinType === pool.coinType);
arr.push({
chain: 'Sui',
project: 'scallop-lend',
Expand All @@ -28,10 +55,12 @@ const main = async () => {
tvlUsd: supplyUsd - borrowUsd,
apyBase: parseFloat(pool.supplyApy * 100),
apyReward: supplyRewards[pool.coinType] ? parseFloat(supplyRewards[pool.coinType].rewardApr * 100) : null,
rewardTokens: supplyRewards[pool.coinType] ? [supplyRewards[pool.coinType].rewardCoinType] : [],
rewardTokens: rewardTokenPool[pool.coinType] ? Array.from(new Set(rewardTokenPool[pool.coinType])) : null,
totalSupplyUsd: supplyUsd,
totalBorrowUsd: borrowUsd,
apyBaseBorrow: parseFloat(pool.borrowApy * 100),
apyRewardBorrow: borrowRewards[pool.coinType] ? parseFloat(borrowRewards[pool.coinType].reduce((prev, curr) => prev + curr.rewardApr, 0) * 100) : null,
ltv: Number(parseFloat(collateralFactor ? collateralFactor.collateralFactor : 0).toFixed(2)),
});
});

Expand Down

0 comments on commit b441084

Please sign in to comment.