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

Add Folks Finance yield #746

Merged
merged 18 commits into from
May 8, 2023
Merged
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"graphql": "^15.5.1",
"graphql-request": "^3.5.0",
"lambert-w-function": "^3.0.0",
"limiter": "^2.1.0",
"lodash": "^4.17.21",
"node-fetch": "^2.6.1",
"pg-promise": "^10.11.1",
Expand Down
29 changes: 29 additions & 0 deletions src/adaptors/folks-finance-lending/helper/chain/algorand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// documentation: https://developer.algorand.org/docs/get-details/indexer/?from_query=curl#sdk-client-instantiations

const axios = require('axios');
const { RateLimiter } = require('limiter');

const axiosObj = axios.create({
baseURL: 'https://mainnet-idx.algonode.cloud',
timeout: 300000,
});

const indexerLimiter = new RateLimiter({
tokensPerInterval: 10,
interval: 'second',
});

async function lookupApplications(appId) {
return (await axiosObj.get(`/v2/applications/${appId}`)).data;
}

const withLimiter =
(fn, tokensToRemove = 1) =>
async (...args) => {
await indexerLimiter.removeTokens(tokensToRemove);
return fn(...args);
};

module.exports = {
lookupApplications: withLimiter(lookupApplications),
};
68 changes: 68 additions & 0 deletions src/adaptors/folks-finance-lending/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const constants = require('./v2/constants');
const {
getStakingProgram,
getPoolsInfo,
getDepositStakingProgramsInfo,
retrieveLoanInfo,
} = require('./v2/index');
const { interestRateToPercentage, ratioToPercentage } = require('./v2/utils');
const utils = require('../utils');

const { pools } = constants;

const poolsFunction = async () => {
let poolArr = [];

const depositsStakingInfo = await getStakingProgram();
const { pools: poolsLoanInfo } = await retrieveLoanInfo();
pools.forEach(async (pool) => {
const poolInfo = await getPoolsInfo(pool);
const {
depositsUsd,
borrowsUsd,
depositInterestYield,
variableBorrowInterestYield,
} = poolInfo;
const totalSupplyUsd = Number(depositsUsd.toFixed(2));
const totalBorrowUsd = Number(borrowsUsd.toFixed(2));
const tvlUsd = Number((depositsUsd - borrowsUsd).toFixed(2));
const apyBase = interestRateToPercentage(depositInterestYield);
const apyBaseBorrow = interestRateToPercentage(variableBorrowInterestYield);
const ltv = ratioToPercentage(poolsLoanInfo[pool.appId].collateralFactor);

let dataSource = {
pool: `${pool.appId}-algorand`,
chain: utils.formatChain('algorand'),
project: 'folks-finance-lending',
symbol: utils.formatSymbol(pool.symbol),
tvlUsd,
totalSupplyUsd,
totalBorrowUsd,
apyBase,
apyBaseBorrow,
ltv,
};

if (pool.hasReward) {
const depositStakingInfo = depositsStakingInfo.find(
(deposit) => deposit.poolAppId === pool.appId
);

const dataSourceRewards = await getDepositStakingProgramsInfo(
depositStakingInfo,
poolInfo,
pool
);
dataSource = { ...dataSource, ...dataSourceRewards };
}

poolArr.push(dataSource);
});
return poolArr;
};

module.exports = {
timetravel: false,
apy: poolsFunction,
url: 'https://app.folks.finance/',
};
91 changes: 91 additions & 0 deletions src/adaptors/folks-finance-lending/v2/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
const pools = [
// ALGO
{
appId: 971368268,
assetId: 0,
fAssetId: 971381860,
symbol: 'ALGO',
hasReward: false,
},
// gALGO
{
appId: 971370097,
assetId: 793124631,
fAssetId: 971383839,
symbol: 'gALGO',
hasReward: false,
},
// USDC
{
appId: 971372237,
assetId: 31566704,
fAssetId: 971384592,
symbol: 'USDC',
hasReward: true,
},
// USDt
{
appId: 971372700,
assetId: 312769,
fAssetId: 971385312,
symbol: 'USDt',
hasReward: true,
},
// goBTC
{
appId: 971373361,
assetId: 386192725,
fAssetId: 971386173,
symbol: 'goBTC',
hasReward: false,
},
// goETH
{
appId: 971373611,
assetId: 386195940,
fAssetId: 971387073,
symbol: 'goETH',
hasReward: false,
},
// Opul
{
appId: 1044267181,
assetId: 287867876,
fAssetId: 1044269355,
symbol: 'OPUL',
hasReward: false,
},
// Gard
{
appId: 1060585819,
assetId: 684649988,
fAssetId: 1060587336,
symbol: 'GARD',
hasReward: false,
},
//WBTC
{
appId: 1067289273,
assetId: 1058926737,
fAssetId: 1067295154,
symbol: 'WBTC',
hasReward: false,
},
// WETH
{
appId: 1067289481,
assetId: 887406851,
fAssetId: 1067295558,
symbol: 'WETH',
hasReward: false,
},
];

const oracleAppId = 1040271396;
const oracleDecimals = 14;

module.exports = {
pools,
oracleAppId,
oracleDecimals,
};
Loading