Skip to content

Commit

Permalink
test velords fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
RedBeardEth committed Jan 4, 2025
1 parent fdc7792 commit 9b97e9d
Show file tree
Hide file tree
Showing 15 changed files with 1,653 additions and 424 deletions.
4 changes: 2 additions & 2 deletions apps/nextjs/env.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable no-restricted-properties */
import { env as authEnv } from "@realms-world/auth/env";
import { createEnv } from "@t3-oss/env-nextjs";
import { vercel } from "@t3-oss/env-nextjs/presets";
import { z } from "zod";

import { env as authEnv } from "@realms-world/auth/env";

export const env = createEnv({
extends: [authEnv, vercel()],
shared: {
Expand All @@ -21,6 +20,7 @@ export const env = createEnv({
*/
server: {
DATABASE_URL: z.string().url(),
DUNE_API_KEY: z.string().optional(),
},

/**
Expand Down
13 changes: 7 additions & 6 deletions apps/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"dependencies": {
"@ark-project/react": "1.1.2",
"@avnu/avnu-sdk": "^2.1.1",
"@cartridge/connector": "^0.5.1",
"@cartridge/controller": "^0.5.1",
"@cartridge/connector": "^0.5.5",
"@cartridge/controller": "^0.5.5",
"@duneanalytics/client-sdk": "^0.2.4",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@keystatic/core": "^0.5.36",
Expand All @@ -39,8 +40,8 @@
"@realms-world/ui": "workspace:*",
"@realms-world/utils": "workspace:*",
"@reservoir0x/reservoir-kit-ui": "^2.5.16",
"@starknet-react/chains": "^3.0.2",
"@starknet-react/core": "^3.0.3",
"@starknet-react/chains": "^3.1.1",
"@starknet-react/core": "^3.6.3",
"@starkware-industries/commons-js-enums": "^1.2.0",
"@starkware-industries/commons-js-utils": "^1.2.2",
"@svgr/webpack": "^8.1.0",
Expand All @@ -64,7 +65,7 @@
"lodash": "4.17.21",
"lucide-react": "^0.441.0",
"merkletreejs": "^0.3.11",
"next": "^15.0.3",
"next": "^15.1.3",
"nuqs": "^1.20.0",
"react": "catalog:react19",
"react-dom": "catalog:react19",
Expand All @@ -76,7 +77,7 @@
"server-only": "0.0.1",
"siws": "workspace:*",
"starknet": "6.11.0",
"starknetkit": "^2.3.3",
"starknetkit": "^2.6.1",
"superjson": "2.2.1",
"viem": "^2.21.27",
"wagmi": "^2.12.19",
Expand Down
26 changes: 14 additions & 12 deletions apps/nextjs/src/app/(app)/tokenomics/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { Metadata } from "next";
import { NETWORK_NAME, SUPPORTED_L1_CHAIN_ID } from "@/constants/env";
import { stakingAddresses } from "@/constants/staking";
import { env } from "env";
import { getRealmNFTHolders } from "@/lib/subgraph/getRealmNFTHolders";
import { getWalletRealmsHeld } from "@/lib/subgraph/getWalletRealmsHeld";

import { getDaoAddressesArrayByChain } from "@realms-world/constants/src/DAO";
import { env } from "env";

import { PageLayout } from "../../_components/PageLayout";
import { DashBoard } from "./Dashboard";
Expand Down Expand Up @@ -133,17 +132,20 @@ export default async function Page() {

return (
<PageLayout title="$Lords Tokenomics">
<div className="pb-8 md:text-2xl">
The $Lords token is the native token of the Realms Autonomous World. It
is governed by BibliothecaDAO who controls the issuance of the token.
<div className="sm:px-4">
<div className="pb-8 md:text-2xl">
The $Lords token is the native token of the Realms Autonomous World.
It is governed by BibliothecaDAO who controls the issuance of the
token.
</div>
<DashBoard
tokenInfo={tokenData}
totalValueLocked={totalValueLocked}
exchangesVolume={exchangesVolume}
totalStakedRealms={totalStakedRealms}
realmNFTHolders={realmNFTHolders.length}
/>
</div>
<DashBoard
tokenInfo={tokenData}
totalValueLocked={totalValueLocked}
exchangesVolume={exchangesVolume}
totalStakedRealms={totalStakedRealms}
realmNFTHolders={realmNFTHolders.length}
/>
</PageLayout>
);
}
56 changes: 56 additions & 0 deletions apps/nextjs/src/app/api/dune/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { api } from "@/trpc/react";
import { DuneClient, QueryParameter } from "@duneanalytics/client-sdk";
import { db } from "@realms-world/db/client";
import { schema } from "@realms-world/db/schema";
import { env } from "env";

const { DUNE_API_KEY } = env;
const client = new DuneClient(DUNE_API_KEY ?? "");
export const config = {
cron: "0 */6 * * *",
};

export async function GET(request: Request) {
const queryID = 4101280;

try {
/*const executionResult = await client.getLatestResult({ queryId: queryID });
console.log(executionResult.result?.rows);
if (executionResult.result?.rows) {
// Filter and transform the rows to match schema
const filteredRows = executionResult.result.rows.map(
(row: Record<string, unknown>) => ({
source: row.Name as string,
amount: Number(row.amount),
block_time: new Date(row.block_time),
epoch: row.epoch ? new Date(row.epoch) : null,
epoch_total_amount: Number(row.epoch_total_amount),
sender_epoch_total_amount: row.sender_epoch_total_amount
? Number(row.sender_epoch_total_amount)
: 0,
}),
) satisfies (typeof schema.duneVelords.$inferInsert)[];
console.log(filteredRows[0]);*/

try {
const tokenAttributeResult = await db
.insert(schema.velords_burns)
.values([{ source: "test" }])
.returning({
source: schema.velords_burns.source,
//amount: schema.duneVelords.amount,
//epoch: schema.duneVelords.epoch,
});

console.log(tokenAttributeResult);

return new Response(JSON.stringify(tokenAttributeResult));
} catch (e) {
console.log(e);
return new Response(JSON.stringify(e));
}
} catch (error) {
console.error(error);
return new Response("Error fetching data from Dune", { status: 500 });
}
}
21 changes: 10 additions & 11 deletions packages/api/src/router/veLordsBurns.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { TRPCRouterRecord } from "@trpc/server";
import { z } from "zod";

import type { SQL } from "@realms-world/db";
import type { TRPCRouterRecord } from "@trpc/server";
import { and, desc, eq, gte, lte, sql } from "@realms-world/db";
import { velords_burns } from "@realms-world/db/schema";
import { velords_burns, velords_burns2 } from "@realms-world/db/schema";
import { z } from "zod";

import { publicProcedure } from "../trpc";

Expand All @@ -19,27 +18,27 @@ export const veLordsBurnsRouter = {
.query(({ ctx, input }) => {
const { sender, startTimestamp, endTimestamp } = input;
const whereFilter: SQL[] = sender
? [eq(velords_burns.sender, sender.toLowerCase())]
? [eq(velords_burns2.sender, sender.toLowerCase())]
: [];

if (startTimestamp) {
whereFilter.push(gte(velords_burns.timestamp, startTimestamp));
whereFilter.push(gte(velords_burns2.timestamp, startTimestamp));
}
if (endTimestamp) {
whereFilter.push(lte(velords_burns.timestamp, endTimestamp));
whereFilter.push(lte(velords_burns2.timestamp, endTimestamp));
}

return ctx.db.query.velords_burns.findMany({
return ctx.db.query.velords_burns2.findMany({
where: and(...whereFilter),
orderBy: desc(velords_burns.timestamp),
orderBy: desc(velords_burns2.timestamp),
});
}),

byHash: publicProcedure
.input(z.object({ hash: z.string() }))
.query(({ ctx, input }) => {
return ctx.db.query.erc721_bridge.findFirst({
where: eq(velords_burns.hash, input.hash),
where: eq(velords_burns2.hash, input.hash),
});
}),

Expand All @@ -59,7 +58,7 @@ export const veLordsBurnsRouter = {
weeks.week,
COALESCE(SUM(vb.amount), 0) AS total_amount
FROM weeks
LEFT JOIN ${velords_burns} vb ON DATE_TRUNC('week', vb.timestamp) = weeks.week
LEFT JOIN ${velords_burns2} vb ON DATE_TRUNC('week', vb.timestamp) = weeks.week
GROUP BY weeks.week
ORDER BY weeks.week ASC
LIMIT 11
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@auth/drizzle-adapter": "^1.4.2",
"@realms-world/db": "workspace:*",
"@t3-oss/env-nextjs": "^0.11.1",
"next": "^15.0.3",
"next": "^15.1.3",
"next-auth": "5.0.0-beta.19",
"react": "catalog:react19",
"react-dom": "catalog:react19",
Expand Down
2 changes: 1 addition & 1 deletion packages/db/drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
schema: "./src/schema/index.ts",
dialect: "postgresql",
dbCredentials: {
url: process.env.DATABASE_URL + "?ssl=true",
url: process.env.DATABASE_URL,
ssl: true,
},
} satisfies Config;
Loading

0 comments on commit 9b97e9d

Please sign in to comment.