Skip to content

Commit

Permalink
Add acala/karura/bifrost to landing page, #1342 (#1348)
Browse files Browse the repository at this point in the history
* Support acala/karura/bifrost in eco server, #1342

* Catch token price fetch error, #1342

* Remove uesless todo, #1342

* Merge bifrost kusama and polkadot treasury balance, #1342

* Fix bifrost token price, #1342

* Enable bifrost on landing page, #1342
  • Loading branch information
wliyongfeng authored Dec 10, 2023
1 parent 2cff43e commit 4debdb7
Show file tree
Hide file tree
Showing 20 changed files with 269 additions and 15 deletions.
46 changes: 46 additions & 0 deletions landing/public/imgs/logo-acala-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions landing/public/imgs/logo-acala.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions landing/public/imgs/logo-bifrost-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions landing/public/imgs/logo-bifrost.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions landing/public/imgs/logo-karura-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions landing/public/imgs/logo-karura.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions landing/src/hooks/ecosystem/useAssetsDistributionData.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export function useEcosystemAssetsDistributionData() {
theme.blue300,
theme.skyblue500,
theme.skyblue300,
theme.pieChart1,
theme.pieChart2,
theme.pieChart3,
theme.pieChart4,
],
[theme],
);
Expand Down
4 changes: 2 additions & 2 deletions landing/src/hooks/useTreasuriesData.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { gql, useLazyQuery } from "@apollo/client";
import { getChainSettings } from "@site/src/utils/chains";
import { CHAINS, getChainSettings } from "@site/src/utils/chains";
import { toPrecision } from "@site/src/utils";
import sumBy from "lodash.sumby";
import { useEffect } from "react";
Expand All @@ -24,7 +24,7 @@ export function useTreasuriesData() {
useEffect(() => {
fetch().then((resp) => {
const treasuries = resp.data?.treasuries || [];
const data = treasuries.map((treasury) => {
const data = treasuries.filter(item => Object.keys(CHAINS).includes(item.chain)).map((treasury) => {
const { decimals } = getChainSettings(treasury.chain);
const amount = toPrecision(treasury.balance, decimals, false);
const fiatValue = amount * treasury.price;
Expand Down
1 change: 1 addition & 0 deletions packages/eco-data-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@graphql-tools/schema": "^10.0.0",
"@interlay/monetary-js": "^0.5.4",
"@osn/polkadot-api-container": "^1.1.11",
"@osn/scan-common": "0.6.3",
"dotenv": "^16.3.1",
"graphql": "^16.8.1",
"graphql-yoga": "^4.0.4",
Expand Down
21 changes: 20 additions & 1 deletion packages/eco-data-server/src/apis/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const CHAINS = Object.freeze({
hydradx: "hydradx",
interlay: "interlay",
kintsugi: "kintsugi",
acala: "acala",
karura: "karura",
bifrost: "bifrost",
});

const endpoints = Object.freeze({
Expand Down Expand Up @@ -49,12 +52,28 @@ const endpoints = Object.freeze({
],
moonriver: [
"wss://wss.api.moonriver.moonbeam.network",
"wss://moonriver-rpc.dwellir.com" ,
"wss://moonriver-rpc.dwellir.com",
],
moonbeam: [
"wss://wss.api.moonbeam.network/",
"wss://moonbeam-rpc.dwellir.com/",
],
acala: [
"wss://acala-rpc-0.aca-api.network",
"wss://acala-rpc-1.aca-api.network",
],
karura: [
"wss://karura-rpc-1.aca-api.network",
"wss://karura-rpc-2.aca-api.network/ws",
],
bifrostPolkadot: [
"wss://hk.p.bifrost-rpc.liebi.com/ws",
"wss://eu.bifrost-polkadot-rpc.liebi.com/ws"
],
bifrostKusama: [
"wss://bifrost-rpc.dwellir.com",
"wss://bifrost-rpc.liebi.com/ws",
],
});

module.exports = {
Expand Down
22 changes: 20 additions & 2 deletions packages/eco-data-server/src/apis/treasury.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const { getApis } = require("@osn/polkadot-api-container");
const { upsertChainTreasury } = require("../mongo/service");
const { CHAINS } = require("./endpoints");
const { Kintsugi, Interlay } = require("@interlay/monetary-js");
const {
utils: { bigAdd },
} = require("@osn/scan-common");

const EMPTY_U8A_32 = new Uint8Array(32);

Expand Down Expand Up @@ -36,14 +39,29 @@ async function queryBalanceFromApi(api, chain) {
return accountData ? accountData.data.free.toString() : "0";
}

async function updateTreasuryBalance(chain) {
async function queryChainTreasuryBalance(chain) {
const promises = [];
const apis = getApis(chain);
for (const api of apis) {
promises.push(queryBalanceFromApi(api, chain));
}

const balance = await Promise.any(promises);
return await Promise.any(promises);
}

async function queryBifrostTreasuryBalance() {
const balanceOnKusama = await queryChainTreasuryBalance("bifrostKusama");
const balanceOnPolkadot = await queryChainTreasuryBalance("bifrostPolkadot");
return bigAdd(balanceOnKusama, balanceOnPolkadot);
}

async function updateTreasuryBalance(chain) {
let balance;
if (CHAINS.bifrost === chain) {
balance = await queryBifrostTreasuryBalance();
} else {
balance = await queryChainTreasuryBalance(chain);
}
await upsertChainTreasury(chain, balance);
}

Expand Down
5 changes: 0 additions & 5 deletions packages/eco-data-server/src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// todo: 1. set chains and related endpoints
// todo: 2. decide database collections to save treasury and price data
// todo: 3. add scripts to read treasury balance and save it to database
// todo: 4. add graphql server to serve related data to fronted

require("dotenv").config();

const { createYoga } = require("graphql-yoga");
Expand Down
15 changes: 12 additions & 3 deletions packages/eco-data-server/src/jobs/price.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { endpoints } = require("../apis/endpoints");
const { CHAINS } = require("../apis/endpoints");
const { upsertChainPrice } = require("../mongo/service");

async function coingeckoGet(api) {
Expand All @@ -24,7 +24,14 @@ async function fetchPrice(coinId) {
}

async function updateTokenPrice(chain, coinId) {
const data = await fetchPrice(coinId);
let data;
try {
data = await fetchPrice(coinId);
} catch (e) {
console.log(`Failed to fetch price of ${ chain }`);
return;
}

const ticker = data?.tickers?.find(
(item) => item.coin_id === coinId && item.target === "USD",
);
Expand All @@ -40,12 +47,14 @@ async function updateTokenPrice(chain, coinId) {
function getCoinId(chain) {
if (["phala", "khala"].includes(chain)) {
return "pha";
} else if ([CHAINS.bifrost].includes(chain)) {
return "bifrost-native-coin";
}
return chain;
}

async function updateTokensPrice() {
const chains = Object.keys(endpoints);
const chains = Object.keys(CHAINS);
try {
const promises = [];
for (const chain of chains) {
Expand Down
4 changes: 2 additions & 2 deletions packages/eco-data-server/src/jobs/treasury.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { endpoints } = require("../apis/endpoints");
const { CHAINS } = require("../apis/endpoints");
const { updateTreasuryBalance } = require("../apis/treasury");

async function updateChainsTreasuryBalance() {
const chains = Object.keys(endpoints);
const chains = Object.keys(CHAINS);
try {
const promises = [];
for (const chain of chains) {
Expand Down
8 changes: 8 additions & 0 deletions site/src/styles/theme/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export const light = {
blue500: "rgba(8, 109, 227, 1)",
skyblue300: "#8DCDDC",
skyblue500: "#41C0DC",
pieChart1: "#9E4ADF",
pieChart2: "#CA95F4",
pieChart3: "#79CA47",
pieChart4: "#AFE48D",
neutral100: "rgba(255, 255, 255, 1)",
neutral200: "rgba(250, 250, 250, 1)",
neutral300: "rgba(244, 244, 244, 1)",
Expand Down Expand Up @@ -89,6 +93,10 @@ export const dark = {
blue500: "rgba(26, 107, 201, 1)",
skyblue300: "#176A7C",
skyblue500: "#1AA9C9",
pieChart1: "#8941C3",
pieChart2: "#64447D",
pieChart3: "#66A73E",
pieChart4: "#3F6626",
neutral100: "rgba(0, 0, 0, 1)",
neutral200: "rgba(15, 15, 15, 1)",
neutral300: "rgba(31, 31, 31, 1)",
Expand Down
11 changes: 11 additions & 0 deletions site/src/utils/chains/acala.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { capitalizeFirstLetter } from "../../utils";

const value = "acala";

export const acala = {
value,
name: capitalizeFirstLetter(value),
symbol: "ACA",
decimals: 12,
hasSubscan: true,
};
11 changes: 11 additions & 0 deletions site/src/utils/chains/bifrostPolkadot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { capitalizeFirstLetter } from "../../utils";

const value = "bifrost";

export const bifrost = {
value,
name: capitalizeFirstLetter(value),
symbol: "BNC",
decimals: 12,
hasSubscan: true,
};
Loading

0 comments on commit 4debdb7

Please sign in to comment.