Skip to content

Commit

Permalink
Merge pull request #88 from Dprof-in-tech/dev
Browse files Browse the repository at this point in the history
Added the Carmine Pools
  • Loading branch information
akiraonstarknet authored Aug 6, 2024
2 parents ce5b9ba + 74dfd3f commit 0edd546
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 0 deletions.
4 changes: 4 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const nextConfig = {
source: '/nostra/:path*',
destination: 'https://us-east-2.aws.data.mongodb-api.com/:path*',
},
{
source: '/carmine/:path*',
destination: 'https://api.carmine.finance/:path*',
},
{
source: '/myswap/:path*',
destination: 'https://myswap-cl-charts.s3.amazonaws.com/:path*',
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export type TokenName = 'USDT' | 'USDC' | 'ETH' | 'STRK' | 'WBTC' | 'DAI';
const CONSTANTS = {
DEX_INCENTIVE_URL: '/strk-incentives/fetchFile?file=strk_grant.json',
NOSTRA_DEGEN_INCENTIVE_URL: 'https://api.nostra.finance/query/pool_aprs',
CARMINE_INCENTIVES_URL: '/carmine/api/v1/mainnet/defispring',
CARMINE_URL: '/carmine/api/v2/mainnet',
LENDING_INCENTIVES_URL:
'/strk-incentives/fetchFile?file=prod-api/lending/lending_strk_grant.json',
LOGOS,
Expand Down
178 changes: 178 additions & 0 deletions src/store/carmine.store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import CONSTANTS from '@/constants';
import { Category, PoolType } from './pools';
import { atom } from 'jotai';
import { PoolInfo, ProtocolAtoms } from './pools';
import { Jediswap } from './jedi.store';
import { atomWithQuery } from 'jotai-tanstack-query';

const poolConfigs = [
{ name: 'STRK/USDC Call Pool (STRK)', tokenA: 'STRK', tokenB: 'USDC' },
{ name: 'STRK/USDC Put Pool (USDC)', tokenA: 'STRK', tokenB: 'USDC' },
{ name: 'ETH/STRK Call Pool (ETH)', tokenA: 'ETH', tokenB: 'STRK' },
{ name: 'ETH/STRK Put Pool (STRK)', tokenA: 'ETH', tokenB: 'STRK' },
{ name: 'ETH/USDC Call Pool (ETH)', tokenA: 'ETH', tokenB: 'USDC' },
{ name: 'ETH/USDC Put Pool (USDC)', tokenA: 'ETH', tokenB: 'USDC' },
{ name: 'wBTC/USDC Put Pool (USDC)', tokenA: 'WBTC', tokenB: 'USDC' },
{ name: 'wBTC/USDC Call Pool (wBTC)', tokenA: 'WBTC', tokenB: 'USDC' },
];

export class Carmine extends Jediswap {
name = 'Carmine Options';
link = 'https://app.carmine.finance/staking';
logo =
'https://static-assets-8zct.onrender.com/integrations/carmine/carmine.jpg';
incentiveDataKey = 'isCarmine';

_computePoolsInfo(data: any) {
try {
const myData = data;
if (!myData) return [];
const pools: PoolInfo[] = [];

poolConfigs.forEach((config) => {
const poolData = myData[config.name];
if (!poolData || !poolData.data) return;

let category: Category;
if (config.name.endsWith('(USDC)')) {
category = Category.Stable;
} else if (config.name.endsWith('(STRK)')) {
category = Category.STRK;
} else {
category = Category.Others;
}

const logo1 =
CONSTANTS.LOGOS[config.tokenA as keyof typeof CONSTANTS.LOGOS];
const logo2 =
CONSTANTS.LOGOS[config.tokenB as keyof typeof CONSTANTS.LOGOS];

const baseApr =
poolData.data.week_annualized / 100 === 0
? 0.0
: parseFloat(poolData.data.week_annualized) / 100;
const rewardApr = parseFloat(poolData.rewardApr) || 0;

const poolInfo: PoolInfo = {
pool: {
name: config.name,
logos: [logo1, logo2],
},
protocol: {
name: this.name,
link: this.link,
logo: this.logo,
},
apr: baseApr + rewardApr,
tvl: poolData.tvl,
aprSplits: [
{
apr: baseApr || baseApr.toString() === '' ? baseApr : 0,
title: 'Supply Apy',
description: '',
},
{
apr: rewardApr ?? 0,
title: 'STRK DeFi Spring rewards',
description: '',
},
],
category,
type: PoolType.Derivatives,
lending: {
collateralFactor: 0,
},
borrow: {
borrowFactor: 0,
apr: 0,
},
};
pools.push(poolInfo);
});

return pools;
} catch (err) {
console.error('Err fetching pools [2]', err);
throw err;
}
}
}

export const carmine = new Carmine();

const poolEndpoints = [
{ name: 'STRK/USDC Call Pool (STRK)', endpoint: 'strk-usdc-call' },
{ name: 'STRK/USDC Put Pool (USDC)', endpoint: 'strk-usdc-put' },
{ name: 'ETH/STRK Call Pool (ETH)', endpoint: 'eth-strk-call' },
{ name: 'ETH/STRK Put Pool (STRK)', endpoint: 'eth-strk-put' },
{ name: 'ETH/USDC Call Pool (ETH)', endpoint: 'eth-usdc-call' },
{ name: 'ETH/USDC Put Pool (USDC)', endpoint: 'eth-usdc-put' },
{ name: 'wBTC/USDC Put Pool (USDC)', endpoint: 'btc-usdc-put' },
{ name: 'wBTC/USDC Call Pool (wBTC)', endpoint: 'btc-usdc-call' },
];

export const CarmineAtom = atomWithQuery((get) => ({
queryKey: ['isCarmine'],
queryFn: async ({ queryKey }) => {
const fetchPool = async (endpoint: any) => {
const res = await fetch(`${CONSTANTS.CARMINE_URL}/${endpoint}/apy`);
let data = await res.text();
data = data.replaceAll('NaN', '0');
return JSON.parse(data);
};

const fetchRewardApr = async () => {
const res = await fetch(CONSTANTS.CARMINE_INCENTIVES_URL);
let data = await res.text();
data = data.replaceAll('NaN', '0');
return JSON.parse(data);
};

const rewardAprData = await fetchRewardApr();
const rewardApr = rewardAprData.data.apy;
const tvl = rewardAprData.data.tvl;

const poolData = await Promise.all(
poolEndpoints.map(async (pool) => {
const data = await fetchPool(pool.endpoint);
return { name: pool.name, data };
}),
);

const combinedData = poolData.reduce(
(acc, pool) => {
acc[pool.name] = {
...pool.data,
rewardApr,
tvl,
};
return acc;
},
{} as { [key: string]: any },
);

const specificPools = [
'wBTC/USDC Call Pool (wBTC)',
'wBTC/USDC Put Pool (USDC)',
];
specificPools.forEach((poolName) => {
if (combinedData[poolName]) {
combinedData[poolName].rewardApr = 0.0;
}
});

return combinedData;
},
}));


const CarmineAtoms: ProtocolAtoms = {
pools: atom((get) => {
const poolsInfo = get(CarmineAtom);
const empty: PoolInfo[] = [];
if (poolsInfo.data) return carmine._computePoolsInfo(poolsInfo.data);
return empty;
}),
};

export default CarmineAtoms;
7 changes: 7 additions & 0 deletions src/store/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import SithswapAtoms, { sithswap } from './sithswap.store';
import StarkDefiAtoms, { starkDefi } from './starkdefi.store';
import TenkSwapAtoms, { tenkswap } from './tenkswap.store';
import ZkLendAtoms, { zkLend } from './zklend.store';
import CarmineAtoms, { carmine } from './carmine.store';

export enum Category {
Stable = 'Stable Pools',
Expand All @@ -26,6 +27,7 @@ export enum PoolType {
DEXV2 = 'V2 LP DEX',
DEXV3 = 'Concentrated LP DEX',
Lending = 'Lending',
Derivatives = 'Derivatives',
}

export interface APRSplit {
Expand Down Expand Up @@ -103,6 +105,11 @@ export const PROTOCOLS = [
class: nostraDegen,
atoms: NostraDegenAtoms,
},
{
name: carmine.name,
class: carmine,
atoms: CarmineAtoms,
},
{
name: starkDefi.name,
class: starkDefi,
Expand Down

0 comments on commit 0edd546

Please sign in to comment.