|
1 |
| -import { Type, type Static } from "@sinclair/typebox"; |
| 1 | +import { type Static, Type } from "@sinclair/typebox"; |
2 | 2 | import type { FastifyInstance } from "fastify";
|
3 | 3 | import { StatusCodes } from "http-status-codes";
|
4 |
| -import type { Address, Hex } from "thirdweb"; |
5 |
| -import { insertTransaction } from "../../../shared/utils/transaction/insert-transaction"; |
| 4 | +import { type Hex, prepareTransaction } from "thirdweb"; |
| 5 | +import { getChain } from "../../../shared/utils/chain"; |
| 6 | +import { thirdwebClient } from "../../../shared/utils/sdk"; |
| 7 | +import { queueTransaction } from "../../../shared/utils/transaction/queue-transation"; |
6 | 8 | import { AddressSchema } from "../../schemas/address";
|
7 | 9 | import {
|
8 | 10 | requestQuerystringSchema,
|
9 | 11 | standardResponseSchema,
|
10 | 12 | transactionWritesResponseSchema,
|
11 | 13 | } from "../../schemas/shared-api-schemas";
|
| 14 | +import { |
| 15 | + authorizationListSchema, |
| 16 | + toParsedAuthorization, |
| 17 | +} from "../../schemas/transaction/authorization"; |
12 | 18 | import { txOverridesSchema } from "../../schemas/tx-overrides";
|
13 | 19 | import {
|
14 | 20 | maybeAddress,
|
| 21 | + requiredAddress, |
15 | 22 | walletChainParamSchema,
|
16 | 23 | walletWithAAHeaderSchema,
|
17 | 24 | } from "../../schemas/wallet";
|
18 | 25 | import { getChainIdFromChain } from "../../utils/chain";
|
19 | 26 | import { parseTransactionOverrides } from "../../utils/transaction-overrides";
|
20 |
| -import { |
21 |
| - authorizationListSchema, |
22 |
| - toParsedAuthorization, |
23 |
| -} from "../../schemas/transaction/authorization"; |
24 | 27 |
|
25 | 28 | const requestBodySchema = Type.Object({
|
26 | 29 | toAddress: Type.Optional(AddressSchema),
|
@@ -78,51 +81,39 @@ export async function sendTransaction(fastify: FastifyInstance) {
|
78 | 81 | "x-idempotency-key": idempotencyKey,
|
79 | 82 | "x-account-address": accountAddress,
|
80 | 83 | "x-account-factory-address": accountFactoryAddress,
|
| 84 | + "x-account-salt": accountSalt, |
81 | 85 | "x-transaction-mode": transactionMode,
|
82 | 86 | } = request.headers as Static<typeof walletWithAAHeaderSchema>;
|
83 | 87 |
|
84 | 88 | const chainId = await getChainIdFromChain(chain);
|
| 89 | + const chainObject = await getChain(chainId); |
| 90 | + const { value: valueOverride, overrides } = |
| 91 | + parseTransactionOverrides(txOverrides); |
| 92 | + const transaction = prepareTransaction({ |
| 93 | + client: thirdwebClient, |
| 94 | + chain: chainObject, |
| 95 | + to: toAddress, |
| 96 | + data: data as Hex, |
| 97 | + value: BigInt(value) || valueOverride, |
| 98 | + authorizationList: authorizationList?.map(toParsedAuthorization), |
| 99 | + ...overrides, |
| 100 | + }); |
85 | 101 |
|
86 |
| - let queueId: string; |
87 |
| - if (accountAddress) { |
88 |
| - queueId = await insertTransaction({ |
89 |
| - insertedTransaction: { |
90 |
| - isUserOp: true, |
91 |
| - chainId, |
92 |
| - from: fromAddress as Address, |
93 |
| - to: toAddress as Address | undefined, |
94 |
| - data: data as Hex, |
95 |
| - value: BigInt(value), |
96 |
| - accountAddress: accountAddress as Address, |
97 |
| - signerAddress: fromAddress as Address, |
98 |
| - target: toAddress as Address | undefined, |
99 |
| - transactionMode: undefined, |
100 |
| - accountFactoryAddress: maybeAddress( |
101 |
| - accountFactoryAddress, |
102 |
| - "x-account-factory-address", |
103 |
| - ), |
104 |
| - ...parseTransactionOverrides(txOverrides), |
105 |
| - }, |
106 |
| - shouldSimulate: simulateTx, |
107 |
| - idempotencyKey, |
108 |
| - }); |
109 |
| - } else { |
110 |
| - queueId = await insertTransaction({ |
111 |
| - insertedTransaction: { |
112 |
| - isUserOp: false, |
113 |
| - chainId, |
114 |
| - from: fromAddress as Address, |
115 |
| - to: toAddress as Address | undefined, |
116 |
| - data: data as Hex, |
117 |
| - transactionMode: transactionMode, |
118 |
| - value: BigInt(value), |
119 |
| - authorizationList: authorizationList?.map(toParsedAuthorization), |
120 |
| - ...parseTransactionOverrides(txOverrides), |
121 |
| - }, |
122 |
| - shouldSimulate: simulateTx, |
123 |
| - idempotencyKey, |
124 |
| - }); |
125 |
| - } |
| 102 | + const queueId = await queueTransaction({ |
| 103 | + transaction, |
| 104 | + fromAddress: requiredAddress(fromAddress, "x-backend-wallet-address"), |
| 105 | + toAddress: maybeAddress(toAddress, "to"), |
| 106 | + accountAddress: maybeAddress(accountAddress, "x-account-address"), |
| 107 | + accountFactoryAddress: maybeAddress( |
| 108 | + accountFactoryAddress, |
| 109 | + "x-account-factory-address", |
| 110 | + ), |
| 111 | + accountSalt, |
| 112 | + txOverrides, |
| 113 | + idempotencyKey, |
| 114 | + transactionMode, |
| 115 | + shouldSimulate: simulateTx, |
| 116 | + }); |
126 | 117 |
|
127 | 118 | reply.status(StatusCodes.OK).send({
|
128 | 119 | result: {
|
|
0 commit comments