Skip to content

Commit 3aebcea

Browse files
amish kohliamish kohli
authored andcommitted
ecs ci/cd
1 parent 320b0cc commit 3aebcea

File tree

3 files changed

+53
-24
lines changed

3 files changed

+53
-24
lines changed

.github/workflows/aws.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Deploy to Amazon ECS
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches: [ "main", "feat/indexer" ]
66

77
env:
88
AWS_REGION: us-east-1
@@ -51,9 +51,11 @@ jobs:
5151
# push it to ECR so that it can
5252
# be deployed to ECS.
5353
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 058264122535.dkr.ecr.us-east-1.amazonaws.com
54-
docker build -t ponder/indexer .
55-
docker tag ponder/indexer:latest 058264122535.dkr.ecr.us-east-1.amazonaws.com/ponder/indexer:latest
56-
docker push 058264122535.dkr.ecr.us-east-1.amazonaws.com/ponder/indexer:latest
54+
docker buildx build \
55+
--platform linux/amd64 \
56+
--push \
57+
-t 058264122535.dkr.ecr.us-east-1.amazonaws.com/ponder/indexer:latest \
58+
.
5759
5860
- name: Fill in the new image ID in the Amazon ECS task definition
5961
id: task-def

Dockerfile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
# Use a more compatible image for cross-platform support
2-
FROM node:18-bullseye-slim
1+
FROM node:18.17.1
32

4-
# Set the working directory
53
WORKDIR /app
64

7-
# Copy package.json and package-lock.json
5+
# Copy package files
86
COPY package*.json ./
97

108
# Install dependencies
@@ -13,11 +11,14 @@ RUN npm install
1311
# Copy the rest of the application code
1412
COPY . .
1513

16-
# Expose the port the app runs on
17-
18-
1914
# Expose ports
20-
EXPOSE 3000
15+
EXPOSE 3000 3001 42069
16+
17+
# Run the application with necessary flags
18+
CMD ["node", \
19+
"--experimental-fetch", \
20+
"--loader", "ts-node/esm", \
21+
"--no-warnings", \
22+
"node_modules/.bin/ponder", \
23+
"dev"]
2124

22-
# Run the application
23-
CMD ["npm", "run", "ponder"]

src/api/server.ts

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,54 @@ const supabase = createClient(supabaseUrl, supabaseKey);
1515

1616
app.use(express.json());
1717

18-
// Example endpoint to fetch rewards for a specific user with total rewards
19-
app.get('/api/rewards/:user', async (req, res) => {
18+
// Updated endpoint to include chain parameter
19+
app.get('/api/rewards/:chain/:user', async (req : any , res : any) => {
2020
try {
21-
const { user } = req.params;
21+
const { chain, user } = req.params;
22+
const validChains = ['mode', 'base']; // Add supported chains here
23+
24+
// Hardcoded ionTokenAddress for each chain
25+
const ionTokenAddresses: { [key: string]: string } = {
26+
mode: '0x18470019bF0E94611f15852F7e93cf5D65BC34CA', // Replace with actual address
27+
base: '0x3eE5e23eEE121094f1cFc0Ccc79d6C809Ebd22e5', // Replace with actual address
28+
};
29+
30+
// Validate chain parameter
31+
if (!validChains.includes(chain.toLowerCase())) {
32+
return res.status(400).json({ error: 'Invalid chain. Supported chains are: ' + validChains.join(', ') });
33+
}
34+
2235
const { data, error } = await supabase
2336
.from('accrue_rewards_events')
2437
.select('*')
2538
.eq('user', user.toLowerCase())
39+
.eq('chain', chain.toLowerCase()) // Add chain filter
2640
.order('timestamp', { ascending: false });
2741

2842
if (error) throw error;
2943

30-
// Sum up the amount in each reward event
31-
const totalAmount = data.reduce((acc: bigint, event: any) => {
32-
const amount = BigInt(event.allEventArgs.amount); // Convert amount to BigInt
33-
return acc + amount; // Add the amount to the accumulator
34-
}, BigInt(0)); // Start with 0 as the initial value for the accumulator
44+
// Create a Map to track unique events using transactionHash as the key
45+
const uniqueEvents = new Map();
46+
data.forEach((event: any) => {
47+
const eventKey = event.transactionHash; // Or use: `${event.blockNumber}-${event.logIndex}`
48+
if (!uniqueEvents.has(eventKey)) {
49+
uniqueEvents.set(eventKey, event);
50+
}
51+
});
52+
53+
// Sum up the amount only for unique events
54+
const totalAmount = Array.from(uniqueEvents.values()).reduce((acc: bigint, event: any) => {
55+
const amount = BigInt(event.allEventArgs.amount);
56+
return acc + amount;
57+
}, BigInt(0));
3558

3659
res.json({
60+
chain: chain.toLowerCase(),
3761
user: user.toLowerCase(),
38-
totalRewards: totalAmount.toString(), // Convert BigInt to string to avoid precision issues in JSON
39-
events: data, // Return the original events data as well
62+
totalRewards: totalAmount.toString(),
63+
ionTokenAddress: ionTokenAddresses[chain.toLowerCase()], // Include ionTokenAddress in response
64+
// uniqueEventsCount: uniqueEvents.size,
65+
// totalEventsCount: data.length,
4066
});
4167
} catch (error) {
4268
console.error('Error fetching user rewards:', error);

0 commit comments

Comments
 (0)