Skip to content

Commit

Permalink
Merge pull request #1078 from osmosis-labs/stage
Browse files Browse the repository at this point in the history
Publish stage
  • Loading branch information
jonator authored Nov 30, 2022
2 parents 596146a + 3ff2694 commit e5f70fc
Show file tree
Hide file tree
Showing 21 changed files with 169 additions and 135 deletions.
34 changes: 20 additions & 14 deletions packages/stores/src/queries/lockup/account-locked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class ObservableQueryAccountLockedInner extends ObservableChainQuery<Acco
chainInfo.addUnknownCurrencies(...[...new Set(unknownCurrencies)]);
}

/** Locked coins aggregated by duration. */
get lockedCoins(): {
amount: CoinPretty;
lockIds: string[];
Expand All @@ -66,8 +67,8 @@ export class ObservableQueryAccountLockedInner extends ObservableChainQuery<Acco
});

const map: Map<
// key: coinMinimalDenom
string,
// key: duration in milliseconds
number,
{
amount: CoinPretty;
lockIds: string[];
Expand All @@ -76,30 +77,35 @@ export class ObservableQueryAccountLockedInner extends ObservableChainQuery<Acco
> = new Map();

for (const lock of matchedLocks) {
const seconds = parseInt(lock.duration.slice(0, -1));
const curDuration = dayjs.duration({ seconds });
const curDurationMs = curDuration.asMilliseconds();

for (const coin of lock.coins) {
const currency = this.chainGetter
.getChain(this.chainId)
.findCurrency(coin.denom);

if (currency) {
const key = currency.coinMinimalDenom;
if (!map.has(key)) {
const seconds = parseInt(lock.duration.slice(0, -1));

map.set(key, {
if (!map.has(curDurationMs)) {
map.set(curDurationMs, {
amount: new CoinPretty(currency, new Dec(0)),
lockIds: [],
duration: dayjs.duration({ seconds }),
duration: curDuration,
});
}

const value = map.get(key)!;
value.amount = value.amount.add(
new CoinPretty(currency, new Dec(coin.amount))
);
value.lockIds.push(lock.ID);
const curDurationValue = map.get(curDurationMs);

map.set(key, value);
// aggregate amount for current duration
if (curDurationValue) {
curDurationValue.amount = curDurationValue.amount.add(
new CoinPretty(currency, new Dec(coin.amount))
);
curDurationValue.lockIds.push(lock.ID);

map.set(curDurationMs, curDurationValue);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/stores/src/queries/lockup/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type AccountLockedLongerDuration = {
ID: string;
owner: string;
duration: string;
/** UTC */
end_time: string;
coins: {
denom: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class ObservableQueryLockableDurations extends ObservableChainQuery<Locka
makeObservable(this);
}

/** On chain param: bond durations capable of receiving internal (OSMO) mint incentives, assuming pool is marked incentivized. */
@computed
get lockableDurations(): Duration[] {
if (!this.response) {
Expand Down
10 changes: 10 additions & 0 deletions packages/stores/src/queries/pool-share/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,14 @@ export class ObservableQueryGammPoolShare {
});
}
);

fetch(bech32Address: string) {
return Promise.all([
this.queryPools.fetch(),
this.queryBalances.getQueryBech32Address(bech32Address).fetch(),
this.queryAccountLocked.get(bech32Address).fetch(),
this.queryLockedCoins.get(bech32Address).fetch(),
this.queryUnlockingCoins.get(bech32Address).fetch(),
]);
}
}
28 changes: 18 additions & 10 deletions packages/stores/src/ui-config/manage-liquidity/bond-liquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import { ObservableQueryPoolFeesMetrics } from "../../queries-external";
import { IPriceStore } from "../../price";
import { UserConfig } from "../user-config";

export type BondableDuration = {
export type BondDuration = {
duration: Duration;
/** Bondable if there's any active gauges for this duration. */
bondable: boolean;
userShares: CoinPretty;
userUnlockingShares?: { shares: CoinPretty; endTime?: Date };
aggregateApr: RatePretty;
Expand All @@ -30,6 +32,8 @@ export type BondableDuration = {
}[];
/** Both `delegated` and `undelegating` will be `undefined` if the user may "Go superfluid". */
superfluid?: {
/** Duration users can bond to for superfluid participation. Assumed to be longest duration on lock durations chain param. */
duration: Duration;
apr: RatePretty;
commission?: RatePretty;
validatorMoniker?: string;
Expand Down Expand Up @@ -61,23 +65,23 @@ export class ObservableBondLiquidityConfig extends UserConfig {
* 2. Liquidity needs to be bonded
*/
readonly calculateBondLevel = computedFn(
(bondableDurations: BondableDuration[]): 1 | 2 | undefined => {
(bondDurations: BondDuration[]): 1 | 2 | undefined => {
if (
this.poolDetails?.userAvailableValue.toDec().gt(new Dec(0)) &&
bondableDurations.length > 0
bondDurations.some((duration) => duration.bondable)
)
return 2;

if (this.poolDetails?.userAvailableValue.toDec().isZero()) return 1;
}
);

/** Gets all available durations for user to bond in, with a breakdown of the assets incentivizing the duration. Internal OSMO incentives & swap fees included in breakdown. */
readonly getBondableAllowedDurations = computedFn(
/** Gets all durations for user to bond in, or has locked tokens for, with a breakdown of the assets incentivizing the duration. Internal OSMO incentives & swap fees included in breakdown. */
readonly getAllowedBondDurations = computedFn(
(
findCurrency: (denom: string) => AppCurrency | undefined,
allowedGauges: { gaugeId: string; denom: string }[] | undefined
): BondableDuration[] => {
): BondDuration[] => {
const poolId = this.poolDetails.pool.id;
const gauges = this.superfluidPool.gaugesWithSuperfluidApr;

Expand Down Expand Up @@ -119,7 +123,7 @@ export class ObservableBondLiquidityConfig extends UserConfig {
});

return Array.from(durationsMsSet.values())
.sort()
.sort((a, b) => b - a)
.reverse()
.map((durationMs) => {
const curDuration = dayjs.duration({
Expand All @@ -142,6 +146,7 @@ export class ObservableBondLiquidityConfig extends UserConfig {
this.poolDetails.poolShareCurrency,
curDuration
).amount;

const unlockingUserShares =
queryLockedCoin.getUnlockingCoinWithDuration(
this.poolDetails.poolShareCurrency,
Expand All @@ -158,8 +163,7 @@ export class ObservableBondLiquidityConfig extends UserConfig {
}
: undefined;

const incentivesBreakdown: BondableDuration["incentivesBreakdown"] =
[];
const incentivesBreakdown: BondDuration["incentivesBreakdown"] = [];

// push single internal incentive for current duration
if (internalGaugeOfDuration) {
Expand Down Expand Up @@ -217,7 +221,7 @@ export class ObservableBondLiquidityConfig extends UserConfig {

// add superfluid data if highest duration
const sfsDuration = this.poolDetails.longestDuration;
let superfluid: BondableDuration["superfluid"] | undefined;
let superfluid: BondDuration["superfluid"] | undefined;
if (
this.superfluidPool.isSuperfluid &&
this.superfluidPool.superfluid &&
Expand All @@ -234,6 +238,7 @@ export class ObservableBondLiquidityConfig extends UserConfig {
: undefined;

superfluid = {
duration: sfsDuration,
apr: this.superfluidPool.superfluidApr,
commission: delegation?.validatorCommission,
delegated: !this.superfluidPool.superfluid.upgradeableLpLockIds
Expand All @@ -260,6 +265,9 @@ export class ObservableBondLiquidityConfig extends UserConfig {

return {
duration: curDuration,
bondable:
internalGaugeOfDuration !== undefined ||
externalGaugesOfDuration.length > 0,
userShares: lockedUserShares,
userUnlockingShares,
aggregateApr,
Expand Down
1 change: 1 addition & 0 deletions packages/stores/types/queries/lockup/account-locked.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export declare class ObservableQueryAccountLockedInner extends ObservableChainQu
constructor(kvStore: KVStore, chainId: string, chainGetter: ChainGetter, bech32Address: string);
protected canFetch(): boolean;
protected setResponse(response: Readonly<QueryResponse<AccountLockedLongerDuration>>): void;
/** Locked coins aggregated by duration. */
get lockedCoins(): {
amount: CoinPretty;
lockIds: string[];
Expand Down
1 change: 1 addition & 0 deletions packages/stores/types/queries/lockup/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export declare type AccountLockedLongerDuration = {
ID: string;
owner: string;
duration: string;
/** UTC */
end_time: string;
coins: {
denom: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LockableDurations } from "./types";
import { Duration } from "dayjs/plugin/duration";
export declare class ObservableQueryLockableDurations extends ObservableChainQuery<LockableDurations> {
constructor(kvStore: KVStore, chainId: string, chainGetter: ChainGetter);
/** On chain param: bond durations capable of receiving internal (OSMO) mint incentives, assuming pool is marked incentivized. */
get lockableDurations(): Duration[];
get highestDuration(): Duration | undefined;
}
1 change: 1 addition & 0 deletions packages/stores/types/queries/pool-share/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ export declare class ObservableQueryGammPoolShare {
amount: CoinPretty;
lockIds: string[];
}[];
fetch(bech32Address: string): Promise<[Generator<unknown, any, any>, void, Generator<unknown, any, any>, Generator<unknown, any, any>, Generator<unknown, any, any>]>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { ObservableQueryPoolDetails, ObservableQuerySuperfluidPool, ObservableQu
import { ObservableQueryPoolFeesMetrics } from "../../queries-external";
import { IPriceStore } from "../../price";
import { UserConfig } from "../user-config";
export declare type BondableDuration = {
export declare type BondDuration = {
duration: Duration;
/** Bondable if there's any active gauges for this duration. */
bondable: boolean;
userShares: CoinPretty;
userUnlockingShares?: {
shares: CoinPretty;
Expand All @@ -22,6 +24,8 @@ export declare type BondableDuration = {
}[];
/** Both `delegated` and `undelegating` will be `undefined` if the user may "Go superfluid". */
superfluid?: {
/** Duration users can bond to for superfluid participation. Assumed to be longest duration on lock durations chain param. */
duration: Duration;
apr: RatePretty;
commission?: RatePretty;
validatorMoniker?: string;
Expand Down Expand Up @@ -50,10 +54,10 @@ export declare class ObservableBondLiquidityConfig extends UserConfig {
* 1. Liquidity needs to be added
* 2. Liquidity needs to be bonded
*/
readonly calculateBondLevel: (bondableDurations: BondableDuration[]) => 1 | 2 | undefined;
/** Gets all available durations for user to bond in, with a breakdown of the assets incentivizing the duration. Internal OSMO incentives & swap fees included in breakdown. */
readonly getBondableAllowedDurations: (findCurrency: (denom: string) => AppCurrency | undefined, allowedGauges: {
readonly calculateBondLevel: (bondDurations: BondDuration[]) => 1 | 2 | undefined;
/** Gets all durations for user to bond in, or has locked tokens for, with a breakdown of the assets incentivizing the duration. Internal OSMO incentives & swap fees included in breakdown. */
readonly getAllowedBondDurations: (findCurrency: (denom: string) => AppCurrency | undefined, allowedGauges: {
gaugeId: string;
denom: string;
}[] | undefined) => BondableDuration[];
}[] | undefined) => BondDuration[];
}
43 changes: 0 additions & 43 deletions packages/web/components/assets/catalyst-icon.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions packages/web/components/assets/pool-assets-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const PoolAssetsIcon: FunctionComponent<Props> = ({
"w-[3.125rem] h-[3.125rem]": size === "md",
"w-[2.5rem] h-[2.5rem]": size === "sm",
},
"absolute z-10 rounded-full flex items-center justify-center overflow-hidden"
"absolute z-10 flex items-center justify-center overflow-hidden"
)}
>
{assets[0].coinImageUrl ? (
Expand All @@ -46,7 +46,7 @@ export const PoolAssetsIcon: FunctionComponent<Props> = ({
"w-[3.125rem] h-[3.125rem] ml-10": size === "md",
"w-[2.5rem] h-[2.5rem] ml-5": size === "sm",
},
"rounded-full shrink-0 flex items-center justify-center overflow-hidden"
"shrink-0 flex items-center justify-center overflow-hidden"
)}
>
{assets.length >= 3 ? (
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/cards/asset-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const AssetCard: FunctionComponent<
);
})
) : (
<div className="w-[2.125rem] h-[2.125rem] rounded-full shrink-0 flex items-center justify-center overflow-hidden">
<div className="w-[2.125rem] h-[2.125rem] shrink-0 flex items-center justify-center overflow-hidden">
<Image
alt="asset"
src={coinImageUrl}
Expand Down
Loading

3 comments on commit e5f70fc

@vercel
Copy link

@vercel vercel bot commented on e5f70fc Nov 30, 2022

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on e5f70fc Nov 30, 2022

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on e5f70fc Nov 30, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.