diff --git a/src/adaptors/size-credit/api.ts b/src/adaptors/size-credit/api.js similarity index 59% rename from src/adaptors/size-credit/api.ts rename to src/adaptors/size-credit/api.js index 2ba71dc09a..4d7c187903 100755 --- a/src/adaptors/size-credit/api.ts +++ b/src/adaptors/size-credit/api.js @@ -1,6 +1,6 @@ -import type Fetch from 'node-fetch'; -const fetch = require('node-fetch') as typeof Fetch; +const fetch = require('node-fetch'); +/* export interface Market { id: string; name: string; @@ -47,7 +47,7 @@ export interface Market { } interface GetMarketsResponse { - available_markets: Market[]; + markets_by_chain: Record } interface GetTvlResponse { @@ -83,27 +83,39 @@ interface GetBestRateResponse { depth_used_collateral_token: number; }[][] } +*/ const ENDPOINT = 'https://api.size.credit'; -export async function getMarkets(): Promise { - const getMarketsResponse: GetMarketsResponse = await fetch(`${ENDPOINT}/`).then((res) => res.json()); - return getMarketsResponse.available_markets; +async function getMarkets() /*: Promise*/ { + const getMarketsResponse /*: GetMarketsResponse*/ = await fetch( + `${ENDPOINT}/` + ).then((res) => res.json()); + return Object.values(getMarketsResponse.markets_by_chain).flat(); } -export async function getTvl(market: Market): Promise { - const getTvlResponse: GetTvlResponse = await fetch(`${ENDPOINT}${market.api_base_url}/market-tvl`).then((res) => res.json()); +async function getTvl(market /*: Market*/) /*: Promise*/ { + const getTvlResponse /*: GetTvlResponse*/ = await fetch( + `${ENDPOINT}${market.api_base_url}/market-tvl` + ).then((res) => res.json()); return getTvlResponse; } -export async function lendingAPR(market: Market, tenor: number, depth: number): Promise { - const getBestRateResponse: GetBestRateResponse = await fetch(`${ENDPOINT}${market.api_base_url}/best-rate-for-tenors-scl/`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ tenors: [tenor], depth }), - }).then((res) => res.json()); +async function lendingAPR( + market /*: Market*/, + tenor /*: number*/, + depth /*: number*/ +) /*: Promise*/ { + const getBestRateResponse /*: GetBestRateResponse*/ = await fetch( + `${ENDPOINT}${market.api_base_url}/best-rate-for-tenors-scl/`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ tenors: [tenor], depth }), + } + ).then((res) => res.json()); const apr18decimals = getBestRateResponse.aprs[0]; if (typeof apr18decimals === 'string') { return undefined; @@ -111,14 +123,21 @@ export async function lendingAPR(market: Market, tenor: number, depth: number): return apr18decimals / 1e16; } -export async function borrowingAPR(market: Market, tenor: number, depth: number): Promise { - const getBestRateResponse: GetBestRateResponse = await fetch(`${ENDPOINT}${market.api_base_url}/best-rate-for-tenors-bcl/`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ tenors: [tenor], depth }), - }).then((res) => res.json()); +async function borrowingAPR( + market /*: Market*/, + tenor /*: number*/, + depth /*: number*/ +) /*: Promise*/ { + const getBestRateResponse /*: GetBestRateResponse*/ = await fetch( + `${ENDPOINT}${market.api_base_url}/best-rate-for-tenors-bcl/`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ tenors: [tenor], depth }), + } + ).then((res) => res.json()); const apr18decimals = getBestRateResponse.aprs[0]; if (typeof apr18decimals === 'string') { return undefined; @@ -126,7 +145,9 @@ export async function borrowingAPR(market: Market, tenor: number, depth: number) return apr18decimals / 1e16; } -export type GetMarkets = typeof getMarkets; -export type GetTvl = typeof getTvl; -export type LendingAPR = typeof lendingAPR; -export type BorrowingAPR = typeof borrowingAPR; +module.exports = { + getMarkets, + getTvl, + lendingAPR, + borrowingAPR, +}; diff --git a/src/adaptors/size-credit/index.ts b/src/adaptors/size-credit/index.js similarity index 76% rename from src/adaptors/size-credit/index.ts rename to src/adaptors/size-credit/index.js index 6b191835ff..1ff81f3cac 100755 --- a/src/adaptors/size-credit/index.ts +++ b/src/adaptors/size-credit/index.js @@ -1,11 +1,4 @@ -import type { Pool } from "../../types/Pool"; -import type { BorrowingAPR, GetMarkets, LendingAPR, GetTvl } from "./api"; -const { borrowingAPR, getMarkets, lendingAPR, getTvl } = require('./api') as { - borrowingAPR: BorrowingAPR; - getMarkets: GetMarkets; - lendingAPR: LendingAPR; - getTvl: GetTvl; -}; +const { borrowingAPR, getMarkets, lendingAPR, getTvl } = require('./api'); const sdk = require('@defillama/sdk'); const AaveV3Pool = require('../aave-v3/poolAbi'); @@ -26,29 +19,30 @@ const AaveProtocolDataProvider = { etherfi: '0xE7d490885A68f00d9886508DF281D67263ed5758', // on ethereum }; -const TENOR_SECONDS = 60 * 60 * 24 * 3 +const TENOR_SECONDS = 60 * 60 * 24 * 3; const DEPTH_BORROW_TOKEN = 10; -function uppercaseFirst(str: string): string { +function uppercaseFirst(str /*: string*/) /*: string*/ { return str.charAt(0).toUpperCase() + str.slice(1); } -export async function apy(): Promise { +async function apy() /*: Promise*/ { const markets = await getMarkets(); return Promise.all( markets.map(async (market) => { const tvl = await getTvl(market); - let apyBase = await lendingAPR(market, TENOR_SECONDS, DEPTH_BORROW_TOKEN) - if (apyBase === undefined) { // no limit borrow offers available, use Aave v3 as a variable-rate lending pool + let apyBase = await lendingAPR(market, TENOR_SECONDS, DEPTH_BORROW_TOKEN); + if (apyBase === undefined) { + // no limit borrow offers available, use Aave v3 as a variable-rate lending pool const { output: getReserveData } = await sdk.api.abi.call({ target: AaveProtocolDataProvider[market.chain], abi: AaveV3Pool.find((m) => m.name === 'getReserveData'), params: [market.debt_token.address], chain: market.chain, - }) - apyBase = getReserveData.liquidityRate / 10 ** 25 + }); + apyBase = getReserveData.liquidityRate / 10 ** 25; } return { pool: market.id, @@ -61,17 +55,20 @@ export async function apy(): Promise { underlyingTokens: [market.debt_token.address], rewardTokens: [], url: `https://app.size.credit/borrow?action=market&type=lend&market_id=${market.id}`, - apyBaseBorrow: await borrowingAPR(market, TENOR_SECONDS, DEPTH_BORROW_TOKEN), + apyBaseBorrow: await borrowingAPR( + market, + TENOR_SECONDS, + DEPTH_BORROW_TOKEN + ), apyRewardBorrow: 0, totalSupplyUsd: tvl.debt_tvl_usd, totalBorrowUsd: tvl.borrow_tvl_usd, ltv: 1e20 / market.risk_config.cr_liquidation, }; - }), + }) ); -}; +} module.exports = { - timetravel: false, apy, };