Skip to content

Commit 4332f0d

Browse files
update thirdweb SDK
1 parent b952e62 commit 4332f0d

File tree

11 files changed

+214
-285
lines changed

11 files changed

+214
-285
lines changed

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@
6464
"knex": "^3.1.0",
6565
"mnemonist": "^0.39.8",
6666
"node-cron": "^3.0.2",
67-
"ox": "^0.6.9",
67+
"ox": "0.6.9",
6868
"pg": "^8.11.3",
6969
"prisma": "^5.14.0",
7070
"prom-client": "^15.1.3",
7171
"superjson": "^2.2.1",
72-
"thirdweb": "^5.83.0",
72+
"thirdweb": "5.89.0",
7373
"undici": "^6.20.1",
7474
"uuid": "^9.0.1",
75-
"viem": "^2.21.54",
75+
"viem": "2.22.17",
7676
"winston": "^3.14.1",
7777
"zod": "^3.23.8"
7878
},
@@ -103,7 +103,9 @@
103103
"cookie": ">=0.7.0",
104104
"elliptic": ">=6.6.0",
105105
"micromatch": ">=4.0.8",
106+
"ox": "0.6.9",
106107
"secp256k1": ">=4.0.4",
108+
"viem": "2.22.17",
107109
"ws": ">=8.17.1",
108110
"cross-spawn": ">=7.0.6"
109111
},

src/abitype.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare module "abitype" {
2+
export interface Config {
3+
AddressType: string;
4+
}
5+
}

src/server/routes/contract/events/get-all-events.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
import { type Static, Type } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4+
import {
5+
type GetContractEventsResult,
6+
type PreparedEvent,
7+
getContract,
8+
getContractEvents,
9+
} from "thirdweb";
10+
import { getChain } from "../../../../shared/utils/chain";
11+
import { prettifyError } from "../../../../shared/utils/error";
12+
import { thirdwebClient } from "../../../../shared/utils/sdk";
13+
import { createCustomError } from "../../../middleware/error";
414
import {
515
contractEventSchema,
616
eventsQuerystringSchema,
717
} from "../../../schemas/contract";
18+
import { toContractEventV4Schema } from "../../../schemas/event";
819
import {
920
contractParamSchema,
1021
standardResponseSchema,
1122
} from "../../../schemas/shared-api-schemas";
12-
import { thirdwebClient } from "../../../../shared/utils/sdk";
13-
import { getChain } from "../../../../shared/utils/chain";
1423
import { getChainIdFromChain } from "../../../utils/chain";
15-
import { getContract, getContractEvents } from "thirdweb";
16-
import {
17-
type ContractEventV5,
18-
toContractEventV4Schema,
19-
} from "../../../schemas/event";
20-
import { createCustomError } from "../../../middleware/error";
21-
import { prettifyError } from "../../../../shared/utils/error";
2224

2325
const requestSchema = contractParamSchema;
2426

@@ -97,7 +99,7 @@ export async function getAllEvents(fastify: FastifyInstance) {
9799
chain: await getChain(chainId),
98100
});
99101

100-
let eventsV5: ContractEventV5[];
102+
let eventsV5: GetContractEventsResult<PreparedEvent<never>[], true>;
101103
try {
102104
eventsV5 = await getContractEvents({
103105
contract: contract,

src/server/routes/contract/read/read-batch.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Type, type Static } from "@sinclair/typebox";
1+
import { type Static, Type } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import SuperJSON from "superjson";
@@ -10,14 +10,14 @@ import {
1010
resolveMethod,
1111
} from "thirdweb";
1212
import { prepareMethod } from "thirdweb/contract";
13-
import { decodeAbiParameters } from "viem/utils";
1413
import type { AbiFunction } from "viem";
15-
import { createCustomError } from "../../../middleware/error";
16-
import { getChainIdFromChain } from "../../../utils/chain";
17-
import { standardResponseSchema } from "../../../schemas/shared-api-schemas";
14+
import { decodeAbiParameters } from "viem/utils";
1815
import { getChain } from "../../../../shared/utils/chain";
19-
import { thirdwebClient } from "../../../../shared/utils/sdk";
2016
import { prettifyError } from "../../../../shared/utils/error";
17+
import { thirdwebClient } from "../../../../shared/utils/sdk";
18+
import { createCustomError } from "../../../middleware/error";
19+
import { standardResponseSchema } from "../../../schemas/shared-api-schemas";
20+
import { getChainIdFromChain } from "../../../utils/chain";
2121

2222
const MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
2323

@@ -118,7 +118,7 @@ export async function readBatchRoute(fastify: FastifyInstance) {
118118
);
119119

120120
// Get Multicall3 contract
121-
const multicall = await getContract({
121+
const multicall = getContract({
122122
chain,
123123
address: multicallAddress,
124124
client: thirdwebClient,
@@ -132,7 +132,7 @@ export async function readBatchRoute(fastify: FastifyInstance) {
132132
});
133133

134134
// Process results
135-
const processedResults = results.map((result: unknown, i) => {
135+
const processedResults = results.map((result: unknown, i: number) => {
136136
const { success, returnData } = result as {
137137
success: boolean;
138138
returnData: unknown;

src/server/routes/contract/write/write.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Type, type Static } from "@sinclair/typebox";
1+
import { type Static, Type } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4+
import type { AbiParameters } from "ox";
45
import { prepareContractCall, resolveMethod } from "thirdweb";
5-
import { parseAbiParams, type AbiFunction } from "thirdweb/utils";
6+
import { type AbiFunction, parseAbiParams } from "thirdweb/utils";
67
import { getContractV5 } from "../../../../shared/utils/cache/get-contractv5";
78
import { prettifyError } from "../../../../shared/utils/error";
89
import { queueTransaction } from "../../../../shared/utils/transaction/queue-transation";
@@ -98,7 +99,7 @@ export async function writeToContract(fastify: FastifyInstance) {
9899
const functionNameOrSignature = sanitizeFunctionName(functionName);
99100
method = await resolveMethod(functionNameOrSignature)(contract);
100101
params = parseAbiParams(
101-
method.inputs.map((i) => i.type),
102+
method.inputs.map((i: AbiParameters.Parameter) => i.type),
102103
args,
103104
);
104105
} catch (e) {

src/server/routes/transaction/blockchain/get-logs.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { Type, type Static } from "@sinclair/typebox";
2-
import type { AbiEvent } from "abitype";
1+
import { type Static, Type } from "@sinclair/typebox";
32
import type { FastifyInstance } from "fastify";
43
import { StatusCodes } from "http-status-codes";
4+
import type { AbiEvent } from "ox";
55
import superjson from "superjson";
66
import {
7+
type Hex,
78
eth_getTransactionReceipt,
89
getContract,
910
getRpcClient,
1011
parseEventLogs,
1112
prepareEvent,
12-
type Hex,
1313
} from "thirdweb";
1414
import { resolveContractAbi } from "thirdweb/contract";
1515
import type { TransactionReceipt } from "thirdweb/transaction";
@@ -204,7 +204,7 @@ export async function getTransactionLogs(fastify: FastifyInstance) {
204204
client: thirdwebClient,
205205
});
206206

207-
const abi: AbiEvent[] = await resolveContractAbi(contract);
207+
const abi: AbiEvent.AbiEvent[] = await resolveContractAbi(contract);
208208
const eventSignatures = abi.filter((item) => item.type === "event");
209209
if (eventSignatures.length === 0) {
210210
throw createCustomError(

src/server/schemas/event.ts

+8-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { BigNumber } from "ethers";
2+
import type { AbiEvent } from "ox";
3+
import type { GetContractEventsResult, PreparedEvent } from "thirdweb";
24

35
export type ContractEventV4 = {
46
eventName: string;
@@ -18,32 +20,22 @@ export type ContractEventV4 = {
1820
};
1921
};
2022

21-
export type ContractEventV5 = {
22-
eventName: string;
23-
args: Record<string, unknown>;
24-
address: string;
25-
topic: string[];
26-
data: string;
27-
blockNumber: bigint;
28-
transactionHash: string;
29-
transactionIndex: number;
30-
blockHash: string;
31-
logIndex: number;
32-
removed: boolean;
33-
};
34-
3523
/**
3624
* Mapping of events v5 response to v4 for backward compatiblity.
3725
* Clients may be using this api and dont want to break things.
3826
*/
3927
export function toContractEventV4Schema(
40-
eventV5: ContractEventV5,
28+
eventV5: GetContractEventsResult<
29+
PreparedEvent<AbiEvent.AbiEvent>[],
30+
true
31+
>[number],
4132
): ContractEventV4 {
4233
const eventName = eventV5.eventName;
4334

4435
// backwards compatibility of BigInt(v5) to BigNumber(v4)
4536
const data: Record<string, unknown> = {};
4637
for (const key of Object.keys(eventV5.args)) {
38+
// @ts-expect-error - FIXME this is kinda hacky
4739
let value = eventV5.args[key];
4840
if (typeof value === "bigint") {
4941
value = BigNumber.from(value.toString());
@@ -61,7 +53,7 @@ export function toContractEventV4Schema(
6153
removed: eventV5.removed,
6254
address: eventV5.address,
6355
data: eventV5.data,
64-
topic: eventV5.topic,
56+
topic: eventV5.topics,
6557
transactionHash: eventV5.transactionHash,
6658
logIndex: eventV5.logIndex,
6759
event: eventV5.eventName,

src/worker/tasks/process-event-logs-worker.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Prisma, Webhooks } from "@prisma/client";
2-
import type { AbiEvent } from "abitype";
2+
import type { AbiEvent } from "ox";
33
import { Worker, type Job, type Processor } from "bullmq";
44
import superjson from "superjson";
55
import {
@@ -144,9 +144,9 @@ const getLogs = async ({
144144

145145
// Get events to filter by, if any.
146146
// Resolve the event name, "Transfer", to event signature, "Transfer(address to, uint256 quantity)".
147-
const events: PreparedEvent<AbiEvent>[] = [];
147+
const events: PreparedEvent<AbiEvent.AbiEvent>[] = [];
148148
if (f.events.length > 0) {
149-
const abi = await resolveContractAbi<AbiEvent[]>(contract);
149+
const abi = await resolveContractAbi<AbiEvent.AbiEvent[]>(contract);
150150
for (const signature of abi) {
151151
if (f.events.includes(signature.name)) {
152152
events.push(prepareEvent({ signature }));
@@ -224,7 +224,7 @@ const formatDecodedLog = async (args: {
224224
}): Promise<Record<string, Prisma.InputJsonObject> | undefined> => {
225225
const { contract, eventName, logArgs } = args;
226226

227-
const abi = await resolveContractAbi<AbiEvent[]>(contract);
227+
const abi = await resolveContractAbi<AbiEvent.AbiEvent[]>(contract);
228228
const eventSignature = abi.find((a) => a.name === eventName);
229229
if (!eventSignature) {
230230
return;

src/worker/tasks/process-transaction-receipts-worker.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import type { Prisma } from "@prisma/client";
2-
import type { AbiEvent } from "abitype";
3-
import { Worker, type Job, type Processor } from "bullmq";
2+
import { type Job, type Processor, Worker } from "bullmq";
3+
import type { AbiEvent } from "ox";
44
import superjson from "superjson";
55
import {
6+
type Address,
7+
type ThirdwebContract,
68
eth_getBlockByNumber,
79
eth_getTransactionReceipt,
810
getContract,
911
getRpcClient,
10-
type Address,
11-
type ThirdwebContract,
1212
} from "thirdweb";
1313
import { resolveContractAbi } from "thirdweb/contract";
14-
import { decodeFunctionData, type Abi, type Hash } from "viem";
14+
import { type Abi, type Hash, decodeFunctionData } from "viem";
1515
import { bulkInsertContractTransactionReceipts } from "../../shared/db/contract-transaction-receipts/create-contract-transaction-receipts";
1616
import { WebhooksEventTypes } from "../../shared/schemas/webhooks";
1717
import { getChain } from "../../shared/utils/chain";
@@ -20,8 +20,8 @@ import { normalizeAddress } from "../../shared/utils/primitive-types";
2020
import { redis } from "../../shared/utils/redis/redis";
2121
import { thirdwebClient } from "../../shared/utils/sdk";
2222
import {
23-
ProcessTransactionReceiptsQueue,
2423
type EnqueueProcessTransactionReceiptsData,
24+
ProcessTransactionReceiptsQueue,
2525
} from "../queues/process-transaction-receipts-queue";
2626
import { logWorkerExceptions } from "../queues/queues";
2727
import { SendWebhookQueue } from "../queues/send-webhook-queue";
@@ -211,7 +211,7 @@ const getFunctionName = async (args: {
211211
contract: ThirdwebContract;
212212
data: Hash;
213213
}) => {
214-
const abi = await resolveContractAbi<AbiEvent[]>(args.contract);
214+
const abi = await resolveContractAbi<AbiEvent.AbiEvent[]>(args.contract);
215215
const decoded = decodeFunctionData<Abi>({
216216
abi,
217217
data: args.data,

src/worker/tasks/send-transaction-worker.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { Worker, type Job, type Processor } from "bullmq";
21
import assert from "node:assert";
2+
import { type Job, type Processor, Worker } from "bullmq";
33
import superjson from "superjson";
44
import {
5+
type Hex,
56
getAddress,
67
getContract,
78
readContract,
89
toSerializableTransaction,
910
toTokens,
10-
type Hex,
1111
} from "thirdweb";
1212
import { getChainMetadata } from "thirdweb/chains";
1313
import { isZkSyncChain, stringify } from "thirdweb/utils";
1414
import type { Account } from "thirdweb/wallets";
1515
import {
16+
type UserOperation,
1617
bundleUserOp,
1718
createAndSignUserOp,
1819
smartWallet,
19-
type UserOperation,
2020
} from "thirdweb/wallets/smart";
2121
import { getContractAddress } from "viem";
2222
import { TransactionDB } from "../../shared/db/transactions/db";
@@ -56,8 +56,8 @@ import { reportUsage } from "../../shared/utils/usage";
5656
import { MineTransactionQueue } from "../queues/mine-transaction-queue";
5757
import { logWorkerExceptions } from "../queues/queues";
5858
import {
59-
SendTransactionQueue,
6059
type SendTransactionData,
60+
SendTransactionQueue,
6161
} from "../queues/send-transaction-queue";
6262

6363
/**

0 commit comments

Comments
 (0)