Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@radix-ui/react-slot": "^1.2.3",
"@react-three/drei": "^9.86.3",
"@react-three/fiber": "^8.14.4",
"@t3-oss/env-nextjs": "^0.13.11",
"axios": "^1.5.1",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
Expand Down
49 changes: 49 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/app/[locale]/_actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import config from "@/config";
import { env } from "@/env";
import { formatNumber } from "@/modules/helpers/numFormatter";
import axios, { AxiosError } from "axios";
import {
Expand All @@ -8,7 +8,7 @@ import {
} from "./_schema";

const CACHE_DURATION_SECONDS_12_HR_IN_SECONDS = 12 * 60 * 60;
const SOPHIA_STATS_API_URL = `https://app.iqai.com/api/agents/stats?address=${config.sophiaAgentAddress}`;
const SOPHIA_STATS_API_URL = `https://app.iqai.com/api/agents/stats?address=${env.NEXT_PUBLIC_SOPHIA_AGENT_ADDRESS}`;

export async function getIqStats() {
try {
Expand Down Expand Up @@ -85,9 +85,9 @@ export async function getSophiaStats() {

async function fetchMarketCapData(): Promise<CMCTokenData> {
try {
const response = await axios.get(`${config.iqGatewayUrl}`, {
const response = await axios.get(`${env.NEXT_PUBLIC_IQ_GATEWAY_URL}`, {
headers: {
"x-api-key": config.iqGatewayKey,
"x-api-key": env.NEXT_PUBLIC_IQ_GATEWAY_KEY,
},
params: {
url: "https://pro-api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=everipedia",
Expand Down
12 changes: 6 additions & 6 deletions src/components/layouts/CgPosthogProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"use client";

import config from "@/config";
import { env } from "@/env";
import posthog from "posthog-js";
import { PostHogProvider } from "posthog-js/react";

if (typeof window !== "undefined") {
posthog.init(config.posthogApiKey, {
api_host: "/ingest",
ui_host: "https://us.posthog.com",
});
posthog.init(env.NEXT_PUBLIC_POSTHOG_KEY, {
api_host: "/ingest",
ui_host: "https://us.posthog.com",
});
}

export const CSPostHogProvider = ({ children }: React.PropsWithChildren) => {
return <PostHogProvider client={posthog}>{children}</PostHogProvider>;
return <PostHogProvider client={posthog}>{children}</PostHogProvider>;
};
20 changes: 0 additions & 20 deletions src/config/index.ts

This file was deleted.

46 changes: 46 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";

const isProd = process.env.NEXT_PUBLIC_VERCEL_ENV === "production";

export const env = createEnv({
client: {
NEXT_PUBLIC_IQ_ADDRESS: z
.string()
.min(1)
.default("0x579cea1889991f68acc35ff5c3dd0621ff29b0c9"),
NEXT_PUBLIC_HIIQ_ADDRESS: z
.string()
.min(1)
.default("0x1bf5457ecaa14ff63cc89efd560e251e814e16ba"),
NEXT_PUBLIC_SOPHIA_AGENT_ADDRESS: z
.string()
.min(1)
.default("0x4dBcC239b265295500D2Fe2d0900629BDcBBD0fB"),
NEXT_PUBLIC_IQ_GATEWAY_URL: z
.string()
.url()
.default("https://gateway.braindao.org"),
NEXT_PUBLIC_POSTHOG_KEY: z
.string()
.min(1)
.default(
isProd
? "phc_4MsVVKQqCaAJUKqSLTIbPpEEl4fWW8h8FKV8mj7Wjsf"
: "phc_cRzhhwKmv122zsoEzDViTsRWaFNxPP9GeZJ5p4eWniZ",
),
NEXT_PUBLIC_ALCHEMY_API_KEY: z.string().min(1),
NEXT_PUBLIC_IQ_GATEWAY_KEY: z.string().min(1),
},
experimental__runtimeEnv: {
NEXT_PUBLIC_IQ_ADDRESS: process.env.NEXT_PUBLIC_IQ_ADDRESS,
NEXT_PUBLIC_HIIQ_ADDRESS: process.env.NEXT_PUBLIC_HIIQ_ADDRESS,
NEXT_PUBLIC_SOPHIA_AGENT_ADDRESS:
process.env.NEXT_PUBLIC_SOPHIA_AGENT_ADDRESS,
NEXT_PUBLIC_IQ_GATEWAY_URL: process.env.NEXT_PUBLIC_IQ_GATEWAY_URL,
NEXT_PUBLIC_POSTHOG_KEY: process.env.NEXT_PUBLIC_POSTHOG_KEY,
NEXT_PUBLIC_ALCHEMY_API_KEY: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY,
NEXT_PUBLIC_IQ_GATEWAY_KEY: process.env.NEXT_PUBLIC_IQ_GATEWAY_KEY,
},
emptyStringAsUndefined: true,
});
4 changes: 2 additions & 2 deletions src/modules/alchemyFetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import config from "@/config";
import { env } from "@/env";

export const HEX_BASE = 16;
export const WEI_TO_ETHER_DIVISOR = 10e17;
Expand All @@ -13,7 +13,7 @@ type RPCParams = [EthCallParams, string] | unknown[];

export const alchemyFetch = async (method: string, params: RPCParams) => {
const response = await fetch(
`https://eth-mainnet.g.alchemy.com/v2/${config.alchemyApiKey}`,
`https://eth-mainnet.g.alchemy.com/v2/${env.NEXT_PUBLIC_ALCHEMY_API_KEY}`,
{
method: "POST",
headers: {
Expand Down
6 changes: 3 additions & 3 deletions src/modules/fetchCoinMarketData.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import config from "@/config";
import { env } from "@/env";

const CACHE_TIME = 60 * 60 * 24;
export const formatNumber = new Intl.NumberFormat("en", {
notation: "compact",
}).format;

export const fetchCoinMarketData = async () => {
const proxyUrl = new URL(config.iqGatewayUrl);
const proxyUrl = new URL(env.NEXT_PUBLIC_IQ_GATEWAY_URL);
const targetUrl =
"https://pro-api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=everipedia";

Expand All @@ -16,7 +16,7 @@ export const fetchCoinMarketData = async () => {
try {
const response = await fetch(proxyUrl.href, {
headers: {
"x-api-key": config.iqGatewayKey,
"x-api-key": env.NEXT_PUBLIC_IQ_GATEWAY_KEY,
},
});

Expand Down
42 changes: 21 additions & 21 deletions src/modules/getLockOverview.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import config from "@/config";
import { env } from "@/env";
import { HEX_BASE, WEI_TO_ETHER_DIVISOR, alchemyFetch } from "./alchemyFetch";

const getTotalHiiqSupply = async () => {
try {
const data = await alchemyFetch("eth_call", [
{
to: config.hiiqAddress,
data: "0x18160ddd",
},
"latest",
]);
try {
const data = await alchemyFetch("eth_call", [
{
to: env.NEXT_PUBLIC_HIIQ_ADDRESS,
data: "0x18160ddd",
},
"latest",
]);

const totalHiiq = Number.parseInt(data, HEX_BASE) / WEI_TO_ETHER_DIVISOR;
return totalHiiq;
} catch (error) {
console.error("🚨 Error getting total hiIQ supply", error);
throw new Error("🚨 Error getting total hiIQ supply");
}
const totalHiiq = Number.parseInt(data, HEX_BASE) / WEI_TO_ETHER_DIVISOR;
return totalHiiq;
} catch (error) {
console.error("🚨 Error getting total hiIQ supply", error);
throw new Error("🚨 Error getting total hiIQ supply");
}
};

export const getLockOverview = async () => {
const totalHiiqSupply = await getTotalHiiqSupply();
const totalHiiqSupply = await getTotalHiiqSupply();

return {
totalSupplyError: totalHiiqSupply === 0,
isFetchingTotalSupply: false,
totalHiiqSupply,
};
return {
totalSupplyError: totalHiiqSupply === 0,
isFetchingTotalSupply: false,
totalHiiqSupply,
};
};
40 changes: 20 additions & 20 deletions src/modules/getTVL.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import config from "@/config";
import { env } from "@/env";
import { HEX_BASE, WEI_TO_ETHER_DIVISOR, alchemyFetch } from "./alchemyFetch";

export const getTvl = async () => {
try {
const data = await alchemyFetch("eth_call", [
{
from: "0x0000000000000000000000000000000000000000",
to: config.iqAddress,
data: `0x70a08231000000000000000000000000${config.hiiqAddress.replace(
"0x",
""
)}`,
},
"latest",
]);
try {
const data = await alchemyFetch("eth_call", [
{
from: "0x0000000000000000000000000000000000000000",
to: env.NEXT_PUBLIC_IQ_ADDRESS,
data: `0x70a08231000000000000000000000000${env.NEXT_PUBLIC_HIIQ_ADDRESS.replace(
"0x",
"",
)}`,
},
"latest",
]);

let tvl = Number.parseInt(data, HEX_BASE);
tvl = tvl / WEI_TO_ETHER_DIVISOR;
return Math.floor(tvl);
} catch (error) {
console.error("🚨 Error getting TVL", error);
throw new Error("🚨 Error getting TVL");
}
let tvl = Number.parseInt(data, HEX_BASE);
tvl = tvl / WEI_TO_ETHER_DIVISOR;
return Math.floor(tvl);
} catch (error) {
console.error("🚨 Error getting TVL", error);
throw new Error("🚨 Error getting TVL");
}
};
Loading