Skip to content

Commit 7c088dd

Browse files
committed
wip
1 parent f9addb6 commit 7c088dd

File tree

16 files changed

+319
-344
lines changed

16 files changed

+319
-344
lines changed

packages/thirdweb/src/transaction/actions/eip7702/authorization.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type * as ox__Authorization from "ox/Authorization";
22
import type { Address } from "../../../utils/address.js";
33

44
/**
5-
* Represents an EIP-7702 authorization object prior to being signed.
5+
* An EIP-7702 authorization input object.
66
*
77
* @beta
88
* @transaction
@@ -13,6 +13,18 @@ export type Authorization = {
1313
nonce?: bigint;
1414
};
1515

16+
/**
17+
* An EIP-7702 authorization object fully prepared and ready for signing.
18+
*
19+
* @beta
20+
* @transaction
21+
*/
22+
export type PreparedAuthorization = {
23+
address: Address;
24+
chainId: number;
25+
nonce: bigint;
26+
};
27+
1628
/**
1729
* Represents a signed EIP-7702 authorization object.
1830
*

packages/thirdweb/src/transaction/actions/eip7702/sign-authorization.test.ts

Lines changed: 0 additions & 75 deletions
This file was deleted.

packages/thirdweb/src/transaction/actions/eip7702/sign-authorization.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

packages/thirdweb/src/transaction/actions/estimate-gas.ts

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import type { Prettify } from "../../utils/type-utils.js";
55
import type { Account } from "../../wallets/interfaces/wallet.js";
66
import { extractError } from "../extract-error.js";
77
import type { PreparedTransaction } from "../prepare-transaction.js";
8+
import { resolveAndSignAuthorizations } from "./to-serializable-transaction.js";
9+
import * as ox__Hex from "ox/Hex";
810

911
export type EstimateGasOptions = Prettify<
1012
{
@@ -16,19 +18,21 @@ export type EstimateGasOptions = Prettify<
1618
transaction: PreparedTransaction<any>;
1719
} & (
1820
| {
19-
/**
20-
* The account the transaction would be sent from.
21-
*/
22-
account: Account;
23-
from?: never;
24-
}
21+
/**
22+
* The account the transaction would be sent from.
23+
*
24+
* @deprecated Use `from` instead
25+
*/
26+
account: Account;
27+
from?: never;
28+
}
2529
| {
26-
account?: never;
27-
/**
28-
* The address the transaction would be sent from.
29-
*/
30-
from?: string;
31-
}
30+
account?: never;
31+
/**
32+
* The address the transaction would be sent from.
33+
*/
34+
from?: string | Account;
35+
}
3236
)
3337
>;
3438

@@ -60,8 +64,11 @@ export async function estimateGas(
6064
// 1. the user specified from address
6165
// 2. the passed in account address
6266
// 3. the passed in wallet's account address
63-
const from = options.from ?? options.account?.address ?? undefined;
64-
const txWithFrom = { ...options.transaction, from };
67+
const fromAddress =
68+
typeof options.from === "string"
69+
? options.from ?? undefined
70+
: options.from?.address ?? options.account?.address;
71+
const txWithFrom = { ...options.transaction, from: fromAddress };
6572
if (cache.has(txWithFrom)) {
6673
// biome-ignore lint/style/noNonNullAssertion: the `has` above ensures that this will always be set
6774
return cache.get(txWithFrom)!;
@@ -92,11 +99,13 @@ export async function estimateGas(
9299

93100
// load up encode function if we need it
94101
const { encode } = await import("./encode.js");
95-
const [encodedData, toAddress, value] = await Promise.all([
96-
encode(options.transaction),
97-
resolvePromisedValue(options.transaction.to),
98-
resolvePromisedValue(options.transaction.value),
99-
]);
102+
const [encodedData, toAddress, value, authorizationList] =
103+
await Promise.all([
104+
encode(options.transaction),
105+
resolvePromisedValue(options.transaction.to),
106+
resolvePromisedValue(options.transaction.value),
107+
resolveAndSignAuthorizations(options),
108+
]);
100109

101110
// load up the rpc client and the estimateGas function if we need it
102111
const [{ getRpcClient }, { eth_estimateGas }] = await Promise.all([
@@ -111,8 +120,16 @@ export async function estimateGas(
111120
formatTransactionRequest({
112121
to: toAddress,
113122
data: encodedData,
114-
from,
123+
from: fromAddress,
115124
value,
125+
// TODO: Remove this casting when we migrate this file to Ox
126+
authorizationList: authorizationList?.map((auth) => ({
127+
...auth,
128+
r: ox__Hex.fromNumber(auth.r),
129+
s: ox__Hex.fromNumber(auth.s),
130+
nonce: Number(auth.nonce),
131+
contractAddress: auth.address,
132+
})),
116133
}),
117134
);
118135
if (options.transaction.chain.experimental?.increaseZeroByteCount) {

0 commit comments

Comments
 (0)