Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/stage' into jose/fe-471-support-…
Browse files Browse the repository at this point in the history
…external-url-providers
  • Loading branch information
JoseRFelix committed Jun 12, 2024
2 parents 9de8449 + 3c225f8 commit 7d224c8
Show file tree
Hide file tree
Showing 83 changed files with 1,211 additions and 1,420 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/frontend-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install Playwright
run: |
yarn --cwd packages/web install --frozen-lockfile && npx playwright install --with-deps chromium
- name: Run Select Swap Pair tests on Master
- name: Run Swap Pair tests on Master
env:
BASE_URL: "https://app.osmosis.zone"
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Install Playwright
run: |
yarn --cwd packages/web install --frozen-lockfile && npx playwright install --with-deps chromium
- name: Run Select Swap Pair tests on Stage
- name: Run Swap Pair tests on Stage
env:
BASE_URL: ${{ github.event.deployment_status.environment_url }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
Expand Down
7 changes: 6 additions & 1 deletion packages/server/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ export const TIMESERIES_DATA_URL =
export const INDEXER_DATA_URL =
process.env.NEXT_PUBLIC_INDEXER_DATA_URL ??
"https://stage-proxy-data-indexer.osmosis-labs.workers.dev";
export const NUMIA_BASE_URL =
process.env.NEXT_PUBLIC_NUMIA_BASE_URL ??
"https://public-osmosis-api.numia.xyz";

// sqs
export const SIDECAR_BASE_URL =
process.env.NEXT_PUBLIC_SIDECAR_BASE_URL ?? "https://sqs.osmosis.zone/";
export const TFM_BASE_URL = process.env.NEXT_PUBLIC_TFM_API_BASE_URL;
export const NUMIA_BASE_URL = "https://public-osmosis-api.numia.xyz";

export const KEYBASE_BASE_URL = "https://keybase.io/";
export const KV_STORE_REST_API_URL = process.env.KV_STORE_REST_API_URL;
export const KV_STORE_REST_API_TOKEN = process.env.KV_STORE_REST_API_TOKEN;
Expand Down
80 changes: 43 additions & 37 deletions packages/server/src/queries/complex/concentrated-liquidity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,28 +255,27 @@ export async function mapGetUserPositionDetails({
...params,
bech32Address: userOsmoAddress,
});
const stakeCurrencyPromise = getAsset({
...params,
anyDenom: params.chainList[0].staking.staking_tokens[0].denom,
});
const superfluidPoolIdsPromise = getSuperfluidPoolIds(params);

const [
positions,
userUnbondingPositions,
delegatedPositions,
undelegatingPositions,
stakeCurrency,
superfluidPoolIds,
] = await Promise.all([
positionsPromise,
userUnbondingPositionsPromise,
delegatedPositionsPromise,
undelegatingPositionsPromise,
stakeCurrencyPromise,
superfluidPoolIdsPromise,
]);

const stakeCurrency = getAsset({
...params,
anyDenom: params.chainList[0].staking.staking_tokens[0].denom,
});

const lockableDurations = getLockableDurations();
const longestLockDuration = lockableDurations[lockableDurations.length - 1];

Expand Down Expand Up @@ -585,23 +584,28 @@ export type PositionHistoricalPerformance = Awaited<

/** Gets a breakdown of current and reward coins, with fiat values, for a single CL position. */
export async function getPositionHistoricalPerformance({
positionId,
position: givenPosition,
...params
}: {
assetLists: AssetList[];
chainList: Chain[];
positionId: string;
/** Position by ID or the returned position object. */
position: string | LiquidityPosition;
}) {
const [{ position }, performance] = await Promise.all([
queryPositionById({ ...params, id: positionId }),
queryPositionPerformance({
positionId,
}),
]);
const { position } =
typeof givenPosition === "string"
? await queryPositionById({ ...params, id: givenPosition })
: { position: givenPosition };

const performance = await queryPositionPerformance({
positionId: position.position.position_id,
});

// There is no performance data for this position
if (performance.message) {
console.error(`No performance data for position ${positionId}`);
console.error(
`No performance data for position ${position.position.position_id}`
);
}

// get all user CL coins, including claimable rewards
Expand Down Expand Up @@ -651,31 +655,33 @@ export async function getPositionHistoricalPerformance({

// calculate fiat values

const currentValue = new PricePretty(
DEFAULT_VS_CURRENCY,
await calcSumCoinsValue({ ...params, coins: currentCoins }).catch((e) =>
captureErrorAndReturn(e, new Dec(0))
)
);
const currentCoinsValues = (
await Promise.all(
const [
currentValue,
currentCoinsValues,
principalValue,
claimableRewardsValue,
totalEarnedValue,
] = await Promise.all([
calcSumCoinsValue({ ...params, coins: currentCoins })
.then((value) => new PricePretty(DEFAULT_VS_CURRENCY, value))
.catch(() => new PricePretty(DEFAULT_VS_CURRENCY, new Dec(0))),
Promise.all(
currentCoins
.map((coin) => calcCoinValue({ ...params, coin }))
.map((p) => p.catch((e) => captureErrorAndReturn(e, 0)))
)
).map((p) => new PricePretty(DEFAULT_VS_CURRENCY, p));
const principalValue = new PricePretty(
DEFAULT_VS_CURRENCY,
await calcSumCoinsValue({ ...params, coins: principalCoins })
);
const claimableRewardsValue = new PricePretty(
DEFAULT_VS_CURRENCY,
await calcSumCoinsValue({ ...params, coins: claimableRewardCoins })
);
const totalEarnedValue = new PricePretty(
DEFAULT_VS_CURRENCY,
await calcSumCoinsValue({ ...params, coins: totalRewardCoins })
);
).then((values) =>
values.map((p) => new PricePretty(DEFAULT_VS_CURRENCY, p))
),
calcSumCoinsValue({ ...params, coins: principalCoins }).then(
(value) => new PricePretty(DEFAULT_VS_CURRENCY, value)
),
calcSumCoinsValue({ ...params, coins: claimableRewardCoins }).then(
(value) => new PricePretty(DEFAULT_VS_CURRENCY, value)
),
calcSumCoinsValue({ ...params, coins: totalRewardCoins }).then(
(value) => new PricePretty(DEFAULT_VS_CURRENCY, value)
),
]);

const principalValueDec = principalValue.toDec();

Expand Down
7 changes: 5 additions & 2 deletions packages/server/src/queries/complex/pools/bonding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ export async function getSharePoolBondDurations({
userLockedLocks.forEach((userDurationLock) => {
userDurationLock.coins.forEach((coin) => {
if (getShareDenomPoolId(coin.denom) === poolId) {
userShares = userShares.add(
new CoinPretty(userShares.currency, coin.amount)
const lockedShares = new CoinPretty(
userShares.currency,
coin.amount
);
userShares = userShares.add(lockedShares);
}
});
userLockedLockIds.push(userDurationLock.ID);
Expand Down Expand Up @@ -334,6 +336,7 @@ export async function getSharePoolBondDurations({
return {
duration: dayjs.duration(durationMs),
bondable: isSuperfluid ? isLongestDuration : Boolean(durationGauges),
/** Locked shares */
userShares,
userLockedShareValue,
userLocks: userLockedLockIds.map((lockId) => ({
Expand Down
84 changes: 47 additions & 37 deletions packages/server/src/queries/complex/pools/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CoinPretty, Dec, IntPretty, PricePretty } from "@keplr-wallet/unit";
import { Dec, IntPretty, PricePretty } from "@keplr-wallet/unit";
import { AssetList, Chain } from "@osmosis-labs/types";
import { aggregateRawCoinsByDenom, timeout } from "@osmosis-labs/utils";

Expand Down Expand Up @@ -201,44 +201,54 @@ export async function getUserSharePools(params: {

// underlying assets behind all shares
// when catching: likely shares balance is too small for precision
const underlyingAvailableCoins: CoinPretty[] = available
? await getGammShareUnderlyingCoins({ ...params, ...available }).catch(
(e) => captureErrorAndReturn(e, [])
)
: [];
const underlyingLockedCoins: CoinPretty[] = locked
? await getGammShareUnderlyingCoins({ ...params, ...locked }).catch((e) =>
captureErrorAndReturn(e, [])
)
: [];
const underlyingUnlockingCoins: CoinPretty[] = unlocking
? await getGammShareUnderlyingCoins({ ...params, ...unlocking }).catch(
(e) => captureErrorAndReturn(e, [])
)
: [];
const totalCoins: CoinPretty[] = total
? await getGammShareUnderlyingCoins({ ...params, ...total }).catch((e) =>
captureErrorAndReturn(e, [])
)
: [];
const [
underlyingAvailableCoins,
underlyingLockedCoins,
underlyingUnlockingCoins,
totalCoins,
] = await Promise.all([
available
? getGammShareUnderlyingCoins({ ...params, ...available }).catch((e) =>
captureErrorAndReturn(e, [])
)
: Promise.resolve([]),
locked
? getGammShareUnderlyingCoins({ ...params, ...locked }).catch((e) =>
captureErrorAndReturn(e, [])
)
: Promise.resolve([]),
unlocking
? getGammShareUnderlyingCoins({ ...params, ...unlocking }).catch((e) =>
captureErrorAndReturn(e, [])
)
: Promise.resolve([]),
total
? getGammShareUnderlyingCoins({ ...params, ...total }).catch((e) =>
captureErrorAndReturn(e, [])
)
: Promise.resolve([]),
]);

// value of all shares
const availableValue = await calcSumCoinsValue({
...params,
coins: underlyingAvailableCoins,
});
const lockedValue = await calcSumCoinsValue({
...params,
coins: underlyingLockedCoins,
});
const unlockingValue = await calcSumCoinsValue({
...params,
coins: underlyingUnlockingCoins,
});
const totalValue = await calcSumCoinsValue({
...params,
coins: totalCoins,
});
const [availableValue, lockedValue, unlockingValue, totalValue] =
await Promise.all([
calcSumCoinsValue({
...params,
coins: underlyingAvailableCoins,
}),
calcSumCoinsValue({
...params,
coins: underlyingLockedCoins,
}),
calcSumCoinsValue({
...params,
coins: underlyingUnlockingCoins,
}),
calcSumCoinsValue({
...params,
coins: totalCoins,
}),
]);

// get locks containing this pool's shares
const lockedLocks = userLocks.filter(
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/queries/complex/staking/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./apr";
export * from "./superfluid";
export * from "./user";
export * from "./validator";
71 changes: 71 additions & 0 deletions packages/server/src/queries/complex/staking/superfluid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { CoinPretty, Dec, DecUtils } from "@keplr-wallet/unit";
import { AssetList, Chain } from "@osmosis-labs/types";
import cachified, { CacheEntry } from "cachified";
import { LRUCache } from "lru-cache";

import { DEFAULT_LRU_OPTIONS } from "../../../utils";
import {
querySuperfluidAssetMultiplier,
querySuperfluidParams,
} from "../../osmosis";
import { getAsset } from "../assets";
import { getShareDenomPoolId, makeGammShareCurrency } from "../pools";

const cache = new LRUCache<string, CacheEntry>(DEFAULT_LRU_OPTIONS);

/** Calculates the OSMO equivalent amount for the given superfluid asset. */
export async function calcOsmoSuperfluidEquivalent({
amount,
denom,
chainList,
assetLists,
}: {
amount: string;
denom: string;
chainList: Chain[];
assetLists: AssetList[];
}) {
return cachified({
cache: cache,
key: `osmo-equivalent-${denom}-${amount}`,
ttl: 1000 * 30, // 30 seconds
getFreshValue: async () => {
// primary chain
const chain = chainList[0];

const stakeDenom = chain.staking.staking_tokens[0].denom;
const stakeAsset = getAsset({ assetLists, anyDenom: stakeDenom });
const equivalentAsset = denom.startsWith("gamm")
? makeGammShareCurrency(getShareDenomPoolId(denom))
: getAsset({ assetLists, anyDenom: denom });

const multipication = DecUtils.getTenExponentN(
equivalentAsset.coinDecimals - stakeAsset.coinDecimals
);

const [minimumRiskFactor, assetMultiplier] = await Promise.all([
querySuperfluidParams({
chainList,
}).then(({ params }) => new Dec(params.minimum_risk_factor)),
querySuperfluidAssetMultiplier({
chainList,
denom,
}).then(
({ osmo_equivalent_multiplier: { multiplier } }) =>
new Dec(multiplier)
),
]);

const multiplier = assetMultiplier
.mul(new Dec(1).sub(minimumRiskFactor))
.mul(multipication);

return new CoinPretty(
stakeAsset,
new CoinPretty(equivalentAsset, amount)
.mul(multiplier)
.mul(DecUtils.getTenExponentN(stakeAsset.coinDecimals))
);
},
});
}
28 changes: 27 additions & 1 deletion packages/server/src/queries/complex/staking/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function getValidatorInfo({
return cachified({
cache: validatorsCache,
key: `validator-${validatorBech32Address}`,
ttl: 1000 * 10, // 10 seconds
ttl: 1000 * 30, // 30 seconds
getFreshValue: async () => {
let jailed = false;
let inactive = false;
Expand Down Expand Up @@ -89,3 +89,29 @@ export async function getValidatorInfo({
},
});
}

export async function getValidatorsWithInfos({
chainList,
status,
}: {
chainList: Chain[];
status: BondStatus;
}) {
return cachified({
cache: validatorsCache,
key: `validator-infos-${status}`,
ttl: 1000 * 30, // 30 seconds
getFreshValue: async () => {
const validators = await getValidators({ chainList, status });

return Promise.all(
validators.map((validator) =>
getValidatorInfo({
chainList,
validatorBech32Address: validator.operator_address,
}).then((info) => ({ ...validator, ...info }))
)
);
},
});
}
Loading

0 comments on commit 7d224c8

Please sign in to comment.