Skip to content
Open
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
3 changes: 2 additions & 1 deletion packages/parsers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@solana/web3.js": "^1.95.0",
"bs58": "^6.0.0",
"buffer": "^6.0.3",
"ethers": "^6.0.0"
"ox": "^0.6.0"
},
"optionalDependencies": {
"@mysten/sui.js": "^0.50.0",
Expand All @@ -61,6 +61,7 @@
"rimraf": "^6.0.1",
"ts-jest": "^29.1.2",
"tsup": "^6.7.0",
"tsx": "^4.21.0",
"typescript": "^5.0.4"
},
"keywords": [
Expand Down
23 changes: 19 additions & 4 deletions packages/parsers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { NetworkId } from "@phantom/constants";
import { base64urlEncode } from "@phantom/base64url";
import { getTransactionEncoder, type Transaction } from "@solana/transactions";
import { Buffer } from "buffer";
import { Transaction as EthersTransaction, getAddress } from "ethers";
import { Address, TransactionEnvelopeEip1559, TransactionEnvelopeLegacy } from "ox";

// Re-export response parsers
export {
Expand Down Expand Up @@ -160,15 +160,30 @@ function parseEVMTransactionToHex(transaction: any): ParsedTransaction {
// Normalize addresses to proper checksum format
if (txForSerialization.to && typeof txForSerialization.to === "string") {
try {
txForSerialization.to = getAddress(txForSerialization.to);
txForSerialization.to = Address.from(txForSerialization.to);
} catch {
// If checksum validation fails, lowercase the address
txForSerialization.to = txForSerialization.to.toLowerCase();
}
}

// Serialize the transaction (RLP encode)
const serialized = EthersTransaction.from(txForSerialization).unsignedSerialized;
// Serialize the transaction (RLP encode) using ox
// Detect transaction type based on fields present
let serialized: string;
if (txForSerialization.maxFeePerGas !== undefined || txForSerialization.maxPriorityFeePerGas !== undefined) {
// EIP-1559 transaction - chainId is required, default to mainnet (1)
const eip1559Tx = {
...txForSerialization,
chainId: (txForSerialization.chainId ?? 1) as number,
} as Parameters<typeof TransactionEnvelopeEip1559.from>[0];
const envelope = TransactionEnvelopeEip1559.from(eip1559Tx);
serialized = TransactionEnvelopeEip1559.serialize(envelope);
} else {
// Legacy transaction
const legacyTx = txForSerialization as Parameters<typeof TransactionEnvelopeLegacy.from>[0];
const envelope = TransactionEnvelopeLegacy.from(legacyTx);
serialized = TransactionEnvelopeLegacy.serialize(envelope);
}
const hex = serialized.startsWith("0x") ? serialized : "0x" + serialized;

return {
Expand Down
Loading