From 79019de32c70ee00682489eaa055431fa47ebf49 Mon Sep 17 00:00:00 2001 From: srph Date: Fri, 7 Oct 2022 04:18:59 +0800 Subject: [PATCH 01/11] Update --- .../pool-incentives/incentivized-pools.ts | 40 +++++++++++++------ packages/web/config/feature-flag.ts | 8 ++++ packages/web/pages/pool/[id].tsx | 9 +++++ 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts index b3bdf6ff9b..c5f06141f0 100644 --- a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts +++ b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts @@ -212,8 +212,15 @@ export class ObservableQueryIncentivizedPools extends ObservableChainQuery { + console.log(label, value); + return value; + }; // 에포치마다 발행되는 민팅 코인의 수. - const epochProvision = this.queryEpochProvision.epochProvisions; + const epochProvision = log( + "epochProvisions", + this.queryEpochProvision.epochProvisions + ); if (epochProvision) { const numEpochPerYear = @@ -223,23 +230,32 @@ export class ObservableQueryIncentivizedPools extends ObservableChainQuery { days={duration.humanize()} apr={queryOsmosis.queryIncentivizedPools .computeAPY(pool.id, duration, priceStore, fiat) + .add( + IncludesInternalAndExternalIncentiveGaugeList[pool.id] + ? allowedGauges[0].rewardAmount + .maxDecimals(0) + .quo(new Dec(1000000)) + .toDec() + : new Dec(0) + ) .maxDecimals(2) .toString()} superfluidApr={superfluidApr?.maxDecimals(2).toString()} From 360e31eb4c32bc7392563ce83c8fc5f9eceea05c Mon Sep 17 00:00:00 2001 From: srph Date: Thu, 13 Oct 2022 04:11:05 +0800 Subject: [PATCH 02/11] Update --- .../pool-incentives/incentivized-pools.ts | 58 ++++++++++++++++++- .../stores/src/queries/pools/pool-details.ts | 9 +-- packages/stores/src/queries/pools/types.ts | 10 ++++ .../pool-incentives/incentivized-pools.d.ts | 3 +- .../types/queries/pools/pool-details.d.ts | 8 +-- .../stores/types/queries/pools/types.d.ts | 9 +++ packages/web/config/feature-flag.ts | 8 +++ packages/web/pages/pool/[id].tsx | 11 +++- 8 files changed, 98 insertions(+), 18 deletions(-) diff --git a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts index b3bdf6ff9b..e047667599 100644 --- a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts +++ b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts @@ -11,7 +11,7 @@ import { ObservableQueryEpochProvisions, ObservableQueryMintParmas, } from "../mint"; -import { ObservableQueryPools } from "../pools"; +import { ObservableQueryPools, ExternalGauge } from "../pools"; import { IPriceStore } from "../../price"; import { ObservableQueryDistrInfo } from "./distr-info"; import { ObservableQueryLockableDurations } from "./lockable-durations"; @@ -118,6 +118,52 @@ export class ObservableQueryIncentivizedPools extends ObservableChainQuery { + const apy = this.computeAPY(poolId, duration, priceStore, fiatCurrency); + + if (!externalGauges) { + return apy; + } + + const externalGauge = externalGauges.find((externalGauge) => { + return ( + duration.asMilliseconds() === externalGauge.duration.asMilliseconds() + ); + }); + + const mintDenom = this.queryMintParmas.mintDenom; + + if (!mintDenom) { + return apy; + } + + const chainInfo = this.chainGetter.getChain(this.chainId); + + const mintCurrency = chainInfo.findCurrency(mintDenom); + + if (!mintCurrency) { + return apy; + } + + if (!externalGauge?.rewardAmount) { + return apy; + } + + const amount = externalGauge.rewardAmount.moveDecimalPointLeft( + mintCurrency.coinDecimals + ); + + return apy.add(amount); + } + ); + /** * 리워드를 받을 수 있는 풀의 연당 이익률을 반환한다. * 리워드를 받을 수 없는 풀일 경우 0를 리턴한다. @@ -157,6 +203,7 @@ export class ObservableQueryIncentivizedPools extends ObservableChainQuery 0.18% + // computeAPYWithExternalGauges(803, 7, priceStore, fiatCurrency, whiteListedExternalGauges) -> 0.28% + // computeAPYWithExternalGauges(803, 14, priceStore, fiatCurrency, whiteListedExternalGauges) -> 14.55% + // + // externalGauge = externalGauge.duration === lockableDuration + // + // if (externalGauge?.rewardAmount) apy = apy.add(externalGauge.rewardAmount) + protected computeAPYForSpecificDuration( poolId: string, duration: Duration, @@ -205,6 +260,7 @@ export class ObservableQueryIncentivizedPools extends ObservableChainQuery RatePretty; + readonly computeAPYWithExternalIncentives: (poolId: string, duration: Duration, priceStore: IPriceStore, fiatCurrency: FiatCurrency, externalGauges: ExternalGauge[]) => RatePretty; /** * 리워드를 받을 수 있는 풀의 연당 이익률을 반환한다. * 리워드를 받을 수 없는 풀일 경우 0를 리턴한다. diff --git a/packages/stores/types/queries/pools/pool-details.d.ts b/packages/stores/types/queries/pools/pool-details.d.ts index d4751082ec..0f24b4115f 100644 --- a/packages/stores/types/queries/pools/pool-details.d.ts +++ b/packages/stores/types/queries/pools/pool-details.d.ts @@ -7,13 +7,7 @@ import { ObservableQueryIncentivizedPools, ObservableQueryLockableDurations, Obs import { ObservableQueryGuage } from "../incentives"; import { ObservableQueryAccountLocked, ObservableQueryAccountLockedCoins, ObservableQueryAccountUnlockingCoins } from "../lockup"; import { ObservableQueryPool } from "./pool"; -/** Non OSMO gauge. */ -export declare type ExternalGauge = { - id: string; - duration: Duration; - rewardAmount?: CoinPretty; - remainingEpochs: number; -}; +import { ExternalGauge } from "./types"; /** Convenience store for getting common details of a pool via many other query stores. */ export declare class ObservableQueryPoolDetails { protected readonly bech32Address: string; diff --git a/packages/stores/types/queries/pools/types.d.ts b/packages/stores/types/queries/pools/types.d.ts index 2ca0208b66..a64f7d09fb 100644 --- a/packages/stores/types/queries/pools/types.d.ts +++ b/packages/stores/types/queries/pools/types.d.ts @@ -1,7 +1,16 @@ import { WeightedPoolRaw } from "@osmosis-labs/pools"; +import { Duration } from "dayjs/plugin/duration"; +import { CoinPretty } from "@keplr-wallet/unit"; export declare type Pools = { pools: WeightedPoolRaw[]; }; export declare type NumPools = { num_pools: string; }; +/** Non OSMO gauge. */ +export declare type ExternalGauge = { + id: string; + duration: Duration; + rewardAmount?: CoinPretty; + remainingEpochs: number; +}; diff --git a/packages/web/config/feature-flag.ts b/packages/web/config/feature-flag.ts index fe84477c91..6a8944744a 100644 --- a/packages/web/config/feature-flag.ts +++ b/packages/web/config/feature-flag.ts @@ -55,6 +55,14 @@ export const PromotedLBPPoolIds: { ] : []; +// The pool ids white listed that would merge their internal and external gauges +export const MergesInternalAndExternalIncentiveGaugeList: Record< + string, + boolean +> = { + "803": true, +}; + /** Gauges to be rendered in pool's respective pool detail page. */ export const ExternalIncentiveGaugeAllowList: { [poolId: string]: { diff --git a/packages/web/pages/pool/[id].tsx b/packages/web/pages/pool/[id].tsx index ccf556e07b..5f4c778073 100644 --- a/packages/web/pages/pool/[id].tsx +++ b/packages/web/pages/pool/[id].tsx @@ -32,6 +32,7 @@ import { DepoolingTable } from "../../components/table/depooling-table"; import { truncateString } from "../../components/utils"; import { ExternalIncentiveGaugeAllowList, + MergesInternalAndExternalIncentiveGaugeList, UnPoolWhitelistedPoolIds, EventName, PromotedLBPPoolIds, @@ -828,7 +829,15 @@ const Pool: FunctionComponent = observer(() => { key={duration.humanize()} days={duration.humanize()} apr={queryOsmosis.queryIncentivizedPools - .computeAPY(pool.id, duration, priceStore, fiat) + .computeAPYWithExternalIncentives( + pool.id, + duration, + priceStore, + fiat, + MergesInternalAndExternalIncentiveGaugeList[pool.id] + ? allowedGauges + : [] + ) .maxDecimals(2) .toString()} superfluidApr={superfluidApr?.maxDecimals(2).toString()} From f6f11ff0b99afe059ed87bfe8f087674ac39dfa9 Mon Sep 17 00:00:00 2001 From: srph Date: Thu, 13 Oct 2022 04:16:23 +0800 Subject: [PATCH 03/11] Remove comments --- .../src/queries/pool-incentives/incentivized-pools.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts index b5d09dc634..505053eb9e 100644 --- a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts +++ b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts @@ -225,14 +225,6 @@ export class ObservableQueryIncentivizedPools extends ObservableChainQuery 0.18% - // computeAPYWithExternalGauges(803, 7, priceStore, fiatCurrency, whiteListedExternalGauges) -> 0.28% - // computeAPYWithExternalGauges(803, 14, priceStore, fiatCurrency, whiteListedExternalGauges) -> 14.55% - // - // externalGauge = externalGauge.duration === lockableDuration - // - // if (externalGauge?.rewardAmount) apy = apy.add(externalGauge.rewardAmount) - protected computeAPYForSpecificDuration( poolId: string, duration: Duration, @@ -282,11 +274,9 @@ export class ObservableQueryIncentivizedPools extends ObservableChainQuery Date: Thu, 13 Oct 2022 04:16:46 +0800 Subject: [PATCH 04/11] Remove buggy condition --- .../stores/src/queries/pool-incentives/incentivized-pools.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts index 505053eb9e..136f84e843 100644 --- a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts +++ b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts @@ -128,7 +128,7 @@ export class ObservableQueryIncentivizedPools extends ObservableChainQuery { const apy = this.computeAPY(poolId, duration, priceStore, fiatCurrency); - if (!externalGauges) { + if (!externalGauges.length) { return apy; } From 804844b2cc41fb6a29a247ddd0ca6788a1e4920d Mon Sep 17 00:00:00 2001 From: srph Date: Thu, 13 Oct 2022 04:17:27 +0800 Subject: [PATCH 05/11] Move condition up --- .../src/queries/pool-incentives/incentivized-pools.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts index 136f84e843..e17b14ed7e 100644 --- a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts +++ b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts @@ -138,6 +138,10 @@ export class ObservableQueryIncentivizedPools extends ObservableChainQuery Date: Thu, 13 Oct 2022 18:53:41 +0800 Subject: [PATCH 06/11] Remove configs --- .../queries/pool-incentives/incentivized-pools.ts | 6 +++--- packages/web/config/feature-flag.ts | 14 -------------- packages/web/pages/pool/[id].tsx | 4 +--- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts index e17b14ed7e..55f3dc2ff5 100644 --- a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts +++ b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts @@ -124,15 +124,15 @@ export class ObservableQueryIncentivizedPools extends ObservableChainQuery { const apy = this.computeAPY(poolId, duration, priceStore, fiatCurrency); - if (!externalGauges.length) { + if (!allowedGauges.length) { return apy; } - const externalGauge = externalGauges.find((externalGauge) => { + const externalGauge = allowedGauges.find((externalGauge) => { return ( duration.asMilliseconds() === externalGauge.duration.asMilliseconds() ); diff --git a/packages/web/config/feature-flag.ts b/packages/web/config/feature-flag.ts index f62edd9d6d..fe84477c91 100644 --- a/packages/web/config/feature-flag.ts +++ b/packages/web/config/feature-flag.ts @@ -37,12 +37,6 @@ export const UnPoolWhitelistedPoolIds: { [poolId: string]: boolean } = { "635": true, }; -export const IncludesInternalAndExternalIncentiveGaugeList: { - [poolId: string]: boolean; -} = { - // Stride ATOM/stATOM - "803": true, -}; /** List of pools active in LBP to present in frontend. */ export const PromotedLBPPoolIds: { poolId: string; @@ -61,14 +55,6 @@ export const PromotedLBPPoolIds: { ] : []; -// The pool ids white listed that would merge their internal and external gauges -export const MergesInternalAndExternalIncentiveGaugeList: Record< - string, - boolean -> = { - "803": true, -}; - /** Gauges to be rendered in pool's respective pool detail page. */ export const ExternalIncentiveGaugeAllowList: { [poolId: string]: { diff --git a/packages/web/pages/pool/[id].tsx b/packages/web/pages/pool/[id].tsx index 5f4c778073..2bdb1bed67 100644 --- a/packages/web/pages/pool/[id].tsx +++ b/packages/web/pages/pool/[id].tsx @@ -834,9 +834,7 @@ const Pool: FunctionComponent = observer(() => { duration, priceStore, fiat, - MergesInternalAndExternalIncentiveGaugeList[pool.id] - ? allowedGauges - : [] + allowedGauges ) .maxDecimals(2) .toString()} From 1585fb5d0ff654030478e77e20c5ac79c674ccff Mon Sep 17 00:00:00 2001 From: srph Date: Fri, 14 Oct 2022 03:27:07 +0800 Subject: [PATCH 07/11] Refactor external incentive calculation function --- .../pool-incentives/incentivized-pools.ts | 31 +++++++--------- .../pool-incentives/incentivized-pools.d.ts | 5 ++- packages/web/pages/pool/[id].tsx | 36 +++++++++++++------ 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts index 55f3dc2ff5..f2133351e8 100644 --- a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts +++ b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts @@ -118,18 +118,13 @@ export class ObservableQueryIncentivizedPools extends ObservableChainQuery { - const apy = this.computeAPY(poolId, duration, priceStore, fiatCurrency); - + /** + * Computes external incentive APY for the given duration + */ + readonly computeExternalIncentiveAPYForSpecificDuration = computedFn( + (duration: Duration, allowedGauges: ExternalGauge[]): RatePretty => { if (!allowedGauges.length) { - return apy; + return new RatePretty(new Dec(0)); } const externalGauge = allowedGauges.find((externalGauge) => { @@ -139,13 +134,13 @@ export class ObservableQueryIncentivizedPools extends ObservableChainQuery RatePretty; - readonly computeAPYWithExternalIncentives: (poolId: string, duration: Duration, priceStore: IPriceStore, fiatCurrency: FiatCurrency, externalGauges: ExternalGauge[]) => RatePretty; + /** + * Computes external incentive APY for the given duration + */ + readonly computeExternalIncentiveAPYForSpecificDuration: (duration: Duration, allowedGauges: ExternalGauge[]) => RatePretty; /** * 리워드를 받을 수 있는 풀의 연당 이익률을 반환한다. * 리워드를 받을 수 없는 풀일 경우 0를 리턴한다. diff --git a/packages/web/pages/pool/[id].tsx b/packages/web/pages/pool/[id].tsx index 2bdb1bed67..a3877fe6c1 100644 --- a/packages/web/pages/pool/[id].tsx +++ b/packages/web/pages/pool/[id].tsx @@ -192,6 +192,29 @@ const Pool: FunctionComponent = observer(() => { gaugeDurationMap.set(gauge.duration.asSeconds(), gauge); }); + // Compute combined APR (internal gauge + white-listed external gauge) + gaugeDurationMap.forEach((gauge) => { + const baseApy = queryOsmosis.queryIncentivizedPools.computeAPY( + pool.id, + gauge.duration, + priceStore, + fiat + ); + + const externalApy = + queryOsmosis.queryIncentivizedPools.computeExternalIncentiveAPYForSpecificDuration( + gauge.duration, + allowedGauges + ); + + const totalApr = baseApy.add(externalApy); + + gaugeDurationMap.set(gauge.duration.asSeconds(), { + ...gauge, + apr: totalApr, + }); + }); + return Array.from(gaugeDurationMap.values()).sort( (a, b) => a.duration.asSeconds() - b.duration.asSeconds() ); @@ -824,20 +847,11 @@ const Pool: FunctionComponent = observer(() => { )} {allowedLockupGauges && pool && (
- {allowedLockupGauges.map(({ duration, superfluidApr }) => ( + {allowedLockupGauges.map(({ duration, apr, superfluidApr }) => ( From 9161754a52c62ee51aeea20e4d9e292e5a06226b Mon Sep 17 00:00:00 2001 From: srph Date: Tue, 18 Oct 2022 03:10:43 +0800 Subject: [PATCH 08/11] Fix types --- packages/web/pages/pool/[id].tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/web/pages/pool/[id].tsx b/packages/web/pages/pool/[id].tsx index a3877fe6c1..1cbe7c5521 100644 --- a/packages/web/pages/pool/[id].tsx +++ b/packages/web/pages/pool/[id].tsx @@ -32,7 +32,6 @@ import { DepoolingTable } from "../../components/table/depooling-table"; import { truncateString } from "../../components/utils"; import { ExternalIncentiveGaugeAllowList, - MergesInternalAndExternalIncentiveGaugeList, UnPoolWhitelistedPoolIds, EventName, PromotedLBPPoolIds, @@ -195,7 +194,7 @@ const Pool: FunctionComponent = observer(() => { // Compute combined APR (internal gauge + white-listed external gauge) gaugeDurationMap.forEach((gauge) => { const baseApy = queryOsmosis.queryIncentivizedPools.computeAPY( - pool.id, + pool?.id ?? "", gauge.duration, priceStore, fiat From 7cc56346fbd4979e9a130fe1a67cd8206f3af361 Mon Sep 17 00:00:00 2001 From: srph Date: Fri, 21 Oct 2022 02:15:32 +0800 Subject: [PATCH 09/11] Update calculation --- .../pool-incentives/incentivized-pools.ts | 70 ++++++++++++++++--- .../pool-incentives/incentivized-pools.d.ts | 2 +- packages/web/pages/pool/[id].tsx | 7 ++ 3 files changed, 70 insertions(+), 9 deletions(-) diff --git a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts index f2133351e8..e48403facd 100644 --- a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts +++ b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts @@ -122,7 +122,13 @@ export class ObservableQueryIncentivizedPools extends ObservableChainQuery { + ( + poolId: string, + duration: Duration, + priceStore: IPriceStore, + fiatCurrency: FiatCurrency, + allowedGauges: ExternalGauge[] + ): RatePretty => { if (!allowedGauges.length) { return new RatePretty(new Dec(0)); } @@ -137,25 +143,67 @@ export class ObservableQueryIncentivizedPools extends ObservableChainQuery RatePretty; + readonly computeExternalIncentiveAPYForSpecificDuration: (poolId: string, duration: Duration, priceStore: IPriceStore, fiatCurrency: FiatCurrency, allowedGauges: ExternalGauge[]) => RatePretty; /** * 리워드를 받을 수 있는 풀의 연당 이익률을 반환한다. * 리워드를 받을 수 없는 풀일 경우 0를 리턴한다. diff --git a/packages/web/pages/pool/[id].tsx b/packages/web/pages/pool/[id].tsx index 1cbe7c5521..ed4cada27a 100644 --- a/packages/web/pages/pool/[id].tsx +++ b/packages/web/pages/pool/[id].tsx @@ -202,10 +202,17 @@ const Pool: FunctionComponent = observer(() => { const externalApy = queryOsmosis.queryIncentivizedPools.computeExternalIncentiveAPYForSpecificDuration( + pool?.id ?? "", gauge.duration, + priceStore, + fiat, allowedGauges ); + // if (externalApy.toString() !== "0%") { + // debugger; + // } + const totalApr = baseApy.add(externalApy); gaugeDurationMap.set(gauge.duration.asSeconds(), { From 0e258b3b81484312ad06b39bae7c341867760e40 Mon Sep 17 00:00:00 2001 From: srph Date: Fri, 21 Oct 2022 02:35:51 +0800 Subject: [PATCH 10/11] Rename vars --- .../src/queries/pool-incentives/incentivized-pools.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts index e48403facd..5260887719 100644 --- a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts +++ b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts @@ -192,7 +192,7 @@ export class ObservableQueryIncentivizedPools extends ObservableChainQuery Date: Fri, 21 Oct 2022 03:14:18 +0800 Subject: [PATCH 11/11] Remove comments --- .../stores/src/queries/pool-incentives/incentivized-pools.ts | 3 --- packages/web/pages/pool/[id].tsx | 4 ---- 2 files changed, 7 deletions(-) diff --git a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts index 5260887719..a41ae5b18b 100644 --- a/packages/stores/src/queries/pool-incentives/incentivized-pools.ts +++ b/packages/stores/src/queries/pool-incentives/incentivized-pools.ts @@ -310,8 +310,6 @@ export class ObservableQueryIncentivizedPools extends ObservableChainQuery { allowedGauges ); - // if (externalApy.toString() !== "0%") { - // debugger; - // } - const totalApr = baseApy.add(externalApy); gaugeDurationMap.set(gauge.duration.asSeconds(), {