Skip to content

chore: support AA addresses in /send-transaction #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions src/server/routes/backend-wallet/sendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
transactionWritesResponseSchema,
} from "../../schemas/sharedApiSchemas";
import { txOverridesSchema } from "../../schemas/txOverrides";
import { walletHeaderSchema } from "../../schemas/wallet";
import { walletWithAAHeaderSchema } from "../../schemas/wallet";
import { getChainIdFromChain } from "../../utils/chain";

const ParamsSchema = Type.Object({
Expand Down Expand Up @@ -57,7 +57,7 @@ export async function sendTransaction(fastify: FastifyInstance) {
operationId: "sendTransaction",
params: ParamsSchema,
body: requestBodySchema,
headers: walletHeaderSchema,
headers: walletWithAAHeaderSchema,
querystring: requestQuerystringSchema,
response: {
...standardResponseSchema,
Expand All @@ -71,19 +71,37 @@ export async function sendTransaction(fastify: FastifyInstance) {
const {
"x-backend-wallet-address": fromAddress,
"x-idempotency-key": idempotencyKey,
} = request.headers as Static<typeof walletHeaderSchema>;
"x-account-address": accountAddress,
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
const chainId = await getChainIdFromChain(chain);

const { id: queueId } = await queueTxRaw({
chainId: chainId.toString(),
fromAddress,
toAddress,
data,
value,
simulateTx,
idempotencyKey,
...txOverrides,
});
let queueId: string;
if (accountAddress) {
const { id } = await queueTxRaw({
chainId: chainId.toString(),
signerAddress: fromAddress,
accountAddress,
target: toAddress,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arent these all optional? prob dont need the if / else right? just pass everything through even if undefined

Copy link
Contributor Author

@arcoraven arcoraven Jun 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some code like this:

if (tx.accountAddress && tx.signerAddress) {
  // process as a userOp
}

In this case accountAddress is undefined so it would be okay, but I'd like to minimize the chance any code assumes a userOp if signerAddress is set (and in this case we'd be setting signerAddress for EOA transactions too).

data,
value,
simulateTx,
idempotencyKey,
...txOverrides,
});
queueId = id;
} else {
const { id } = await queueTxRaw({
chainId: chainId.toString(),
fromAddress,
toAddress,
data,
value,
simulateTx,
idempotencyKey,
...txOverrides,
});
queueId = id;
}

reply.status(StatusCodes.OK).send({
result: {
Expand Down
Loading