Skip to content

Commit

Permalink
Merge pull request #689 from UnUniFi/osmo-apr
Browse files Browse the repository at this point in the history
feat: osmosis API for Pool APR
  • Loading branch information
Senna46 authored Nov 23, 2023
2 parents b3b93ec + 695f048 commit 93386e6
Show file tree
Hide file tree
Showing 15 changed files with 814 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,14 @@ const strategiesInfo = [
},
},
{
id: '0',
id: '1',
denom: 'ibc/20D06D04E1BC1FAC482FECC06C2E2879A596904D64D8BA3285B4A3789DEAF910',
name: 'Osmosis stATOM/ATOM Strategy (ATOM deposit)',
description: '',
gitUrl: '',
poolInfo: {
type: 'osmosis',
poolId: '803',
apr: 0.157,
},
},
{
Expand All @@ -267,7 +266,6 @@ const strategiesInfo = [
poolInfo: {
type: 'osmosis',
poolId: '1',
apr: 0.215,
},
},
{
Expand All @@ -279,7 +277,6 @@ const strategiesInfo = [
poolInfo: {
type: 'osmosis',
poolId: '3',
apr: 0.237,
},
},
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getSymbolExponent } from '../cosmos/bank.model';
import { CacheService } from '../query.cache.service';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

Expand All @@ -13,9 +14,13 @@ export type TokenAmountUSD = {
providedIn: 'root',
})
export class BandProtocolService {
constructor(private http: HttpClient) {}
constructor(private http: HttpClient, private cacheService: CacheService) {}

async getPrice(symbol: string): Promise<number | undefined> {
const cacheKey = 'oracle_price_' + symbol;
if (this.cacheService.has(cacheKey)) {
return this.cacheService.get(cacheKey);
}
const url = `${rest}/oracle/v1/request_prices?symbols=${symbol}`;
try {
const result = await this.http
Expand All @@ -26,6 +31,7 @@ export class BandProtocolService {
const px = Number(res.price_results[0].px);
return px / multiplier;
});
this.cacheService.set(cacheKey, result);
return result;
} catch {
console.log(`Failed to get price for ${symbol}`);
Expand Down
20 changes: 20 additions & 0 deletions projects/portal/src/app/models/query.cache.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root',
})
export class CacheService {
private cache: { [key: string]: any } = {};

set(key: string, value: any): void {
this.cache[key] = value;
}

get(key: string): any {
return this.cache[key];
}

has(key: string): boolean {
return this.cache.hasOwnProperty(key);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
export type OsmosisPoolAPRs = {
totalAPR: number;
superfluidAPR?: number;
internalGaugeAPR?: number;
externalGaugeAPR?: number;
swapFeeAPR?: number;
};

export type OsmosisAPRsPools = OsmosisAPRsPool[];

export type OsmosisAPRsPool = {
pool_id: number;
apr_list: {
start_date: string;
denom: string;
symbol: string;
apr_1d: number;
apr_7d: number;
apr_14d: number;
apr_superfluid: number;
}[];
};

export type OsmosisAvgAPR = {
APR: number;
};

export type OsmosisFees = {
last_update_at: number;
data: OsmosisFee[];
};

export type OsmosisFee = {
pool_id: string;
volume_24h: number;
volume_7d: number;
fees_spent_24h: number;
fees_spent_7d: number;
fees_percentage: string;
};

export type OsmosisPoolAssets = {
symbol: string;
amount: number;
denom: string;
coingecko_id: string;
liquidity: number;
liquidity_24h_change: number;
volume_24h: number;
volume_24h_change: number;
price: number;
price_24h_change: number;
fees: string;
}[];

export type OsmosisIncentivePools = {
incentivized_pools: {
pool_id: string;
lockable_duration: string;
gauge_id: string;
}[];
};

export type OsmosisLockableDurations = {
lockable_durations: string[];
};

type Distribution = {
lock_query_type: string;
denom: string;
duration: string;
timestamp: string;
};

type Coin = {
denom: string;
amount: string;
};

export type OsmosisActiveGauges = {
data: {
id: string;
is_perpetual: boolean;
distribute_to: Distribution;
coins: Coin[];
start_time: string;
num_epochs_paid_over: string;
filled_epochs: string;
distributed_coins: Coin[];
}[];
};

type Record = {
gauge_id: string;
weight: string;
};

type DistributionInfo = {
total_weight: string;
records: Record[];
};

export type OsmosisDistrInfo = {
distr_info: DistributionInfo;
};

type WeightedDeveloperRewardReceiver = {
address: string;
weight: string;
};

type DistributionProportions = {
staking: string;
pool_incentives: string;
developer_rewards: string;
community_pool: string;
};

export type OsmosisMintParams = {
params: {
mint_denom: string;
genesis_epoch_provisions: string;
epoch_identifier: string;
reduction_period_in_epochs: string;
reduction_factor: string;
distribution_proportions: DistributionProportions;
weighted_developer_rewards_receivers: WeightedDeveloperRewardReceiver[];
};
};
export type OsmosisToken = {
price: number;
denom: string;
symbol: string;
liquidity: number;
volume_24h: number;
volume_24h_change: number;
name: string;
price_24h_change: number;
price_7d_change: number;
exponent: number;
display: string;
};

export type TokenStream = {
name: string;
symbol: string;
denom: string;
price: number;
price_24h_change: number;
exponent: number;
display: string;
};

export type OsmosisGaugeIncentive = {
gauge: {
id: string;
is_perpetual: boolean;
distribute_to: {
lock_query_type: string;
denom: string;
duration: string;
timestamp: string;
};
coins: {
denom: string;
amount: string;
}[];
start_time: string;
num_epochs_paid_over: string;
filled_epochs: string;
distributed_coins: {
denom: string;
amount: string;
}[];
};
};

export type OsmosisSymbolPrice = {
price: number;
'24h_change': number;
};
Loading

0 comments on commit 93386e6

Please sign in to comment.