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

Adding v1 of the new ETH filter for pools #196

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
16 changes: 10 additions & 6 deletions docs/add_new_protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ export class MyProtocol extends IDapp<BaseAPYT> {
.filter(this.commonVaultFilter)
.forEach((poolName) => {
const arr = myData[poolName];
let category = Category.Others;
let category: Category[] = [Category.Others];
if (poolName === 'USDC/USDT') {
category = Category.Stable;
category.push(Category.Stable);
} else if (poolName.includes('STRK')) {
category = Category.STRK;
category.push(Category.STRK);
} else if (poolName.includes('ETH')) {
category.push(Category.ETH);
}

const tokens: TokenName[] = poolName.split('/');
Expand Down Expand Up @@ -223,11 +225,13 @@ export class MyProtocol extends IDapp<BaseAPYT> {
.filter(this.commonVaultFilter)
.forEach((poolName) => {
const arr = myData[poolName];
let category = Category.Others;
let category: Category[] = [Category.Others];
if (poolName === 'USDC/USDT') {
category = Category.Stable;
category.push(Category.Stable);
} else if (poolName.includes('STRK')) {
category = Category.STRK;
category.push(Category.STRK);
} else if (poolName.includes('ETH')) {
category.push(Category.ETH);
}

const tokens: TokenName[] = poolName.split('/');
Expand Down
31 changes: 31 additions & 0 deletions src/components/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,37 @@ export function CategoryFilters() {
</TagLabel>
</Tag>

{/* ETH pools */}
<Tag
size="lg"
borderRadius="full"
mr={'10px'}
padding={'6px 10px'}
as={'button'}
onClick={() => {
updateCategory(Category.ETH);
}}
bg={
categoriesFilter.includes(Category.ETH.valueOf())
? 'purple'
: 'color1'
}
marginBottom={'10px'}
>
<AvatarGroup size={'xs'} spacing={'-15px'} mr={'5px'}>
<Avatar
src={getTokenInfoFromName('ETH').logo}
name="ETH"
key={'ETH'}
/>
</AvatarGroup>
<TagLabel
{...getTextProps(categoriesFilter.includes(Category.ETH.valueOf()))}
>
{Category.ETH.valueOf()}
</TagLabel>
</Tag>

{/* Low risk pools */}
<Tag
size="lg"
Expand Down
10 changes: 5 additions & 5 deletions src/store/carmine.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export class Carmine extends Jediswap {
const poolData = myData[config.name];
if (!poolData || !poolData.data) return;

let category: Category;
const category: Category[] = [Category.Others];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont think having others as default for everything makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Others is only for something that doesn't wallet in one of the known categories.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. So I'm going to just defined the variable and thats it. @akiraonstarknet

const riskFactor = 3;
if (config.name.endsWith('(USDC)')) {
category = Category.Stable;
category.push(Category.Stable);
} else if (config.name.endsWith('(STRK)')) {
category = Category.STRK;
} else {
category = Category.Others;
category.push(Category.STRK);
} else if (config.name.endsWith('(ETH)')) {
category.push(Category.ETH);
}

const logo1 =
Expand Down
8 changes: 5 additions & 3 deletions src/store/ekobu.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ export class Ekubo extends IDapp<EkuboBaseAprDoc> {
.filter(this.commonVaultFilter)
.forEach((poolName) => {
const arr = myData[poolName];
let category = Category.Others;
const category: Category[] = [Category.Others];
let riskFactor = 3;
if (poolName === 'USDC/USDT') {
category = Category.Stable;
category.push(Category.Stable);
riskFactor = 0.5;
} else if (poolName.includes('STRK')) {
category = Category.STRK;
category.push(Category.STRK);
} else if (poolName.includes('ETH')) {
category.push(Category.ETH);
}

const tokens: TokenName[] = <TokenName[]>poolName.split('/');
Expand Down
2 changes: 1 addition & 1 deletion src/store/endur.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const EndurAtoms = {
description: 'Includes fees & Defi spring rewards',
},
],
category: Category.STRK,
category: [Category.STRK],
type: PoolType.Staking,
additional: {
riskFactor: 0.5,
Expand Down
8 changes: 5 additions & 3 deletions src/store/haiko.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ export class Haiko extends IDapp<Pool[]> {
.filter(this.commonVaultFilter)
.forEach((poolName) => {
const arr = myData[poolName];
let category = Category.Others;
const category: Category[] = [Category.Others];
let riskFactor = 3;
if (poolName === 'USDC/USDT') {
category = Category.Stable;
category.push(Category.Stable);
riskFactor = 0.5;
} else if (poolName.includes('STRK')) {
category = Category.STRK;
category.push(Category.STRK);
} else if (poolName.includes('ETH')) {
category.push(Category.ETH);
}

const tokens: TokenName[] = <TokenName[]>poolName.split('/');
Expand Down
8 changes: 5 additions & 3 deletions src/store/hashstack.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ export class Hashstack extends IDapp<LendingSpace.MyBaseAprDoc[]> {
const arr = myData[poolName];
if (arr.length === 0) return;

let category = Category.Others;
const category: Category[] = [Category.Others];
if (['USDC', 'USDT'].includes(poolName)) {
category = Category.Stable;
category.push(Category.Stable);
} else if (poolName.includes('STRK')) {
category = Category.STRK;
category.push(Category.STRK);
} else if (poolName.includes('ETH')) {
category.push(Category.ETH);
}

const logo1 = CONSTANTS.LOGOS[<TokenName>poolName];
Expand Down
8 changes: 5 additions & 3 deletions src/store/jedi.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ export class Jediswap extends IDapp<string> {
.filter(this.commonVaultFilter)
.forEach((poolName) => {
const arr = myData[poolName];
let category = Category.Others;
const category: Category[] = [Category.Others];

let riskFactor = 3;
if (poolName === 'USDC/USDT') {
category = Category.Stable;
category.push(Category.Stable);
riskFactor = 0.5;
} else if (poolName.includes('STRK')) {
category = Category.STRK;
category.push(Category.STRK);
} else if (poolName.includes('ETH')) {
category.push(Category.ETH);
}

const tokens: TokenName[] = <TokenName[]>poolName.split('/');
Expand Down
8 changes: 5 additions & 3 deletions src/store/lending.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ export namespace LendingSpace {
const arr = myData[poolName];
if (arr.length === 0) return;

let category = Category.Others;
const category: Category[] = [Category.Others];
if (['USDC', 'USDT'].includes(poolName)) {
category = Category.Stable;
category.push(Category.Stable);
} else if (poolName.includes('STRK')) {
category = Category.STRK;
category.push(Category.STRK);
} else if (poolName.includes('ETH')) {
category.push(Category.ETH);
}

const logo1 = CONSTANTS.LOGOS[<TokenName>poolName];
Expand Down
8 changes: 5 additions & 3 deletions src/store/myswap.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ export class MySwap extends IDapp<IndexedPoolData> {
.filter(this.commonVaultFilter)
.forEach((poolName) => {
const arr = myData[poolName];
let category = Category.Others;
const category: Category[] = [Category.Others];
let riskFactor = 3;
if (poolName === 'USDC/USDT') {
category = Category.Stable;
category.push(Category.Stable);
riskFactor = 0.5;
} else if (poolName.includes('STRK')) {
category = Category.STRK;
category.push(Category.STRK);
} else if (poolName.includes('ETH')) {
category.push(Category.ETH);
}

const tokens: TokenName[] = <TokenName[]>poolName.split('/');
Expand Down
4 changes: 2 additions & 2 deletions src/store/nimboradex.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ export class NimboraDex extends IDapp<NimboraDexDoc> {
.filter(this.commonVaultFilter)
.forEach((poolName) => {
const poolData: NimboraDexDoc = data[poolName];
let category = Category.Others;
const category: Category[] = [Category.Others];
const riskFactor = 0.75;

if (poolName == 'USDC') {
category = Category.Stable;
category.push(Category.Stable);
}

const logo =
Expand Down
7 changes: 6 additions & 1 deletion src/store/nostradegen.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ export class NostraDegen extends Jediswap {
poolData.baseApr === '0' ? 0.0 : parseFloat(poolData.baseApr);
const rewardApr = parseFloat(poolData.rewardApr);
const isStrkPool = poolData.id.includes('STRK');
const category = isStrkPool ? Category.STRK : Category.Others;
const category: Category[] = [Category.Others];
if (isStrkPool) {
category.push(Category.STRK);
} else if (poolData.id.includes('ETH')) {
category.push(Category.ETH);
}

const _poolName = poolData.id;
const poolInfo: PoolInfo = {
Expand Down
8 changes: 5 additions & 3 deletions src/store/nostradex.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ export class NostraDex extends Jediswap {
poolData.baseApr === '0' ? 0.0 : parseFloat(poolData.baseApr);
const rewardApr = parseFloat(poolData.rewardApr);

let category = Category.Others;
const category: Category[] = [Category.Others];
let riskFactor = 3;
if (poolData.id === 'USDC-USDT') {
category = Category.Stable;
category.push(Category.Stable);
riskFactor = 0.5;
} else if (poolData.id.includes('STRK')) {
category = Category.STRK;
category.push(Category.STRK);
} else if (poolData.id.includes('ETH')) {
category.push(Category.ETH);
}
const poolInfo: PoolInfo = {
pool: {
Expand Down
5 changes: 3 additions & 2 deletions src/store/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import fetchWithRetry from '@/utils/fetchWithRetry';
export enum Category {
Stable = 'Stable Pools',
STRK = 'STRK Pools',
ETH = 'ETH Pools',
Others = 'Others',
}

Expand Down Expand Up @@ -50,7 +51,7 @@ export interface PoolInfo extends PoolMetadata {
tvl: number;
apr: number; // not in %
aprSplits: APRSplit[];
category: Category;
category: Category[];
type: PoolType;
isLoading?: boolean;
additional: {
Expand All @@ -77,7 +78,7 @@ export function getDefaultPoolInfo(): PoolInfo {
apr: 0,
tvl: 0,
aprSplits: [],
category: Category.Others,
category: [Category.Others],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to validate this. @EjembiEmmanuel

type: PoolType.Derivatives,
additional: {
riskFactor: 0,
Expand Down
12 changes: 8 additions & 4 deletions src/store/protocols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,13 @@ export const allPoolsAtomUnSorted = atom((get) => {
export function getPoolInfoFromStrategy(
strat: STRKFarmStrategyAPIResult,
): PoolInfo {
let category = Category.Others;
const category = [Category.Others];
if (strat.name.includes('STRK')) {
category = Category.STRK;
category.push(Category.STRK);
} else if (strat.name.includes('USDC')) {
category = Category.Stable;
category.push(Category.Stable);
} else if (strat.name.includes('ETH')) {
category.push(Category.ETH);
}
return {
pool: {
Expand Down Expand Up @@ -306,7 +308,9 @@ export const filteredPools = atom((get) => {
// category filter
if (
!categories.includes(ALL_FILTER) &&
!categories.includes(pool.category.valueOf())
!categories.some((category) =>
pool.category.some((poolCategory) => poolCategory === category),
)
)
return false;

Expand Down
10 changes: 6 additions & 4 deletions src/store/strkfarm.atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ export class STRKFarm extends IDapp<STRKFarmStrategyAPIResult> {
const rawPools: STRKFarmStrategyAPIResult[] = data.strategies;
const pools: PoolInfo[] = [];
return rawPools.map((rawPool) => {
let category = Category.Others;
const categories = [Category.Others];
const poolName = rawPool.name;
const riskFactor = rawPool.riskFactor;
if (poolName.includes('USDC') || poolName.includes('USDT')) {
category = Category.Stable;
categories.push(Category.Stable);
} else if (poolName.includes('STRK')) {
category = Category.STRK;
categories.push(Category.STRK);
} else if (poolName.includes('ETH')) {
categories.push(Category.ETH);
}
const poolInfo: PoolInfo = {
pool: {
Expand All @@ -75,7 +77,7 @@ export class STRKFarm extends IDapp<STRKFarmStrategyAPIResult> {
apr: 0,
tvl: rawPool.tvlUsd,
aprSplits: [],
category,
category: categories,
type: PoolType.Derivatives,
lending: {
collateralFactor: 0,
Expand Down
4 changes: 3 additions & 1 deletion src/strategies/IStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ export class IStrategy extends IStrategyProps {
amount: string,
prevActions: StrategyAction[],
) {
const eligiblePools = pools.filter((p) => p.category == Category.Stable);
const eligiblePools = pools.filter((p) =>
p.category.includes(Category.Stable),
);
if (!eligiblePools) throw new Error(`${this.tag}: [F1] no eligible pools`);
return eligiblePools;
}
Expand Down
Loading