From 49cd3dba9754076dbb50f2f31e84f9939144f4b7 Mon Sep 17 00:00:00 2001 From: Senna46 <29295263+Senna46@users.noreply.github.com> Date: Fri, 13 Oct 2023 22:05:39 +0900 Subject: [PATCH 1/7] feat: apy load faster --- .../yield-aggregator.service.ts | 43 +++++++++++++++++-- .../vaults/vault/vault.component.ts | 7 +-- .../vaults/vaults.component.ts | 9 ++-- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/projects/portal/src/app/models/yield-aggregators/yield-aggregator.service.ts b/projects/portal/src/app/models/yield-aggregators/yield-aggregator.service.ts index 4798cfa80..61a5a932b 100644 --- a/projects/portal/src/app/models/yield-aggregators/yield-aggregator.service.ts +++ b/projects/portal/src/app/models/yield-aggregators/yield-aggregator.service.ts @@ -180,6 +180,28 @@ export class YieldAggregatorService { }); } + async getAllOsmoPool(): Promise { + const url = 'https://api-osmosis.imperator.co/apr/v2/all'; + return this.http + .get(url) + .toPromise() + .then((res: any) => { + const pools = res as OsmosisPools; + return pools; + }); + } + + async getOsmoPool(poolId: string): Promise { + const url = 'https://api-osmosis.imperator.co/apr/v2/' + poolId; + return this.http + .get(url) + .toPromise() + .then((res: any) => { + const pool = res as OsmosisPools; + return pool; + }); + } + async getStrategyAPR(strategyInfo?: YieldInfo): Promise { if (!strategyInfo) { return 0; @@ -192,7 +214,7 @@ export class YieldAggregatorService { return strategyInfo.minApy || 0; } - async calcVaultAPY(vault: Vault200Response, config?: Config): Promise { + calcVaultAPY(vault: Vault200Response, config: Config, osmoPools: OsmosisPools): YieldInfo { if (!vault.vault?.strategy_weights) { return { id: vault.vault?.id || '', @@ -208,15 +230,30 @@ export class YieldAggregatorService { } let vaultAPY = 0; let vaultAPYCertainty = false; + for (const strategyWeight of vault.vault.strategy_weights) { const strategyInfo = config?.strategiesInfo?.find( (strategyInfo) => strategyInfo.id === strategyWeight.strategy_id && strategyInfo.denom === vault.vault?.denom, ); - const strategyAPY = await this.getStrategyAPR(strategyInfo); - vaultAPY += Number(strategyAPY) * Number(strategyWeight.weight); + if (!strategyInfo || !strategyInfo.poolInfo) { + continue; + } + const poolInfo = strategyInfo.poolInfo; + if (poolInfo.type === 'osmosis') { + const pool = osmoPools.find((pool) => pool.pool_id.toString() === poolInfo.poolId); + if (!pool) { + continue; + } + let totalApr = 0; + for (const apr of pool.apr_list) { + totalApr += apr.apr_superfluid; + } + vaultAPY += (Number(totalApr) / 100) * Number(strategyWeight.weight); + } } + return { id: vault.vault?.id || '', denom: vault.vault?.denom || '', diff --git a/projects/portal/src/app/pages/yieldaggregator/vaults/vault/vault.component.ts b/projects/portal/src/app/pages/yieldaggregator/vaults/vault/vault.component.ts index b99426e2b..955ea085f 100644 --- a/projects/portal/src/app/pages/yieldaggregator/vaults/vault/vault.component.ts +++ b/projects/portal/src/app/pages/yieldaggregator/vaults/vault/vault.component.ts @@ -19,7 +19,7 @@ import { import { YieldAggregatorQueryService } from 'projects/portal/src/app/models/yield-aggregators/yield-aggregator.query.service'; import { YieldAggregatorService } from 'projects/portal/src/app/models/yield-aggregators/yield-aggregator.service'; import { ExternalChain } from 'projects/portal/src/app/views/yieldaggregator/vaults/vault/vault.component'; -import { BehaviorSubject, combineLatest, Observable, of, timer } from 'rxjs'; +import { BehaviorSubject, combineLatest, from, Observable, of, timer } from 'rxjs'; import { filter, map, mergeMap } from 'rxjs/operators'; import { EstimateMintAmount200Response, @@ -152,8 +152,9 @@ export class VaultComponent implements OnInit { return this.iyaQuery.getEstimatedRedeemAmount$(id, (burn * 10 ** exponent).toString()); }), ); - this.vaultInfo$ = combineLatest([this.vault$, this.configService.config$]).pipe( - mergeMap(async ([vault, config]) => this.iyaService.calcVaultAPY(vault, config)), + const osmoPools$ = from(this.iyaService.getAllOsmoPool()); + this.vaultInfo$ = combineLatest([this.vault$, this.configService.config$, osmoPools$]).pipe( + map(([vault, config, pools]) => this.iyaService.calcVaultAPY(vault, config!, pools)), ); const balances$ = this.address$.pipe(mergeMap((addr) => this.bankQuery.getBalance$(addr))); this.vaultBalance$ = combineLatest([vaultId$, balances$]).pipe( diff --git a/projects/portal/src/app/pages/yieldaggregator/vaults/vaults.component.ts b/projects/portal/src/app/pages/yieldaggregator/vaults/vaults.component.ts index 0cdc6b779..c47b1678b 100644 --- a/projects/portal/src/app/pages/yieldaggregator/vaults/vaults.component.ts +++ b/projects/portal/src/app/pages/yieldaggregator/vaults/vaults.component.ts @@ -10,7 +10,7 @@ import { YieldAggregatorQueryService } from '../../../models/yield-aggregators/y import { YieldAggregatorService } from '../../../models/yield-aggregators/yield-aggregator.service'; import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; -import { BehaviorSubject, combineLatest, Observable } from 'rxjs'; +import { BehaviorSubject, combineLatest, from, Observable } from 'rxjs'; import { filter, map, mergeMap } from 'rxjs/operators'; import { VaultAll200ResponseVaultsInner } from 'ununifi-client/esm/openapi'; @@ -48,9 +48,10 @@ export class VaultsComponent implements OnInit { this.keyword$ = this.route.queryParams.pipe(map((params) => params.keyword)); const denomMetadataMap$ = this.bankQuery.getDenomMetadataMap$(); const symbolMetadataMap$ = this.bankQuery.getSymbolMetadataMap$(); - const vaultYields$ = combineLatest([vaults$, config$]).pipe( - mergeMap(async ([vaults, config]) => - Promise.all(vaults.map(async (vault) => this.iyaService.calcVaultAPY(vault, config))), + const osmoPools$ = from(this.iyaService.getAllOsmoPool()); + const vaultYields$ = combineLatest([vaults$, config$, osmoPools$]).pipe( + map(([vaults, config, pools]) => + vaults.map((vault) => this.iyaService.calcVaultAPY(vault, config!, pools)), ), ); const vaultDeposits$ = combineLatest([vaults$, denomMetadataMap$, symbolMetadataMap$]).pipe( From a4ae8cd00a2971fa0285191299ee210f200a0957 Mon Sep 17 00:00:00 2001 From: Senna46 <29295263+Senna46@users.noreply.github.com> Date: Fri, 13 Oct 2023 23:16:20 +0900 Subject: [PATCH 2/7] feat: delete id --- .../views/yieldaggregator/vaults/vaults.component.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/portal/src/app/views/yieldaggregator/vaults/vaults.component.html b/projects/portal/src/app/views/yieldaggregator/vaults/vaults.component.html index df2dc6a12..4ac2d1212 100644 --- a/projects/portal/src/app/views/yieldaggregator/vaults/vaults.component.html +++ b/projects/portal/src/app/views/yieldaggregator/vaults/vaults.component.html @@ -78,7 +78,7 @@

Available Vaults

- + - + diff --git a/projects/portal/src/app/views/yieldaggregator/yield-aggregator.component.ts b/projects/portal/src/app/views/yieldaggregator/yield-aggregator.component.ts index 704c558d0..0305c704d 100644 --- a/projects/portal/src/app/views/yieldaggregator/yield-aggregator.component.ts +++ b/projects/portal/src/app/views/yieldaggregator/yield-aggregator.component.ts @@ -1,6 +1,9 @@ import { Component, Input, OnInit } from '@angular/core'; import cosmosclient from '@cosmos-client/core'; -import { VaultAll200ResponseVaultsInner } from 'ununifi-client/esm/openapi'; +import { + StrategyAll200ResponseStrategiesInner, + VaultAll200ResponseVaultsInner, +} from 'ununifi-client/esm/openapi'; export interface OptionConfig { name: string; @@ -21,6 +24,8 @@ export class YieldAggregatorComponent implements OnInit { availableSymbols?: string[] | null; @Input() vaults?: VaultAll200ResponseVaultsInner[] | null; + @Input() + strategies?: StrategyAll200ResponseStrategiesInner[] | null; configs: OptionConfig[]; selectedConfig: OptionConfig; From 16bd90673eae6a303b6a46b9cc28328e48ad6956 Mon Sep 17 00:00:00 2001 From: Senna46 <29295263+Senna46@users.noreply.github.com> Date: Sat, 14 Oct 2023 00:10:38 +0900 Subject: [PATCH 7/7] feat: delete icon --- .../yieldaggregator/vaults/create/create.component.html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/projects/portal/src/app/views/yieldaggregator/vaults/create/create.component.html b/projects/portal/src/app/views/yieldaggregator/vaults/create/create.component.html index 9564f7116..061cb1470 100644 --- a/projects/portal/src/app/views/yieldaggregator/vaults/create/create.component.html +++ b/projects/portal/src/app/views/yieldaggregator/vaults/create/create.component.html @@ -71,12 +71,13 @@

What is Vault Name?

What is Fee Collector? What is the strategies? target="_blank" > {{ strategy.name }} - info +