thirdweb 5.92.0 → 5.92.2-nightly-1e8d1e4b5225e7bb378f10e64efb6443b3351444-20250312000323

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/cjs/adapters/ethers5.js +2 -0
  2. package/dist/cjs/adapters/ethers5.js.map +1 -1
  3. package/dist/cjs/extensions/prebuilts/compute-ref-deployments.js +118 -0
  4. package/dist/cjs/extensions/prebuilts/compute-ref-deployments.js.map +1 -0
  5. package/dist/cjs/extensions/prebuilts/process-ref-deployments.js +7 -2
  6. package/dist/cjs/extensions/prebuilts/process-ref-deployments.js.map +1 -1
  7. package/dist/cjs/react/core/utils/wallet.js +1 -1
  8. package/dist/cjs/utils/any-evm/compute-published-contract-deploy-info.js +15 -1
  9. package/dist/cjs/utils/any-evm/compute-published-contract-deploy-info.js.map +1 -1
  10. package/dist/cjs/version.js +1 -1
  11. package/dist/cjs/version.js.map +1 -1
  12. package/dist/cjs/wallets/in-app/core/wallet/enclave-wallet.js +11 -15
  13. package/dist/cjs/wallets/in-app/core/wallet/enclave-wallet.js.map +1 -1
  14. package/dist/esm/adapters/ethers5.js +2 -0
  15. package/dist/esm/adapters/ethers5.js.map +1 -1
  16. package/dist/esm/extensions/prebuilts/compute-ref-deployments.js +115 -0
  17. package/dist/esm/extensions/prebuilts/compute-ref-deployments.js.map +1 -0
  18. package/dist/esm/extensions/prebuilts/process-ref-deployments.js +7 -2
  19. package/dist/esm/extensions/prebuilts/process-ref-deployments.js.map +1 -1
  20. package/dist/esm/react/core/utils/wallet.js +1 -1
  21. package/dist/esm/utils/any-evm/compute-published-contract-deploy-info.js +15 -1
  22. package/dist/esm/utils/any-evm/compute-published-contract-deploy-info.js.map +1 -1
  23. package/dist/esm/version.js +1 -1
  24. package/dist/esm/version.js.map +1 -1
  25. package/dist/esm/wallets/in-app/core/wallet/enclave-wallet.js +12 -16
  26. package/dist/esm/wallets/in-app/core/wallet/enclave-wallet.js.map +1 -1
  27. package/dist/types/extensions/prebuilts/compute-ref-deployments.d.ts +16 -0
  28. package/dist/types/extensions/prebuilts/compute-ref-deployments.d.ts.map +1 -0
  29. package/dist/types/extensions/prebuilts/process-ref-deployments.d.ts +5 -0
  30. package/dist/types/extensions/prebuilts/process-ref-deployments.d.ts.map +1 -1
  31. package/dist/types/react/core/utils/wallet.d.ts +1 -1
  32. package/dist/types/utils/any-evm/compute-published-contract-deploy-info.d.ts.map +1 -1
  33. package/dist/types/version.d.ts +1 -1
  34. package/dist/types/version.d.ts.map +1 -1
  35. package/dist/types/wallets/in-app/core/wallet/enclave-wallet.d.ts.map +1 -1
  36. package/package.json +1 -1
  37. package/src/adapters/eip1193/to-eip1193.test.ts +23 -0
  38. package/src/adapters/ethers5.test.ts +21 -0
  39. package/src/adapters/ethers5.ts +3 -0
  40. package/src/adapters/ethers6.test.ts +96 -20
  41. package/src/extensions/prebuilts/compute-ref-deployments.ts +161 -0
  42. package/src/extensions/prebuilts/process-ref-deployments.test.ts +73 -11
  43. package/src/extensions/prebuilts/process-ref-deployments.ts +7 -2
  44. package/src/react/core/utils/wallet.ts +1 -1
  45. package/src/utils/any-evm/compute-published-contract-deploy-info.ts +20 -1
  46. package/src/version.ts +1 -1
  47. package/src/wallets/in-app/core/wallet/enclave-wallet.ts +23 -26
  48. package/src/wallets/smart/smart-wallet-integration-v07.test.ts +1 -0
@@ -0,0 +1,161 @@
1
+ import type { Chain } from "../../chains/types.js";
2
+ import type { ThirdwebClient } from "../../client/client.js";
3
+ import { encodeAbiParameters } from "../../utils/abi/encodeAbiParameters.js";
4
+ import { computePublishedContractAddress } from "../../utils/any-evm/compute-published-contract-address.js";
5
+ import type { ImplementationConstructorParam } from "./process-ref-deployments.js";
6
+
7
+ type ComputeRefDeploymentsOptions = {
8
+ client: ThirdwebClient;
9
+ chain: Chain;
10
+ paramValue: string | ImplementationConstructorParam;
11
+ };
12
+
13
+ /**
14
+ * Computes addresses for published contract references in constructor params.
15
+ * @returns Param value after processing references.
16
+ * @internal
17
+ */
18
+ export async function computeRefDeployments(
19
+ options: ComputeRefDeploymentsOptions,
20
+ ): Promise<string | string[]> {
21
+ const { client, chain, paramValue } = options;
22
+
23
+ if (typeof paramValue === "object") {
24
+ if (
25
+ "defaultValue" in paramValue &&
26
+ paramValue.defaultValue &&
27
+ paramValue.defaultValue.length > 0
28
+ ) {
29
+ return paramValue.defaultValue;
30
+ }
31
+
32
+ if ("dynamicValue" in paramValue && paramValue.dynamicValue) {
33
+ const dynamicValue = paramValue.dynamicValue;
34
+ const contracts = dynamicValue.refContracts;
35
+
36
+ if (dynamicValue.type === "address") {
37
+ if (!contracts || contracts.length === 0 || !contracts[0]?.contractId) {
38
+ throw new Error("Invalid or empty param value");
39
+ }
40
+ const salt =
41
+ contracts[0]?.salt && contracts[0]?.salt.length > 0
42
+ ? contracts[0]?.salt
43
+ : "";
44
+
45
+ const addr = await computePublishedContractAddress({
46
+ client,
47
+ chain,
48
+ contractId: contracts[0]?.contractId,
49
+ publisher: contracts[0]?.publisherAddress,
50
+ version: contracts[0]?.version,
51
+ salt,
52
+ });
53
+
54
+ return addr;
55
+ }
56
+
57
+ if (dynamicValue.type === "address[]") {
58
+ if (!contracts || contracts.length === 0) {
59
+ throw new Error("Invalid or empty param value");
60
+ }
61
+ const addressArray: string[] = [];
62
+
63
+ for (const c of contracts) {
64
+ const salt = c?.salt && c?.salt.length > 0 ? c?.salt : "";
65
+
66
+ addressArray.push(
67
+ await computePublishedContractAddress({
68
+ client,
69
+ chain,
70
+ contractId: c.contractId,
71
+ publisher: c.publisherAddress,
72
+ version: c.version,
73
+ salt,
74
+ }),
75
+ );
76
+ }
77
+
78
+ return addressArray;
79
+ }
80
+
81
+ if (dynamicValue.type === "bytes") {
82
+ if (!dynamicValue.paramsToEncode) {
83
+ throw new Error("Invalid or empty param value");
84
+ }
85
+ const paramsToEncode = dynamicValue.paramsToEncode[0];
86
+
87
+ if (paramsToEncode) {
88
+ const types: string[] = [];
89
+ const values: (string | string[])[] = [];
90
+ for (const v of paramsToEncode) {
91
+ types.push(v.type);
92
+
93
+ if (v.defaultValue) {
94
+ values.push(v.defaultValue);
95
+ } else if (v.dynamicValue) {
96
+ values.push(
97
+ await computeRefDeployments({
98
+ client,
99
+ chain,
100
+ paramValue: v,
101
+ }),
102
+ );
103
+ }
104
+ }
105
+
106
+ return encodeAbiParameters(
107
+ types.map((t) => {
108
+ return { type: t };
109
+ }),
110
+ values,
111
+ );
112
+ }
113
+ }
114
+
115
+ if (dynamicValue.type === "bytes[]") {
116
+ if (!dynamicValue.paramsToEncode) {
117
+ throw new Error("Invalid or empty param value");
118
+ }
119
+ const bytesArray: string[] = [];
120
+ const paramArray = dynamicValue.paramsToEncode;
121
+
122
+ for (const a of paramArray) {
123
+ const paramsToEncode = a;
124
+
125
+ if (paramsToEncode) {
126
+ const types: string[] = [];
127
+ const values: (string | string[])[] = [];
128
+ for (const v of paramsToEncode) {
129
+ types.push(v.type);
130
+
131
+ if (v.defaultValue) {
132
+ values.push(v.defaultValue);
133
+ } else if (v.dynamicValue) {
134
+ values.push(
135
+ await computeRefDeployments({
136
+ client,
137
+ chain,
138
+ paramValue: v,
139
+ }),
140
+ );
141
+ }
142
+ }
143
+
144
+ bytesArray.push(
145
+ encodeAbiParameters(
146
+ types.map((t) => {
147
+ return { type: t };
148
+ }),
149
+ values,
150
+ ),
151
+ );
152
+ }
153
+ }
154
+
155
+ return bytesArray;
156
+ }
157
+ }
158
+ }
159
+
160
+ return paramValue as string;
161
+ }
@@ -3,6 +3,7 @@ import { ANVIL_CHAIN } from "../../../test/src/chains.js";
3
3
  import { TEST_CLIENT } from "../../../test/src/test-clients.js";
4
4
  import { TEST_ACCOUNT_A } from "../../../test/src/test-wallets.js";
5
5
  import { getContract } from "../../contract/contract.js";
6
+ import { getDeployedInfraContract } from "../../contract/deployment/utils/infra.js";
6
7
  import { readContract } from "../../transaction/read-contract.js";
7
8
  import { getInstalledModules } from "../modules/__generated__/IModularCore/read/getInstalledModules.js";
8
9
  import { deployPublishedContract } from "./deploy-published.js";
@@ -29,7 +30,7 @@ describe.runIf(process.env.TW_SECRET_KEY)(
29
30
  account: TEST_ACCOUNT_A,
30
31
  contractId: "MultiSig",
31
32
  version: "0.0.4",
32
- salt: "tw",
33
+ salt: "",
33
34
  publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
34
35
  });
35
36
  dummyContractAddress = await deployPublishedContract({
@@ -37,8 +38,8 @@ describe.runIf(process.env.TW_SECRET_KEY)(
37
38
  chain: ANVIL_CHAIN,
38
39
  account: TEST_ACCOUNT_A,
39
40
  contractId: "ContractWithBytes",
40
- version: "0.0.1",
41
- salt: "tw",
41
+ version: "0.0.2",
42
+ salt: "",
42
43
  publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
43
44
  });
44
45
  mintfeeManagerModuleAddress = await deployPublishedContract({
@@ -47,7 +48,7 @@ describe.runIf(process.env.TW_SECRET_KEY)(
47
48
  account: TEST_ACCOUNT_A,
48
49
  contractId: "MintFeeManagerModule",
49
50
  version: "0.0.1",
50
- salt: "tw",
51
+ salt: "",
51
52
  publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
52
53
  });
53
54
  mintfeeManagerCoreAddress = await deployPublishedContract({
@@ -55,8 +56,8 @@ describe.runIf(process.env.TW_SECRET_KEY)(
55
56
  chain: ANVIL_CHAIN,
56
57
  account: TEST_ACCOUNT_A,
57
58
  contractId: "MintFeeManagerCore",
58
- version: "0.0.25",
59
- salt: "tw",
59
+ version: "0.0.26",
60
+ salt: "",
60
61
  publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
61
62
  });
62
63
  claimableModuleAddress = await deployPublishedContract({
@@ -64,18 +65,17 @@ describe.runIf(process.env.TW_SECRET_KEY)(
64
65
  chain: ANVIL_CHAIN,
65
66
  account: TEST_ACCOUNT_A,
66
67
  contractId: "ClaimableERC721",
67
- version: "0.0.13",
68
- salt: "tw",
68
+ version: "0.0.14",
69
+ salt: "",
69
70
  publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
70
71
  });
71
-
72
72
  wethAddress = await deployPublishedContract({
73
73
  client: TEST_CLIENT,
74
74
  chain: ANVIL_CHAIN,
75
75
  account: TEST_ACCOUNT_A,
76
76
  contractId: "WETH9",
77
77
  version: "0.0.1",
78
- salt: "thirdweb",
78
+ salt: "",
79
79
  publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
80
80
  });
81
81
  forwarderAddress = await deployPublishedContract({
@@ -84,7 +84,7 @@ describe.runIf(process.env.TW_SECRET_KEY)(
84
84
  account: TEST_ACCOUNT_A,
85
85
  contractId: "Forwarder",
86
86
  version: "0.0.1",
87
- salt: "thirdweb",
87
+ salt: "",
88
88
  publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
89
89
  });
90
90
  multiwrapAddress = await deployPublishedContract({
@@ -192,5 +192,67 @@ describe.runIf(process.env.TW_SECRET_KEY)(
192
192
  expect(fetchedWethAddress.toLowerCase()).to.eq(wethAddress);
193
193
  expect(isTrustedForwarder).to.be.true;
194
194
  });
195
+
196
+ it("should correctly compute addresses for deployed contracts with refs", async () => {
197
+ const [
198
+ multisigAddressComputed,
199
+ dummyContractAddressComputed,
200
+ mintfeeManagerModuleAddressComputed,
201
+ mintfeeManagerCoreAddressComputed,
202
+ claimableModuleAddressComputed,
203
+ ] = await Promise.all([
204
+ getDeployedInfraContract({
205
+ client: TEST_CLIENT,
206
+ chain: ANVIL_CHAIN,
207
+ contractId: "MultiSig",
208
+ version: "0.0.4",
209
+ publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
210
+ }),
211
+ getDeployedInfraContract({
212
+ client: TEST_CLIENT,
213
+ chain: ANVIL_CHAIN,
214
+ contractId: "ContractWithBytes",
215
+ version: "0.0.2",
216
+ publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
217
+ }),
218
+ getDeployedInfraContract({
219
+ client: TEST_CLIENT,
220
+ chain: ANVIL_CHAIN,
221
+ contractId: "MintFeeManagerModule",
222
+ version: "0.0.1",
223
+ publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
224
+ }),
225
+ getDeployedInfraContract({
226
+ client: TEST_CLIENT,
227
+ chain: ANVIL_CHAIN,
228
+ contractId: "MintFeeManagerCore",
229
+ version: "0.0.26",
230
+ publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
231
+ }),
232
+ getDeployedInfraContract({
233
+ client: TEST_CLIENT,
234
+ chain: ANVIL_CHAIN,
235
+ contractId: "ClaimableERC721",
236
+ version: "0.0.14",
237
+ publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
238
+ }),
239
+ ]);
240
+
241
+ expect(multisigAddressComputed?.address.toLowerCase()).to.eq(
242
+ multisigAddress,
243
+ );
244
+ expect(dummyContractAddressComputed?.address.toLowerCase()).to.eq(
245
+ dummyContractAddress,
246
+ );
247
+ expect(mintfeeManagerModuleAddressComputed?.address.toLowerCase()).to.eq(
248
+ mintfeeManagerModuleAddress,
249
+ );
250
+ expect(mintfeeManagerCoreAddressComputed?.address.toLowerCase()).to.eq(
251
+ mintfeeManagerCoreAddress,
252
+ );
253
+ expect(claimableModuleAddressComputed?.address.toLowerCase()).to.eq(
254
+ claimableModuleAddress,
255
+ );
256
+ });
195
257
  },
196
258
  );
@@ -17,6 +17,11 @@ type ProcessRefDeploymentsOptions = {
17
17
  paramValue: string | ImplementationConstructorParam;
18
18
  };
19
19
 
20
+ /**
21
+ * Processes published contract references in constructor params. Deploys recursively if needed.
22
+ * @returns Param value after processing references.
23
+ * @internal
24
+ */
20
25
  export async function processRefDeployments(
21
26
  options: ProcessRefDeploymentsOptions,
22
27
  ): Promise<string | string[]> {
@@ -42,7 +47,7 @@ export async function processRefDeployments(
42
47
  const salt =
43
48
  contracts[0]?.salt && contracts[0]?.salt.length > 0
44
49
  ? contracts[0]?.salt
45
- : "thirdweb";
50
+ : "";
46
51
 
47
52
  const addr = await deployPublishedContract({
48
53
  client,
@@ -64,7 +69,7 @@ export async function processRefDeployments(
64
69
  const addressArray = [];
65
70
 
66
71
  for (const c of contracts) {
67
- const salt = c?.salt && c?.salt.length > 0 ? c?.salt : "thirdweb";
72
+ const salt = c?.salt && c?.salt.length > 0 ? c?.salt : "";
68
73
 
69
74
  addressArray.push(
70
75
  await deployPublishedContract({
@@ -157,7 +157,7 @@ export function useConnectedWalletDetails(
157
157
  * import { useWalletInfo } from "thirdweb/react";
158
158
  *
159
159
  * const { data: walletInfo } = useWalletInfo("io.metamask");
160
- * console.log("Walelt name", walletInfo?.name);
160
+ * console.log("wallet name", walletInfo?.name);
161
161
  * ```
162
162
  * @wallet
163
163
  */
@@ -3,6 +3,8 @@ import type { Chain } from "../../chains/types.js";
3
3
  import type { ThirdwebClient } from "../../client/client.js";
4
4
  import { fetchPublishedContractMetadata } from "../../contract/deployment/publisher.js";
5
5
  import { computeCreate2FactoryAddress } from "../../contract/deployment/utils/create-2-factory.js";
6
+ import { computeRefDeployments } from "../../extensions/prebuilts/compute-ref-deployments.js";
7
+ import type { ImplementationConstructorParam } from "../../extensions/prebuilts/process-ref-deployments.js";
6
8
  import { encodeAbiParameters } from "../abi/encodeAbiParameters.js";
7
9
  import { normalizeFunctionParams } from "../abi/normalizeFunctionParams.js";
8
10
  import { ensureBytecodePrefix } from "../bytecode/prefix.js";
@@ -51,6 +53,23 @@ export async function computeDeploymentInfoFromMetadata(args: {
51
53
  constructorParams?: Record<string, unknown>;
52
54
  salt?: string;
53
55
  }) {
56
+ const { client, chain, constructorParams, contractMetadata } = args;
57
+ const definedConstructorParams =
58
+ constructorParams || contractMetadata.constructorParams;
59
+ let processedConstructorParams: Record<string, string | string[]> | undefined;
60
+ if (definedConstructorParams) {
61
+ processedConstructorParams = {};
62
+ for (const key in definedConstructorParams) {
63
+ processedConstructorParams[key] = await computeRefDeployments({
64
+ client,
65
+ chain,
66
+ paramValue: definedConstructorParams[key] as
67
+ | string
68
+ | ImplementationConstructorParam,
69
+ });
70
+ }
71
+ }
72
+
54
73
  return computeDeploymentInfoFromBytecode({
55
74
  client: args.client,
56
75
  chain: args.chain,
@@ -60,7 +79,7 @@ export async function computeDeploymentInfoFromMetadata(args: {
60
79
  client: args.client,
61
80
  chain: args.chain,
62
81
  }),
63
- constructorParams: args.constructorParams,
82
+ constructorParams: processedConstructorParams,
64
83
  salt: args.salt,
65
84
  });
66
85
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.92.0";
1
+ export const version = "5.92.2-nightly-1e8d1e4b5225e7bb378f10e64efb6443b3351444-20250312000323";
@@ -5,7 +5,7 @@ import type { ThirdwebClient } from "../../../../client/client.js";
5
5
  import { eth_sendRawTransaction } from "../../../../rpc/actions/eth_sendRawTransaction.js";
6
6
  import { getRpcClient } from "../../../../rpc/rpc.js";
7
7
  import { getAddress } from "../../../../utils/address.js";
8
- import { type Hex, toHex } from "../../../../utils/encoding/hex.js";
8
+ import { type Hex, isHex, toHex } from "../../../../utils/encoding/hex.js";
9
9
  import { parseTypedData } from "../../../../utils/signatures/helpers/parse-typed-data.js";
10
10
  import type { Prettify } from "../../../../utils/type-utils.js";
11
11
  import type {
@@ -141,39 +141,32 @@ export class EnclaveWallet implements IWebWallet {
141
141
  const transaction: Record<string, Hex | number | undefined> = {
142
142
  to: tx.to ? getAddress(tx.to) : undefined,
143
143
  data: tx.data,
144
- value: typeof tx.value === "bigint" ? toHex(tx.value) : undefined,
145
- gas:
146
- typeof tx.gas === "bigint"
147
- ? toHex(tx.gas + tx.gas / BigInt(10))
148
- : undefined, // Add a 10% buffer to gas
144
+ value: hexlify(tx.value),
145
+ gas: hexlify(tx.gas),
149
146
  nonce:
150
- typeof tx.nonce === "number"
151
- ? toHex(tx.nonce)
152
- : toHex(
153
- await import(
154
- "../../../../rpc/actions/eth_getTransactionCount.js"
155
- ).then(({ eth_getTransactionCount }) =>
156
- eth_getTransactionCount(rpcRequest, {
157
- address: getAddress(this.address),
158
- blockTag: "pending",
159
- }),
160
- ),
161
- ),
147
+ hexlify(tx.nonce) ||
148
+ toHex(
149
+ await import(
150
+ "../../../../rpc/actions/eth_getTransactionCount.js"
151
+ ).then(({ eth_getTransactionCount }) =>
152
+ eth_getTransactionCount(rpcRequest, {
153
+ address: getAddress(this.address),
154
+ blockTag: "pending",
155
+ }),
156
+ ),
157
+ ),
162
158
  chainId: toHex(tx.chainId),
163
159
  };
164
160
 
165
- if (typeof tx.maxFeePerGas === "bigint") {
166
- transaction.maxFeePerGas = toHex(tx.maxFeePerGas);
167
- transaction.maxPriorityFeePerGas =
168
- typeof tx.maxPriorityFeePerGas === "bigint"
169
- ? toHex(tx.maxPriorityFeePerGas)
170
- : undefined;
161
+ if (hexlify(tx.maxFeePerGas)) {
162
+ transaction.maxFeePerGas = hexlify(tx.maxFeePerGas);
163
+ transaction.maxPriorityFeePerGas = hexlify(tx.maxPriorityFeePerGas);
171
164
  transaction.type = 2;
172
165
  } else {
173
- transaction.gasPrice =
174
- typeof tx.gasPrice === "bigint" ? toHex(tx.gasPrice) : undefined;
166
+ transaction.gasPrice = hexlify(tx.gasPrice);
175
167
  transaction.type = 0;
176
168
  }
169
+
177
170
  return signEnclaveTransaction({
178
171
  client,
179
172
  storage,
@@ -253,3 +246,7 @@ export class EnclaveWallet implements IWebWallet {
253
246
  };
254
247
  }
255
248
  }
249
+
250
+ function hexlify(value: string | number | bigint | undefined) {
251
+ return value === undefined || isHex(value) ? value : toHex(value);
252
+ }
@@ -305,6 +305,7 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
305
305
  const newSmartWallet = smartWallet({
306
306
  chain,
307
307
  gasless: true,
308
+ factoryAddress: DEFAULT_ACCOUNT_FACTORY_V0_7,
308
309
  overrides: {
309
310
  accountSalt: "test",
310
311
  },