Skip to content

Commit bdf0989

Browse files
Merge pull request #8 from InternetMaximalism/shared-improved
Shared improved
2 parents b72c1b3 + 3c0c1d4 commit bdf0989

39 files changed

+256
-1633
lines changed

.env.example

+3
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@ WITHDRAWAL_GROUP_SIZE=5
3131
WITHDRAWAL_MIN_BATCH_SIZE=5
3232
WITHDRAWAL_MIN_WAIT_MINUTES=5
3333

34+
# scroll
35+
SCROLL_GAS_MULTIPLIER=2
36+
3437
# seed
3538
PROOF_URL=

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# intmax2-aggregator
1+
# intmax2-withdrawal-aggregator
22

3-
The aggregator is responsible for consolidating withdrawals and managing requests to the ZKP (Zero-Knowledge Proof).
3+
The withdrawal aggregator is responsible for consolidating withdrawals and managing requests to the ZKP (Zero-Knowledge Proof).
44

55
## Development
66

docker-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
postgres:
33
image: postgres:15.10
4-
container_name: intmax2-aggregator-postgres
4+
container_name: intmax2-withdrawal-aggregator-postgres
55
hostname: postgres
66
restart: unless-stopped
77
environment:
@@ -15,7 +15,7 @@ services:
1515

1616
redis:
1717
image: redis:7.4.2
18-
container_name: intmax2-aggregator-redis
18+
container_name: intmax2-withdrawal-aggregator-redis
1919
hostname: redis
2020
restart: unless-stopped
2121
ports:

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"name": "intmax2-aggregator",
2+
"name": "intmax2-withdrawal-aggregator",
33
"version": "1.2.7",
44
"workspaces": [
55
"packages/*"
66
],
77
"scripts": {
88
"build": "yarn workspaces foreach --all --topological run build",
9-
"build:shared": "yarn workspace @intmax2-aggregator/shared run build",
9+
"build:shared": "yarn workspace @intmax2-withdrawal-aggregator/shared run build",
1010
"build:parallel": "yarn workspaces foreach --all -pt run build",
1111
"lint": "biome lint .",
1212
"format": "biome check --write --unsafe .",
@@ -20,13 +20,13 @@
2020
},
2121
"devDependencies": {
2222
"@biomejs/biome": "1.9.4",
23-
"@types/node": "^22.10.7",
23+
"@types/node": "^22.13.1",
2424
"tsx": "^4.19.2",
2525
"typescript": "^5.7.3"
2626
},
2727
"dependencies": {
28-
"@prisma/client": "6.2.1",
29-
"prisma": "^6.2.1"
28+
"@prisma/client": "6.3.0",
29+
"prisma": "^6.3.0"
3030
},
3131
"prisma": {
3232
"seed": "tsx --env-file=./.env prisma/seed.ts"

packages/collector/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "collector",
33
"version": "1.0.0",
44
"dependencies": {
5-
"@intmax2-aggregator/shared": "workspace:*",
5+
"@intmax2-withdrawal-aggregator/shared": "workspace:*",
66
"date-fns": "^4.1.0"
77
},
88
"scripts": {

packages/collector/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cleanup, logger, timeOperation } from "@intmax2-aggregator/shared";
1+
import { cleanup, logger, timeOperation } from "@intmax2-withdrawal-aggregator/shared";
22
import { name } from "../package.json";
33
import { performJob } from "./service/job.service";
44

packages/collector/src/service/job.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type RequestingWithdrawal, config, logger } from "@intmax2-aggregator/shared";
1+
import { type RequestingWithdrawal, config, logger } from "@intmax2-withdrawal-aggregator/shared";
22
import { differenceInMinutes } from "date-fns";
33
import { chunkArray } from "../lib/utils";
44
import { createWithdrawalGroup, fetchRequestingWithdrawals } from "./withdrawal.service";

packages/collector/src/service/withdrawal.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
logger,
88
withdrawalManager,
99
withdrawalPrisma,
10-
} from "@intmax2-aggregator/shared";
10+
} from "@intmax2-withdrawal-aggregator/shared";
1111

1212
export const fetchRequestingWithdrawals = async () => {
1313
const processedUUIDs = await withdrawalManager.getAllProcessedUUIDs();
@@ -32,8 +32,8 @@ export const fetchRequestingWithdrawals = async () => {
3232
};
3333

3434
export const createWithdrawalGroup = async (group: RequestingWithdrawal[]) => {
35-
const now = new Date();
3635
const queueManager = QueueManager.getInstance("withdrawal-aggregator");
36+
const now = new Date();
3737

3838
const groupId = await withdrawalManager.addGroup({
3939
requestingWithdrawals: group.map((withdrawal) => ({

packages/processor/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "processor",
33
"version": "1.0.0",
44
"dependencies": {
5-
"@intmax2-aggregator/shared": "workspace:*",
5+
"@intmax2-withdrawal-aggregator/shared": "workspace:*",
66
"axios": "^1.7.9",
77
"ethers": "^6.13.5"
88
},

packages/processor/src/constants.ts

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export const DEFAULT_POLL_OPTIONS: Required<PollOptions> = {
1111
};
1212

1313
// transaction
14-
export const REPLACED_TX_WAIT_TIMEOUT = 15_000;
1514
export const WAIT_TRANSACTION_TIMEOUT = 15_000;
1615
export const TRANSACTION_MAX_RETRIES = 5;
1716

packages/processor/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QueueManager, cleanup, logger } from "@intmax2-aggregator/shared";
1+
import { QueueManager, cleanup, logger } from "@intmax2-withdrawal-aggregator/shared";
22
import { name } from "../package.json";
33
import { startHealthCheckServer } from "./lib/healthCheck";
44
import { shutdown } from "./lib/shutdown";

packages/processor/src/lib/healthCheck.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import http from "http";
2-
import { config, logger } from "@intmax2-aggregator/shared";
2+
import { config, logger } from "@intmax2-withdrawal-aggregator/shared";
33
import { name } from "../../package.json";
44

55
const server = http.createServer((req, res) => {

packages/processor/src/lib/shutdown.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cleanup, logger } from "@intmax2-aggregator/shared";
1+
import { cleanup, logger } from "@intmax2-withdrawal-aggregator/shared";
22

33
let isShuttingDown = false;
44

packages/processor/src/lib/zkp.ts

+14-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { config } from "@intmax2-aggregator/shared";
1+
import { config } from "@intmax2-withdrawal-aggregator/shared";
22
import axios, { type AxiosError, type AxiosRequestConfig } from "axios";
33
import type {
44
CreateGnarkProofResponse,
@@ -41,6 +41,16 @@ export const createWrappedProof = async (
4141
});
4242
};
4343

44+
export const createGnarkProof = async (wrappedProof: string) => {
45+
return makeProverRequest<CreateGnarkProofResponse>({
46+
method: "post",
47+
path: "gnark-server/start-proof",
48+
data: {
49+
proof: wrappedProof,
50+
},
51+
});
52+
};
53+
4454
export const getWithdrawalProof = async (proofId: string) => {
4555
return makeProverRequest<GetZKProofResponse<WithdrawalProof>>({
4656
method: "get",
@@ -55,16 +65,6 @@ export const getWithdrawalWrapperProof = async (proofId: string) => {
5565
});
5666
};
5767

58-
export const createGnarkProof = async (wrappedProof: string) => {
59-
return makeProverRequest<CreateGnarkProofResponse>({
60-
method: "post",
61-
path: "gnark-server/start-proof",
62-
data: {
63-
proof: wrappedProof,
64-
},
65-
});
66-
};
67-
6868
export const getGnarkProof = async (jobId: string) => {
6969
return makeProverRequest<GetZKProofResponse<GnarkProof>>({
7070
method: "get",
@@ -80,7 +80,9 @@ const makeProverRequest = async <T>({ method, path, data, params }: ProverReques
8080
const requestConfig: AxiosRequestConfig = {
8181
method,
8282
url: `${config.ZKP_PROVER_URL}/v1/beta/${path}`,
83-
...getHeaders(),
83+
headers: {
84+
contentType: "application/json",
85+
},
8486
};
8587

8688
if (params) {
@@ -108,12 +110,6 @@ const makeProverRequest = async <T>({ method, path, data, params }: ProverReques
108110
}
109111
};
110112

111-
const getHeaders = () => ({
112-
headers: {
113-
contentType: "application/json",
114-
},
115-
});
116-
117113
const handleAxiosError = (error: unknown) => {
118114
if (axios.isAxiosError(error)) {
119115
const axiosError = error as AxiosError;

packages/processor/src/service/job.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import {
66
timeOperation,
77
withdrawalManager,
88
withdrawalPrisma,
9-
} from "@intmax2-aggregator/shared";
9+
} from "@intmax2-withdrawal-aggregator/shared";
1010
import { EXECUTION_REVERTED_ERROR_MESSAGE } from "../constants";
1111
import { processWithdrawalGroup } from "./withdrawal.service";
1212

1313
export const processQueueJob = async (jobData: QueueJobData) => {
1414
return await timeOperation(async () => await performJob(jobData));
1515
};
1616

17-
export const performJob = async (data: QueueJobData): Promise<void> => {
17+
const performJob = async (data: QueueJobData): Promise<void> => {
1818
const { groupId } = data.payload;
1919

2020
try {

packages/processor/src/service/proof.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
getRandomString,
44
getWalletClient,
55
logger,
6-
} from "@intmax2-aggregator/shared";
6+
} from "@intmax2-withdrawal-aggregator/shared";
77
import { DEFAULT_ID_LENGTH } from "../constants";
88
import { pollGnarkProof, pollWithdrawalProof, pollWithdrawalWrapperProof } from "../lib/poll";
99
import { createGnarkProof, createWithdrawalProof, createWrappedProof } from "../lib/zkp";
@@ -43,8 +43,8 @@ export const generateWithdrawalProofs = async (withdrawals: WithdrawalWithProof[
4343
};
4444

4545
export const generateWrappedProof = async (
46-
walletClientData: ReturnType<typeof getWalletClient>,
4746
withdrawalProofs: WithdrawalProof[],
47+
walletClientData: ReturnType<typeof getWalletClient>,
4848
) => {
4949
if (withdrawalProofs.length === 0) {
5050
throw new Error("No withdrawal proofs available to generate Wrapped proof");

packages/processor/src/service/submit.service.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
calculateEthersIncreasedGasPrice,
88
calculateGasMultiplier,
99
config,
10+
createNetworkClient,
1011
ethersWaitForTransactionConfirmation,
1112
executeEthersTransaction,
1213
getEthersMaxGasMultiplier,
@@ -15,7 +16,7 @@ import {
1516
getWalletClient,
1617
logger,
1718
replacedEthersTransaction,
18-
} from "@intmax2-aggregator/shared";
19+
} from "@intmax2-withdrawal-aggregator/shared";
1920
import { ethers } from "ethers";
2021
import { type Abi, type PublicClient, toHex } from "viem";
2122
import {
@@ -29,10 +30,11 @@ import {
2930
import type { SubmitWithdrawalParams } from "../types";
3031

3132
export const submitWithdrawalProof = async (
32-
ethereumClient: PublicClient,
33+
params: SubmitWithdrawalParams,
3334
walletClientData: ReturnType<typeof getWalletClient>,
34-
parmas: SubmitWithdrawalParams,
3535
) => {
36+
const ethereumClient = createNetworkClient("scroll");
37+
3638
const retryOptions: RetryOptionsEthers = {
3739
gasPrice: null,
3840
};
@@ -44,7 +46,7 @@ export const submitWithdrawalProof = async (
4446
const { transactionHash } = await submitWithdrawalProofWithRetry(
4547
ethereumClient,
4648
walletClientData,
47-
parmas,
49+
params,
4850
multiplier,
4951
retryOptions,
5052
);

packages/processor/src/service/withdrawal.service.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import {
22
type RequestingWithdrawal,
33
WithdrawalStatus,
4-
createNetworkClient,
54
getWalletClient,
65
logger,
76
withdrawalPrisma,
8-
} from "@intmax2-aggregator/shared";
7+
} from "@intmax2-withdrawal-aggregator/shared";
98
import { formatContractWithdrawal, getLastWithdrawalHashFromWithdrawalProofs } from "../lib/utils";
109
import type { GnarkProof, WithdrawalProof, WithdrawalWithProof } from "../types";
1110
import {
@@ -16,14 +15,14 @@ import {
1615
import { submitWithdrawalProof } from "./submit.service";
1716

1817
export const processWithdrawalGroup = async (requestingWithdrawals: RequestingWithdrawal[]) => {
19-
const withdrawals = await fetchWithdrawalsWithProofs(requestingWithdrawals);
2018
const walletClientData = getWalletClient("withdrawal", "scroll");
2119

20+
const withdrawals = await fetchWithdrawalsWithProofs(requestingWithdrawals);
2221
const withdrawalProofs = await generateWithdrawalProofs(withdrawals);
23-
const wrappedProof = await generateWrappedProof(walletClientData, withdrawalProofs);
22+
const wrappedProof = await generateWrappedProof(withdrawalProofs, walletClientData);
2423
const gnarkProof = await generateGnarkProof(wrappedProof);
2524

26-
await submitWithdrawalProofToScroll(walletClientData, withdrawalProofs, gnarkProof);
25+
await submitWithdrawalProofToScroll(withdrawalProofs, gnarkProof, walletClientData);
2726
};
2827

2928
const fetchWithdrawalsWithProofs = async (requestingWithdrawals: RequestingWithdrawal[]) => {
@@ -52,10 +51,10 @@ const fetchWithdrawalsWithProofs = async (requestingWithdrawals: RequestingWithd
5251
return withdrawals as unknown as WithdrawalWithProof[];
5352
};
5453

55-
export const submitWithdrawalProofToScroll = async (
56-
walletClientData: ReturnType<typeof getWalletClient>,
54+
const submitWithdrawalProofToScroll = async (
5755
withdrawalProofs: WithdrawalProof[],
5856
gnarkProof: GnarkProof,
57+
walletClientData: ReturnType<typeof getWalletClient>,
5958
) => {
6059
const lastWithdrawalHash = getLastWithdrawalHashFromWithdrawalProofs(withdrawalProofs);
6160
const withdrawalAggregator = walletClientData.account.address;
@@ -69,6 +68,5 @@ export const submitWithdrawalProofToScroll = async (
6968
proof: `0x${gnarkProof.proof}`,
7069
};
7170

72-
const ethereumClient = createNetworkClient("scroll");
73-
await submitWithdrawalProof(ethereumClient, walletClientData, params);
71+
await submitWithdrawalProof(params, walletClientData);
7472
};

packages/shared/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# @intmax2-aggregator/shared
1+
# @intmax2-withdrawal-aggregator/shared
22

3-
@intmax2-aggregator/shared is a shared library designed to provide common functionalities and utilities for projects within the INTMAX2 ecosystem.
3+
@intmax2-withdrawal-aggregator/shared is a shared library designed to provide common functionalities and utilities for projects within the INTMAX2 ecosystem.
44

55
## Usage
66

packages/shared/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@intmax2-aggregator/shared",
2+
"name": "@intmax2-withdrawal-aggregator/shared",
33
"version": "1.0.0",
44
"main": "dist/index.js",
55
"dependencies": {
@@ -9,7 +9,7 @@
99
"ethers": "^6.13.5",
1010
"pino": "^9.6.0",
1111
"pino-pretty": "^13.0.0",
12-
"viem": "^2.22.11"
12+
"viem": "^2.22.21"
1313
},
1414
"scripts": {
1515
"build": "rm -rf dist tsconfig.tsbuildinfo && tsc",

0 commit comments

Comments
 (0)