Skip to content

Commit

Permalink
Merge branch 'stage' into jonator/v13
Browse files Browse the repository at this point in the history
  • Loading branch information
delivan committed Dec 8, 2022
2 parents e651e86 + 3ff2694 commit fbe1f22
Show file tree
Hide file tree
Showing 61 changed files with 1,165 additions and 460 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/push-docker-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
file: ./docker/Dockerfile
context: .
push: true
platforms: linux/amd64,linux/arm64
platforms: linux/amd64
tags: ${{ env.FRONTEND_DOCKER_REPOSITORY }}:${{ env.SHA }}, ${{ env.FRONTEND_DOCKER_REPOSITORY }}:latest
-
name: Build and push (frontier)
Expand All @@ -61,7 +61,7 @@ jobs:
file: ./docker/Dockerfile.frontier
context: .
push: true
platforms: linux/amd64,linux/arm64
platforms: linux/amd64
tags: ${{ env.FRONTIER_DOCKER_REPOSITORY }}:${{ env.SHA }}, ${{ env.FRONTIER_DOCKER_REPOSITORY }}:latest
-
name: Build and push (testnet)
Expand All @@ -70,5 +70,5 @@ jobs:
file: ./docker/Dockerfile.testnet
context: .
push: true
platforms: linux/amd64,linux/arm64
platforms: linux/amd64
tags: ${{ env.TESTNET_DOCKER_REPOSITORY }}:${{ env.SHA }}, ${{ env.TESTNET_DOCKER_REPOSITORY }}:latest
20 changes: 0 additions & 20 deletions Dockerfile

This file was deleted.

9 changes: 0 additions & 9 deletions docker-compose.yml

This file was deleted.

4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18 as build
FROM node:18.12.1 as build

WORKDIR /app

Expand All @@ -8,7 +8,7 @@ COPY packages /app/packages/
RUN yarn
RUN yarn build

FROM node:18-alpine3.15
FROM node:18.12.1-alpine3.15

WORKDIR /app
COPY --from=build /app .
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.frontier
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18 as build
FROM node:18.12.1 as build

WORKDIR /app

Expand All @@ -8,7 +8,7 @@ COPY packages /app/packages/
RUN yarn
RUN yarn build:frontier

FROM node:18-alpine3.15
FROM node:18.12.1-alpine3.15

WORKDIR /app
COPY --from=build /app .
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.testnet
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18 as build
FROM node:18.12.1 as build

WORKDIR /app

Expand All @@ -8,7 +8,7 @@ COPY packages /app/packages/
RUN yarn
RUN yarn build:testnet

FROM node:18-alpine3.15
FROM node:18.12.1-alpine3.15

WORKDIR /app
COPY --from=build /app .
Expand Down
6 changes: 3 additions & 3 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ In case you need to build images only:
### Main

```bash
docker-compose build frontend -t osmosis-frontend:main
docker-compose build frontend
```

### Frontier

```bash
docker-compose build frontend-frontier -t osmosis-frontend:frontier
docker-compose build frontend-frontier
```

### Testnet

```bash
docker-compose build frontend-testnet -t osmosis-frontend:testnet
docker-compose build frontend-testnet
```
133 changes: 62 additions & 71 deletions packages/stores/src/price/pool.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { makeObservable, observable, computed } from "mobx";
import { CoinGeckoPriceStore, ChainGetter } from "@keplr-wallet/stores";
import { FiatCurrency } from "@keplr-wallet/types";
import { CoinPretty, Dec } from "@keplr-wallet/unit";
import { Dec } from "@keplr-wallet/unit";
import { KVStore } from "@keplr-wallet/common";
import { ObservableQueryPools } from "../queries";
import { IntermediateRoute, IPriceStore } from "./types";
import { computedFn } from "mobx-utils";

/**
* PoolFallbackPriceStore permits the some currencies that are not listed on CoinGecko
Expand Down Expand Up @@ -48,80 +49,70 @@ export class PoolFallbackPriceStore
return result;
}

getPrice(coinId: string, vsCurrency?: string): number | undefined {
if (!vsCurrency) {
vsCurrency = this.defaultVsCurrency;
}

try {
const routes = this.intermediateRoutesMap;
const route = routes.get(coinId);
if (route) {
const pool = this.queryPool.getPool(route.poolId);
if (!pool) {
return;
}
readonly getPrice = computedFn(
(coinId: string, vsCurrency?: string): number | undefined => {
if (!vsCurrency) {
vsCurrency = this.defaultVsCurrency;
}

const osmosisChainInfo = this.chainGetter.getChain(this.osmosisChainId);
// If the currencies are unknown yet,
// it is assumed that the raw currency with the 0 decimals.
// But, using this raw currency will make improper result because it will create greater spot price than expected.
// So, if the currencies are unknown, block calculating the price.
if (
!osmosisChainInfo.currencies.find(
(cur) => cur.coinMinimalDenom === route.spotPriceSourceDenom
) ||
!osmosisChainInfo.currencies.find(
(cur) => cur.coinMinimalDenom === route.spotPriceDestDenom
)
) {
return;
try {
const routes = this.intermediateRoutesMap;
const route = routes.get(coinId);
if (route) {
const pool = this.queryPool.getPool(route.poolId);
if (!pool) {
return;
}

const osmosisChainInfo = this.chainGetter.getChain(
this.osmosisChainId
);
// If the currencies are unknown yet,
// it is assumed that the raw currency with the 0 decimals.
// But, using this raw currency will make improper result because it will create greater spot price than expected.
// So, if the currencies are unknown, block calculating the price.
if (
!osmosisChainInfo.currencies.find(
(cur) => cur.coinMinimalDenom === route.spotPriceSourceDenom
) ||
!osmosisChainInfo.currencies.find(
(cur) => cur.coinMinimalDenom === route.spotPriceDestDenom
)
) {
return;
}

const inSpotPrice = pool.getSpotPriceInOverOutWithoutSwapFee(
route.spotPriceSourceDenom,
route.spotPriceDestDenom
);
const spotPriceDec = inSpotPrice.toDec().equals(new Dec(0))
? new Dec(0)
: new Dec(1).quo(inSpotPrice.toDec());
const destCoinPrice = this.getPrice(route.destCoinId, vsCurrency);
if (destCoinPrice === undefined) {
return;
}

const res = parseFloat(spotPriceDec.toString()) * destCoinPrice;
if (Number.isNaN(res)) {
return;
}
// CoinGeckoPriceStore uses the `Dec` to calculate the price of assets.
// However, `Dec` requires that the decimals must not exceed 18.
// Since the spot price is `Dec`, it can have 18 decimals,
// and if the `destCoinPrice` has the fraction, the multiplication can make the more than 18 decimals.
// To prevent this problem, shorthand the fraction part.
return parseFloat(res.toFixed(10));
}

const inSpotPrice = pool.getSpotPriceInOverOutWithoutSwapFee(
route.spotPriceSourceDenom,
route.spotPriceDestDenom
return super.getPrice(coinId, vsCurrency);
} catch (e: any) {
console.error(
`Failed to calculate price of (${coinId}, ${vsCurrency}): ${e?.message}`
);
const spotPriceDec = inSpotPrice.toDec().equals(new Dec(0))
? new Dec(0)
: new Dec(1).quo(inSpotPrice.toDec());
const destCoinPrice = this.getPrice(route.destCoinId, vsCurrency);
if (destCoinPrice === undefined) {
return;
}

const res = parseFloat(spotPriceDec.toString()) * destCoinPrice;
if (Number.isNaN(res)) {
return;
}
// CoinGeckoPriceStore uses the `Dec` to calculate the price of assets.
// However, `Dec` requires that the decimals must not exceed 18.
// Since the spot price is `Dec`, it can have 18 decimals,
// and if the `destCoinPrice` has the fraction, the multiplication can make the more than 18 decimals.
// To prevent this problem, shorthand the fraction part.
return parseFloat(res.toFixed(10));
return undefined;
}

return super.getPrice(coinId, vsCurrency);
} catch (e: any) {
console.error(
`Failed to calculate price of (${coinId}, ${vsCurrency}): ${e?.message}`
);
return undefined;
}
}

getPricePretty(coin: CoinPretty, vsCurrency?: string, decimals = 2): string {
const coinId = coin.currency.coinGeckoId;
const currency = vsCurrency ? vsCurrency : this.defaultVsCurrency;
const symbol = this.getFiatCurrency(currency)?.symbol;
let price = "0";

if (coinId) {
const raw = super.getPrice(coinId, currency);
price = raw ? raw.toFixed(decimals) : "0";
}

return `${symbol}${price}`;
}
);
}
2 changes: 2 additions & 0 deletions packages/stores/src/queries-external/ibc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./status-by-id";
export * from "./types";
Loading

1 comment on commit fbe1f22

@vercel
Copy link

@vercel vercel bot commented on fbe1f22 Dec 8, 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.