Skip to content

Commit c0d83fc

Browse files
committed
add header to all v5 endpoints + fix SDK upgrade type incompatibilities
1 parent 534435f commit c0d83fc

28 files changed

+134
-28
lines changed

src/server/routes/backend-wallet/send-transaction-batch.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ export async function sendTransactionBatch(fastify: FastifyInstance) {
5656
},
5757
handler: async (request, reply) => {
5858
const { chain } = request.params;
59-
const { "x-backend-wallet-address": fromAddress } =
60-
request.headers as Static<typeof walletHeaderSchema>;
59+
const {
60+
"x-backend-wallet-address": fromAddress,
61+
"x-transaction-mode": transactionMode,
62+
} = request.headers as Static<typeof walletHeaderSchema>;
6163
const chainId = await getChainIdFromChain(chain);
6264

6365
const transactionRequests = request.body;
@@ -70,6 +72,7 @@ export async function sendTransactionBatch(fastify: FastifyInstance) {
7072
insertedTransaction: {
7173
isUserOp: false,
7274
chainId,
75+
transactionMode,
7376
from: fromAddress as Address,
7477
to: toAddress as Address | undefined,
7578
data: data as Hex,

src/server/routes/backend-wallet/send-transaction.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export async function sendTransaction(fastify: FastifyInstance) {
7272
"x-idempotency-key": idempotencyKey,
7373
"x-account-address": accountAddress,
7474
"x-account-factory-address": accountFactoryAddress,
75+
"x-transaction-mode": transactionMode,
7576
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
7677

7778
const chainId = await getChainIdFromChain(chain);
@@ -89,6 +90,7 @@ export async function sendTransaction(fastify: FastifyInstance) {
8990
accountAddress: accountAddress as Address,
9091
signerAddress: fromAddress as Address,
9192
target: toAddress as Address | undefined,
93+
transactionMode: undefined,
9294
accountFactoryAddress: maybeAddress(
9395
accountFactoryAddress,
9496
"x-account-factory-address",
@@ -106,6 +108,7 @@ export async function sendTransaction(fastify: FastifyInstance) {
106108
from: fromAddress as Address,
107109
to: toAddress as Address | undefined,
108110
data: data as Hex,
111+
transactionMode: transactionMode,
109112
value: BigInt(value),
110113
...parseTransactionOverrides(txOverrides),
111114
},

src/server/routes/backend-wallet/sign-transaction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { Type, type Static } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4-
import type { Hex } from "thirdweb";
5-
import type { TransactionSerializable } from "viem";
64
import { getAccount } from "../../../shared/utils/account";
75
import {
86
getChecksumAddress,
@@ -13,6 +11,7 @@ import { toTransactionType } from "../../../shared/utils/sdk";
1311
import { createCustomError } from "../../middleware/error";
1412
import { standardResponseSchema } from "../../schemas/shared-api-schemas";
1513
import { walletHeaderSchema } from "../../schemas/wallet";
14+
import type { Hex } from "thirdweb";
1615

1716
const requestBodySchema = Type.Object({
1817
transaction: Type.Object({
@@ -86,7 +85,8 @@ export async function signTransaction(fastify: FastifyInstance) {
8685
maxFeePerGas: maybeBigInt(transaction.maxFeePerGas),
8786
maxPriorityFeePerGas: maybeBigInt(transaction.maxPriorityFeePerGas),
8887
ccipReadEnabled: transaction.ccipReadEnabled,
89-
} as TransactionSerializable;
88+
};
89+
9090
const signature = await account.signTransaction(serializableTransaction);
9191

9292
reply.status(StatusCodes.OK).send({

src/server/routes/backend-wallet/simulate-transaction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export async function simulateTransaction(fastify: FastifyInstance) {
8282
const {
8383
"x-backend-wallet-address": walletAddress,
8484
"x-account-address": accountAddress,
85+
"x-transaction-mode": transactionMode,
8586
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
8687

8788
const chainId = await getChainIdFromChain(chain);
@@ -99,6 +100,7 @@ export async function simulateTransaction(fastify: FastifyInstance) {
99100
functionArgs: args,
100101
data: data as Hex | undefined,
101102
value: value ? BigInt(value) : 0n,
103+
transactionMode: transactionMode,
102104

103105
...(accountAddress
104106
? {

src/server/routes/backend-wallet/transfer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export async function transfer(fastify: FastifyInstance) {
8888
const {
8989
"x-backend-wallet-address": walletAddress,
9090
"x-idempotency-key": idempotencyKey,
91+
"x-transaction-mode": transactionMode,
9192
} = request.headers as Static<typeof walletHeaderSchema>;
9293
const { simulateTx: shouldSimulate } = request.query;
9394

@@ -109,6 +110,7 @@ export async function transfer(fastify: FastifyInstance) {
109110
value: toWei(amount),
110111
extension: "none",
111112
functionName: "transfer",
113+
transactionMode,
112114
...parseTransactionOverrides(txOverrides),
113115
};
114116
} else {
@@ -143,6 +145,7 @@ export async function transfer(fastify: FastifyInstance) {
143145
extension: "erc20",
144146
functionName: "transfer",
145147
functionArgs: [to, amount, currencyAddress],
148+
transactionMode,
146149
...parseTransactionOverrides(txOverrides),
147150
};
148151
}

src/server/routes/contract/extensions/account-factory/write/create-account.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export const createAccount = async (fastify: FastifyInstance) => {
7474
"x-account-factory-address": accountFactoryAddress,
7575
"x-account-salt": accountSalt,
7676
"x-idempotency-key": idempotencyKey,
77+
"x-transaction-mode": transactionMode,
7778
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
7879
const chainId = await getChainIdFromChain(chain);
7980

@@ -116,6 +117,7 @@ export const createAccount = async (fastify: FastifyInstance) => {
116117
txOverrides,
117118
idempotencyKey,
118119
shouldSimulate: simulateTx,
120+
transactionMode,
119121
});
120122

121123
// Note: This is a temporary solution to cache the deployed address's factory for 7 days.

src/server/routes/contract/extensions/erc1155/write/claim-to.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export async function erc1155claimTo(fastify: FastifyInstance) {
8383
"x-idempotency-key": idempotencyKey,
8484
"x-account-factory-address": accountFactoryAddress,
8585
"x-account-salt": accountSalt,
86+
"x-transaction-mode": transactionMode,
8687
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
8788

8889
const chainId = await getChainIdFromChain(chain);
@@ -113,6 +114,7 @@ export async function erc1155claimTo(fastify: FastifyInstance) {
113114
txOverrides,
114115
idempotencyKey,
115116
shouldSimulate: simulateTx,
117+
transactionMode,
116118
});
117119

118120
reply.status(StatusCodes.OK).send({

src/server/routes/contract/extensions/erc1155/write/mint-to.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export async function erc1155mintTo(fastify: FastifyInstance) {
8282
"x-idempotency-key": idempotencyKey,
8383
"x-account-factory-address": accountFactoryAddress,
8484
"x-account-salt": accountSalt,
85+
"x-transaction-mode": transactionMode,
8586
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
8687

8788
const chainId = await getChainIdFromChain(_chain);
@@ -129,6 +130,7 @@ export async function erc1155mintTo(fastify: FastifyInstance) {
129130
extension: "erc1155",
130131
functionName: "mintTo",
131132
shouldSimulate: simulateTx,
133+
transactionMode,
132134
});
133135

134136
reply.status(StatusCodes.OK).send({

src/server/routes/contract/extensions/erc1155/write/transfer-from.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export async function erc1155transferFrom(fastify: FastifyInstance) {
8787
"x-idempotency-key": idempotencyKey,
8888
"x-account-factory-address": accountFactoryAddress,
8989
"x-account-salt": accountSalt,
90+
"x-transaction-mode": transactionMode,
9091
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
9192

9293
const chainId = await getChainIdFromChain(chain);
@@ -117,6 +118,7 @@ export async function erc1155transferFrom(fastify: FastifyInstance) {
117118
shouldSimulate: simulateTx,
118119
functionName: "safeTransferFrom",
119120
extension: "erc1155",
121+
transactionMode,
120122
});
121123

122124
reply.status(StatusCodes.OK).send({

src/server/routes/contract/extensions/erc1155/write/transfer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export async function erc1155transfer(fastify: FastifyInstance) {
7979
"x-idempotency-key": idempotencyKey,
8080
"x-account-factory-address": accountFactoryAddress,
8181
"x-account-salt": accountSalt,
82+
"x-transaction-mode": transactionMode,
8283
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
8384

8485
const chainId = await getChainIdFromChain(chain);
@@ -109,6 +110,7 @@ export async function erc1155transfer(fastify: FastifyInstance) {
109110
shouldSimulate: simulateTx,
110111
functionName: "safeTransferFrom",
111112
extension: "erc1155",
113+
transactionMode,
112114
});
113115

114116
reply.status(StatusCodes.OK).send({

src/server/routes/contract/extensions/erc20/write/claim-to.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export async function erc20claimTo(fastify: FastifyInstance) {
7777
"x-idempotency-key": idempotencyKey,
7878
"x-account-factory-address": accountFactoryAddress,
7979
"x-account-salt": accountSalt,
80+
"x-transaction-mode": transactionMode,
8081
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
8182

8283
const chainId = await getChainIdFromChain(chain);
@@ -105,6 +106,7 @@ export async function erc20claimTo(fastify: FastifyInstance) {
105106
txOverrides,
106107
idempotencyKey,
107108
shouldSimulate: simulateTx,
109+
transactionMode,
108110
});
109111

110112
reply.status(StatusCodes.OK).send({

src/server/routes/contract/extensions/erc20/write/mint-to.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export async function erc20mintTo(fastify: FastifyInstance) {
7575
"x-idempotency-key": idempotencyKey,
7676
"x-account-factory-address": accountFactoryAddress,
7777
"x-account-salt": accountSalt,
78+
"x-transaction-mode": transactionMode,
7879
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
7980

8081
const chainId = await getChainIdFromChain(_chain);
@@ -106,6 +107,7 @@ export async function erc20mintTo(fastify: FastifyInstance) {
106107
extension: "erc20",
107108
functionName: "mintTo",
108109
shouldSimulate: simulateTx,
110+
transactionMode,
109111
});
110112

111113
reply.status(StatusCodes.OK).send({

src/server/routes/contract/extensions/erc20/write/transfer-from.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export async function erc20TransferFrom(fastify: FastifyInstance) {
8181
"x-idempotency-key": idempotencyKey,
8282
"x-account-factory-address": accountFactoryAddress,
8383
"x-account-salt": accountSalt,
84+
"x-transaction-mode": transactionMode,
8485
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
8586

8687
const chainId = await getChainIdFromChain(chain);
@@ -109,6 +110,7 @@ export async function erc20TransferFrom(fastify: FastifyInstance) {
109110
shouldSimulate: simulateTx,
110111
functionName: "transferFrom",
111112
extension: "erc20",
113+
transactionMode,
112114
});
113115

114116
reply.status(StatusCodes.OK).send({

src/server/routes/contract/extensions/erc20/write/transfer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export async function erc20Transfer(fastify: FastifyInstance) {
7474
"x-idempotency-key": idempotencyKey,
7575
"x-account-factory-address": accountFactoryAddress,
7676
"x-account-salt": accountSalt,
77+
"x-transaction-mode": transactionMode,
7778
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
7879

7980
const chainId = await getChainIdFromChain(chain);
@@ -101,6 +102,7 @@ export async function erc20Transfer(fastify: FastifyInstance) {
101102
shouldSimulate: simulateTx,
102103
functionName: "transfer",
103104
extension: "erc20",
105+
transactionMode,
104106
});
105107

106108
reply.status(StatusCodes.OK).send({

src/server/routes/contract/extensions/erc721/write/claim-to.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export async function erc721claimTo(fastify: FastifyInstance) {
7878
"x-idempotency-key": idempotencyKey,
7979
"x-account-factory-address": accountFactoryAddress,
8080
"x-account-salt": accountSalt,
81+
"x-transaction-mode": transactionMode,
8182
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
8283

8384
const chainId = await getChainIdFromChain(chain);
@@ -106,6 +107,7 @@ export async function erc721claimTo(fastify: FastifyInstance) {
106107
txOverrides,
107108
idempotencyKey,
108109
shouldSimulate: simulateTx,
110+
transactionMode,
109111
});
110112

111113
reply.status(StatusCodes.OK).send({

src/server/routes/contract/extensions/erc721/write/mint-to.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export async function erc721mintTo(fastify: FastifyInstance) {
7878
"x-idempotency-key": idempotencyKey,
7979
"x-account-factory-address": accountFactoryAddress,
8080
"x-account-salt": accountSalt,
81+
"x-transaction-mode": transactionMode,
8182
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
8283

8384
const chainId = await getChainIdFromChain(_chain);
@@ -123,6 +124,7 @@ export async function erc721mintTo(fastify: FastifyInstance) {
123124
extension: "erc721",
124125
functionName: "mintTo",
125126
shouldSimulate: simulateTx,
127+
transactionMode,
126128
});
127129

128130
reply.status(StatusCodes.OK).send({

src/server/routes/contract/extensions/erc721/write/signature-mint.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export async function erc721SignatureMint(fastify: FastifyInstance) {
8787
"x-backend-wallet-address": fromAddress,
8888
"x-account-address": accountAddress,
8989
"x-idempotency-key": idempotencyKey,
90+
"x-transaction-mode": transactionMode,
9091
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
9192
const { "x-thirdweb-sdk-version": sdkVersion } =
9293
request.headers as Static<typeof thirdwebSdkVersionSchema>;
@@ -133,6 +134,7 @@ export async function erc721SignatureMint(fastify: FastifyInstance) {
133134
accountAddress: accountAddress as Address,
134135
signerAddress: fromAddress as Address,
135136
target: contractAddress as Address | undefined,
137+
transactionMode: undefined,
136138
},
137139
shouldSimulate: simulateTx,
138140
idempotencyKey,
@@ -142,6 +144,7 @@ export async function erc721SignatureMint(fastify: FastifyInstance) {
142144
insertedTransaction: {
143145
...insertedTransaction,
144146
isUserOp: false,
147+
transactionMode,
145148
},
146149
shouldSimulate: simulateTx,
147150
idempotencyKey,

src/server/routes/contract/extensions/erc721/write/transfer-from.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export async function erc721transferFrom(fastify: FastifyInstance) {
7979
"x-idempotency-key": idempotencyKey,
8080
"x-account-factory-address": accountFactoryAddress,
8181
"x-account-salt": accountSalt,
82+
"x-transaction-mode": transactionMode,
8283
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
8384

8485
const chainId = await getChainIdFromChain(chain);
@@ -107,6 +108,7 @@ export async function erc721transferFrom(fastify: FastifyInstance) {
107108
shouldSimulate: simulateTx,
108109
functionName: "transferFrom",
109110
extension: "erc721",
111+
transactionMode,
110112
});
111113

112114
reply.status(StatusCodes.OK).send({

src/server/routes/contract/extensions/erc721/write/transfer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export async function erc721transfer(fastify: FastifyInstance) {
7272
"x-idempotency-key": idempotencyKey,
7373
"x-account-factory-address": accountFactoryAddress,
7474
"x-account-salt": accountSalt,
75+
"x-transaction-mode": transactionMode,
7576
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
7677

7778
const chainId = await getChainIdFromChain(chain);
@@ -100,6 +101,7 @@ export async function erc721transfer(fastify: FastifyInstance) {
100101
shouldSimulate: simulateTx,
101102
functionName: "transferFrom",
102103
extension: "erc721",
104+
transactionMode,
103105
});
104106

105107
reply.status(StatusCodes.OK).send({

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export async function writeToContract(fastify: FastifyInstance) {
7777
"x-idempotency-key": idempotencyKey,
7878
"x-account-factory-address": accountFactoryAddress,
7979
"x-account-salt": accountSalt,
80+
"x-transaction-mode": transactionMode,
8081
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
8182

8283
const chainId = await getChainIdFromChain(chain);
@@ -128,6 +129,7 @@ export async function writeToContract(fastify: FastifyInstance) {
128129
accountSalt,
129130
txOverrides,
130131
idempotencyKey,
132+
transactionMode,
131133
shouldSimulate: simulateTx,
132134
});
133135

src/server/schemas/wallet/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ export const walletHeaderSchema = Type.Object({
1616
description: `Transactions submitted with the same idempotency key will be de-duplicated. Only the last ${env.TRANSACTION_HISTORY_COUNT} transactions are compared.`,
1717
}),
1818
),
19+
"x-transaction-mode": Type.Optional(
20+
Type.Union(
21+
[
22+
Type.Literal("sponsored", {
23+
description: "Attmpt to use native AA on ZKSync chains",
24+
}),
25+
],
26+
{
27+
description:
28+
"Transaction mode to use for EOA transactions. Will be ignored if using a smart wallet. If omitted, defaults to regular EOA transactions.",
29+
},
30+
),
31+
),
1932
});
2033

2134
export const walletWithAAHeaderSchema = Type.Object({

0 commit comments

Comments
 (0)