Skip to content
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

WC-AA: Add workaround to support odd values on sendTransaction #416

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { logError } from "@/services/logging";
import { SCW_SERVICE, TransactionError, TransferError, errorToJSON } from "@/utils";
import { SCW_SERVICE, TransactionError, TransferError, decorateSendTransactionData, errorToJSON } from "@/utils";
import type { SignTypedDataParams } from "@alchemy/aa-core";
import type { Deferrable } from "@ethersproject/properties";
import { type TransactionRequest, type TransactionResponse } from "@ethersproject/providers";
Expand Down Expand Up @@ -120,7 +120,8 @@ class BaseWallet extends ZeroDevAccountSigner<"ECDSA"> {

async sendTransaction(transaction: Deferrable<TransactionRequest>): Promise<TransactionResponse> {
try {
return await super.sendTransaction(transaction);
const decoratedTransaction = await decorateSendTransactionData(transaction);
return await super.sendTransaction(decoratedTransaction);
} catch (error) {
logError("[SEND_TRANSACTION] - ERROR_SENDING_TRANSACTION", {
service: SCW_SERVICE,
Expand Down
1 change: 1 addition & 0 deletions packages/client/wallets/aa/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./constants";
export * from "./error";
export * from "./signer";
export * from "./helpers";
export * from "./transactions";
34 changes: 34 additions & 0 deletions packages/client/wallets/aa/src/utils/transactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { Deferrable } from "@ethersproject/properties";
import { type TransactionRequest } from "@ethersproject/providers";
import { hexlify } from "ethers/lib/utils";

/**
* We need to support odd value and data fields in a tx, as that data comes from WC
* ZeroDev implements hexlify, but doesn't support to send an odd string in value or data fields
* so we need to make the hexlify fix manually when sending a transaction.
* That fix can be found here:
* https://github.com/ethers-io/ethers.js/commit/a12030ad29aa13c02aa75d9e0860f4986a0043b4#diff-047e7ebfdbd5c41e762cda03593bd15ed8b3121dece67262729dfcbde7040818R221
* And more context on this issue:
* https://github.com/ethers-io/ethers.js/issues/614
*
* Applying to it hexValue is used as a workaround on Crossbit, but doesn't cover all the cases (i.e. 0x71afd498d0000).
* This function is the same as hexValue but without hexStripZeros, which is what makes it to not work.
*/
export async function decorateSendTransactionData(transaction: Deferrable<TransactionRequest>) {
const decoratedTransaction = { ...transaction };
if (transaction.value) {
const awaitedValue = await transaction.value;
if (awaitedValue) {
decoratedTransaction.value = hexlify(awaitedValue, { hexPad: "left" });
}
}

if (transaction.data) {
const awaitedData = await transaction.data;
if (awaitedData) {
decoratedTransaction.data = hexlify(awaitedData, { hexPad: "left" });
}
}

return decoratedTransaction;
}
Loading