Skip to content

Commit

Permalink
Merge branch 'main' of github.com:EjembiEmmanuel/afk_monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
EjembiEmmanuel committed Aug 29, 2024
2 parents 6d99ce0 + 06b407f commit 41c6e02
Show file tree
Hide file tree
Showing 81 changed files with 2,102 additions and 763 deletions.
27 changes: 27 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,33 @@
"contributions": [
"code"
]
},
{
"login": "manlikeHB",
"name": "Yusuf Habib",
"avatar_url": "https://avatars.githubusercontent.com/u/109147010?v=4",
"profile": "https://github.com/manlikeHB",
"contributions": [
"code"
]
},
{
"login": "Dprof-in-tech",
"name": "Isaac Onyemaechi Ugwu",
"avatar_url": "https://avatars.githubusercontent.com/u/116242877?v=4",
"profile": "https://isaaconyemaechi.tech/",
"contributions": [
"code"
]
},
{
"login": "EjembiEmmanuel",
"name": "Oche",
"avatar_url": "https://avatars.githubusercontent.com/u/83036156?v=4",
"profile": "https://github.com/EjembiEmmanuel",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
13 changes: 8 additions & 5 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[submodule "solidity/solidity_contracts/lib/kakarot-lib"]
path = solidity/solidity_contracts/lib/kakarot-lib
url = https://github.com/kkrt-labs/kakarot-lib
[submodule "solidity/solidity_contracts/lib/forge-std"]
path = solidity/solidity_contracts/lib/forge-std
[submodule "onchain/lib/kakarot-rpc"]
path = onchain/lib/kakarot-rpc
url = https://github.com/kkrt-labs/kakarot-rpc
[submodule "onchain/solidity_contracts/lib/forge-std"]
path = onchain/solidity_contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "onchain/solidity_contracts/lib/kakarot-lib"]
path = onchain/solidity_contracts/lib/kakarot-lib
url = https://github.com/kkrt-labs/kakarot-lib
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/bhavyagosai"><img src="https://avatars.githubusercontent.com/u/64588227?v=4?s=100" width="100px;" alt="Bhavya Gosai"/><br /><sub><b>Bhavya Gosai</b></sub></a><br /><a href="https://github.com/AFK-AlignedFamKernel/afk_monorepo/commits?author=bhavyagosai" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/manlikeHB"><img src="https://avatars.githubusercontent.com/u/109147010?v=4?s=100" width="100px;" alt="Yusuf Habib"/><br /><sub><b>Yusuf Habib</b></sub></a><br /><a href="https://github.com/AFK-AlignedFamKernel/afk_monorepo/commits?author=manlikeHB" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://isaaconyemaechi.tech/"><img src="https://avatars.githubusercontent.com/u/116242877?v=4?s=100" width="100px;" alt="Isaac Onyemaechi Ugwu"/><br /><sub><b>Isaac Onyemaechi Ugwu</b></sub></a><br /><a href="https://github.com/AFK-AlignedFamKernel/afk_monorepo/commits?author=Dprof-in-tech" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/EjembiEmmanuel"><img src="https://avatars.githubusercontent.com/u/83036156?v=4?s=100" width="100px;" alt="Oche"/><br /><sub><b>Oche</b></sub></a><br /><a href="https://github.com/AFK-AlignedFamKernel/afk_monorepo/commits?author=EjembiEmmanuel" title="Code">💻</a></td>
</tr>
</tbody>
<tfoot>
Expand Down
5 changes: 3 additions & 2 deletions apps/data-backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ TELEGRAM_WEB_APP="https://tg.afk-community.xyz"
INDEXER_DATABASE_URL="postgresql://postgres"
TELEGRAM_BOT_TOKEN=TG_BOT_FATHER
TG_ADMIN_CHAT_ID=
WEBHOOK_DOMAIN=https://data-backend.xyz
WEBHOOK_DOMAIN="https://data-backend.xyz"

BACKEND_DATABASE_URL=
BACKEND_DATABASE_URL=
APP_URL_WEB="http://localhost:8081"
50 changes: 22 additions & 28 deletions apps/data-backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
import express from "express";
import {server} from "./graphql"
import dotenv from "dotenv";
import router from "./router";
import helmet from "helmet"
import helmet from "helmet";
import { launchBot, sendWebAppButton } from "./services/telegram-app";
const cors = require("cors")
const cors = require("cors");

dotenv.config();
const app = express();
app.use(cors())
app.use(helmet())
// Alternatively, you can configure CORS for specific routes or origins

app.use(helmet());
app.use(cors({
origin: 'http://localhost:8081' // Adjust this to match the URL of your React Native web version if necessary
origin: process.env.APP_URL_WEB
}));
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
// app.use(cors)
// app.use(express.urlencoded({ extended: false }))
// app.use(express.json())
// Start the Backend
const port = process.env.PORT || 5050;
app.use('/', router)
app.use('/telegram-app', router)
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.use('/', router);
const port = process.env.PORT || 5050;
app.listen(port, () => {
console.log(`🚀 Backend server running at http://localhost:${port}`);
try {
launchBot(process.env.TELEGRAM_BOT_TOKEN)
}catch(e) {

}
// sendWebAppButton(process.env.TG_ADMIN_CHAT_ID)
console.log(`🚀 Backend server running at http://localhost:${port}`);
try {
launchBot(process.env.TELEGRAM_BOT_TOKEN);
} catch (error) {
console.error("Error launching bot:", error);
}
});

// Start the server GraphQL
// server.listen().then(({ url }) => {
// console.log(`🚀 Backend server running at http://localhost:${port}/graphql`);
// });
// Optionally re-enable GraphQL if you plan to use it
/*
server.listen({ port: 4000 }).then(({ url }) => {
console.log(`🚀 GraphQL server ready at ${url}`);
});
*/
27 changes: 18 additions & 9 deletions apps/data-backend/src/router.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import express from 'express'
import express from 'express';

import deploy from './routes/indexer/deploy-token'
import deployLaunch from './routes/indexer/deploy-launch'
import buyCoin from './routes/indexer/buy-coin'
import deploy from './routes/indexer/deploy-token';
import deployLaunch from './routes/indexer/deploy-launch';
import buyCoin from './routes/indexer/buy-coin';
import tokenStats from './routes/indexer/token_stats';
import tokenGraph from './routes/indexer/graph';
import holdings from './routes/indexer/holdings';
import transactions from './routes/indexer/transactions';

const Router = express.Router()
Router.use('/deploy', deploy)
Router.use('/deploy-launch', deployLaunch)
Router.use("/buy-coin", buyCoin)
const Router = express.Router();

export default Router
Router.use('/deploy', deploy);
Router.use('/deploy-launch', deployLaunch);
Router.use('/buy-coin', buyCoin);
Router.use('/stats', tokenStats);
Router.use('/candles', tokenGraph);
Router.use('/token-distribution', holdings);
Router.use('/my-share', transactions);

export default Router;
6 changes: 0 additions & 6 deletions apps/data-backend/src/routes/indexer/deploy-launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ const Router = express.Router()
Router.get('/', async (req, res) => {
try {
const launches = await prisma.token_launch.findMany({})
// console.log("launches", launches)
res.status(HTTPStatus.OK).json({
data:launches
})
// res.status(HTTPStatus.OK).json({
// data: launches
// })
} catch (error) {
res.status(HTTPStatus.InternalServerError).send(error)
}
Expand Down Expand Up @@ -64,6 +60,4 @@ Router.get('/stats/:launch', async (req, res) => {
}
})



export default Router
54 changes: 54 additions & 0 deletions apps/data-backend/src/routes/indexer/graph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import express from 'express';
const { prisma } = require("indexer-prisma");
import { HTTPStatus } from '../../utils/http';
import { isValidStarknetAddress } from '../../utils/starknet';

const Router = express.Router();

Router.get('/candles/:tokenAddress', async (req, res) => {
const { tokenAddress } = req.params;

if (!isValidStarknetAddress(tokenAddress)) {
return res.status(HTTPStatus.BadRequest).json({
error: "Invalid token address format."
});
}

try {
const transactions = await prisma.token_transactions.findMany({
where: { memecoin_address: tokenAddress },
orderBy: { block_timestamp: 'asc' },
select: {
price: true,
block_timestamp: true,
transaction_type: true
}
});

if (transactions.length === 0) {
return res.status(HTTPStatus.NotFound).json({
error: "No transactions found for this token address."
});
}
// Hourly candles
const candles = transactions.reduce((acc, { block_timestamp, price }) => {
const hour = block_timestamp.getHours();
if (!acc[hour]) {
acc[hour] = { open: price, high: price, low: price, close: price };
} else {
acc[hour].high = Math.max(acc[hour].high, price);
acc[hour].low = Math.min(acc[hour].low, price);
acc[hour].close = price;
}
return acc;
}, {});

res.status(HTTPStatus.OK).json(candles);
} catch (error) {
res.status(HTTPStatus.InternalServerError).json({
error: "Internal Server Error while generating candles."
});
}
});

export default Router;
44 changes: 44 additions & 0 deletions apps/data-backend/src/routes/indexer/holdings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import express from 'express';
const { prisma } = require("indexer-prisma");
import { HTTPStatus } from '../../utils/http';
import { isValidStarknetAddress } from '../../utils/starknet';

const Router = express.Router();

Router.get('/token-distribution/:tokenAddress', async (req, res) => {
const { tokenAddress } = req.params;

if (!isValidStarknetAddress(tokenAddress)) {
return res.status(HTTPStatus.BadRequest).json({
error: "Invalid token address format."
});
}

try {
const distributions = await prisma.token_transactions.groupBy({
by: ['owner_address'],
where: { memecoin_address: tokenAddress },
_sum: {
amount: true
},
_count: {
owner_address: true
}
});

if (distributions.length === 0) {
return res.status(HTTPStatus.NotFound).json({
error: "No holders found for this token address."
});
}

res.status(HTTPStatus.OK).json(distributions);
} catch (error) {
console.error("Failed to fetch token distribution:", error);
res.status(HTTPStatus.InternalServerError).json({
error: "Internal Server Error while fetching token distribution."
});
}
});

export default Router;
43 changes: 43 additions & 0 deletions apps/data-backend/src/routes/indexer/token_stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import express from 'express';
const { prisma } = require("indexer-prisma");
import { HTTPStatus } from '../../utils/http';
import { isValidStarknetAddress } from '../../utils/starknet';

const Router = express.Router();

// Endpoint to get the latest statistics for a specific token address
Router.get('/stats/:tokenAddress', async (req, res) => {
const { tokenAddress } = req.params;

if (!isValidStarknetAddress(tokenAddress)) {
return res.status(HTTPStatus.BadRequest).json({
error: "Invalid token address format."
});
}

try {
// Query the latest price and liquidity raised
const stats = await prisma.token_transactions.findFirst({
where: { memecoin_address: tokenAddress },
orderBy: { created_at: 'desc' },
select: {
price: true,
liquidity_raised: true
}
});

if (stats) {
res.status(HTTPStatus.OK).json(stats);
} else {
res.status(HTTPStatus.NotFound).json({
error: "No data found for the specified token address."
});
}
} catch (error) {
res.status(HTTPStatus.InternalServerError).json({
error: "Internal Server Error while fetching statistics."
});
}
});

export default Router;
54 changes: 54 additions & 0 deletions apps/data-backend/src/routes/indexer/transactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import express from 'express';
const { prisma } = require("indexer-prisma");
import { HTTPStatus } from '../../utils/http';
import { isValidStarknetAddress } from '../../utils/starknet';

const Router = express.Router();

Router.get('/my-share/:tokenAddress/:userId', async (req, res) => {
const { tokenAddress, userId } = req.params;

if (!isValidStarknetAddress(tokenAddress)) {
return res.status(HTTPStatus.BadRequest).json({
error: "Invalid token address format."
});
}

try {
const transactions = await prisma.token_transactions.findMany({
where: {
memecoin_address: tokenAddress,
owner_address: userId
},
select: {
transaction_type: true,
amount: true
}
});

if (transactions.length === 0) {
return res.status(HTTPStatus.NotFound).json({
error: "No transactions found for this user and token address."
});
}

const result = transactions.reduce((acc, cur) => {
acc.total += parseFloat(cur.amount || 0);
if (cur.transaction_type === 'buy') {
acc.buy += parseFloat(cur.amount || 0);
} else if (cur.transaction_type === 'sell') {
acc.sell += parseFloat(cur.amount || 0);
}
return acc;
}, { total: 0, buy: 0, sell: 0 });

res.status(HTTPStatus.OK).json(result);
} catch (error) {
console.error("Failed to retrieve user transactions:", error);
res.status(HTTPStatus.InternalServerError).json({
error: "Internal Server Error while fetching user transactions."
});
}
});

export default Router;
3 changes: 2 additions & 1 deletion apps/indexer/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export const FACTORY_ADDRESS = '0x01a46467a9246f45c8c340f1f155266a26a71c07bd55d3
export const STARTING_BLOCK = 100_000
export const LAUNCHPAD_ADDRESS = {
// SEPOLIA:"0x74acb6752abb734a7b3388567429217988e02409d9bf43c5586dc2c4f8baf40",
SEPOLIA:"0x29a532e6933a6d6f9939e59469d96b52b7c38561745331302e1a29f035e4dd0"
// SEPOLIA:"0x29a532e6933a6d6f9939e59469d96b52b7c38561745331302e1a29f035e4dd0",
SEPOLIA:"0x3798921000573bfc442d8153fc088db97bd3794f5ed19ea8c0846db5378f4af"
}
Loading

0 comments on commit 41c6e02

Please sign in to comment.