thirdweb 5.93.6-nightly-48e014d4265f0cb14e1ccea2ff516b11c3a3005c-20250328000331 → 5.93.7-nightly-12bcfc596ae789cbeb8918896f18033258cee15f-20250329000332
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.
- package/dist/cjs/cli/bin.js +20 -0
- package/dist/cjs/cli/bin.js.map +1 -1
- package/dist/cjs/cli/commands/stylus/builder.js +179 -0
- package/dist/cjs/cli/commands/stylus/builder.js.map +1 -0
- package/dist/cjs/cli/commands/stylus/create.js +49 -0
- package/dist/cjs/cli/commands/stylus/create.js.map +1 -0
- package/dist/cjs/contract/deployment/deploy-deterministic.js +1 -1
- package/dist/cjs/contract/deployment/deploy-deterministic.js.map +1 -1
- package/dist/cjs/contract/deployment/deploy-with-abi.js +34 -11
- package/dist/cjs/contract/deployment/deploy-with-abi.js.map +1 -1
- package/dist/cjs/contract/deployment/utils/bootstrap.js +19 -0
- package/dist/cjs/contract/deployment/utils/bootstrap.js.map +1 -1
- package/dist/cjs/contract/deployment/utils/infra.js +1 -1
- package/dist/cjs/contract/deployment/utils/infra.js.map +1 -1
- package/dist/cjs/exports/extensions/stylus.js +9 -0
- package/dist/cjs/exports/extensions/stylus.js.map +1 -0
- package/dist/cjs/extensions/prebuilts/deploy-published.js +10 -0
- package/dist/cjs/extensions/prebuilts/deploy-published.js.map +1 -1
- package/dist/cjs/extensions/stylus/__generated__/IArbWasm/write/activateProgram.js +124 -0
- package/dist/cjs/extensions/stylus/__generated__/IArbWasm/write/activateProgram.js.map +1 -0
- package/dist/cjs/extensions/stylus/write/activateStylusContract.js +71 -0
- package/dist/cjs/extensions/stylus/write/activateStylusContract.js.map +1 -0
- package/dist/cjs/utils/any-evm/compute-deployment-address.js +3 -1
- package/dist/cjs/utils/any-evm/compute-deployment-address.js.map +1 -1
- package/dist/cjs/utils/any-evm/compute-published-contract-deploy-info.js +14 -2
- package/dist/cjs/utils/any-evm/compute-published-contract-deploy-info.js.map +1 -1
- package/dist/cjs/utils/any-evm/encode-extra-data-with-uri.js +13 -0
- package/dist/cjs/utils/any-evm/encode-extra-data-with-uri.js.map +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/cli/bin.js +20 -0
- package/dist/esm/cli/bin.js.map +1 -1
- package/dist/esm/cli/commands/stylus/builder.js +175 -0
- package/dist/esm/cli/commands/stylus/builder.js.map +1 -0
- package/dist/esm/cli/commands/stylus/create.js +46 -0
- package/dist/esm/cli/commands/stylus/create.js.map +1 -0
- package/dist/esm/contract/deployment/deploy-deterministic.js +1 -1
- package/dist/esm/contract/deployment/deploy-deterministic.js.map +1 -1
- package/dist/esm/contract/deployment/deploy-with-abi.js +34 -11
- package/dist/esm/contract/deployment/deploy-with-abi.js.map +1 -1
- package/dist/esm/contract/deployment/utils/bootstrap.js +19 -0
- package/dist/esm/contract/deployment/utils/bootstrap.js.map +1 -1
- package/dist/esm/contract/deployment/utils/infra.js +1 -1
- package/dist/esm/contract/deployment/utils/infra.js.map +1 -1
- package/dist/esm/exports/extensions/stylus.js +5 -0
- package/dist/esm/exports/extensions/stylus.js.map +1 -0
- package/dist/esm/extensions/prebuilts/deploy-published.js +10 -0
- package/dist/esm/extensions/prebuilts/deploy-published.js.map +1 -1
- package/dist/esm/extensions/stylus/__generated__/IArbWasm/write/activateProgram.js +117 -0
- package/dist/esm/extensions/stylus/__generated__/IArbWasm/write/activateProgram.js.map +1 -0
- package/dist/esm/extensions/stylus/write/activateStylusContract.js +68 -0
- package/dist/esm/extensions/stylus/write/activateStylusContract.js.map +1 -0
- package/dist/esm/utils/any-evm/compute-deployment-address.js +3 -1
- package/dist/esm/utils/any-evm/compute-deployment-address.js.map +1 -1
- package/dist/esm/utils/any-evm/compute-published-contract-deploy-info.js +14 -2
- package/dist/esm/utils/any-evm/compute-published-contract-deploy-info.js.map +1 -1
- package/dist/esm/utils/any-evm/encode-extra-data-with-uri.js +10 -0
- package/dist/esm/utils/any-evm/encode-extra-data-with-uri.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/cli/commands/stylus/builder.d.ts +3 -0
- package/dist/types/cli/commands/stylus/builder.d.ts.map +1 -0
- package/dist/types/cli/commands/stylus/create.d.ts +2 -0
- package/dist/types/cli/commands/stylus/create.d.ts.map +1 -0
- package/dist/types/contract/deployment/deploy-with-abi.d.ts +3 -0
- package/dist/types/contract/deployment/deploy-with-abi.d.ts.map +1 -1
- package/dist/types/contract/deployment/utils/bootstrap.d.ts.map +1 -1
- package/dist/types/exports/extensions/stylus.d.ts +5 -0
- package/dist/types/exports/extensions/stylus.d.ts.map +1 -0
- package/dist/types/extensions/prebuilts/deploy-published.d.ts.map +1 -1
- package/dist/types/extensions/stylus/__generated__/IArbWasm/write/activateProgram.d.ts +79 -0
- package/dist/types/extensions/stylus/__generated__/IArbWasm/write/activateProgram.d.ts.map +1 -0
- package/dist/types/extensions/stylus/write/activateStylusContract.d.ts +25 -0
- package/dist/types/extensions/stylus/write/activateStylusContract.d.ts.map +1 -0
- package/dist/types/react/web/ui/MediaRenderer/MediaRenderer.d.ts +1 -1
- package/dist/types/utils/any-evm/compute-deployment-address.d.ts +1 -0
- package/dist/types/utils/any-evm/compute-deployment-address.d.ts.map +1 -1
- package/dist/types/utils/any-evm/compute-published-contract-deploy-info.d.ts +7 -3
- package/dist/types/utils/any-evm/compute-published-contract-deploy-info.d.ts.map +1 -1
- package/dist/types/utils/any-evm/deploy-metadata.d.ts +1 -1
- package/dist/types/utils/any-evm/deploy-metadata.d.ts.map +1 -1
- package/dist/types/utils/any-evm/encode-extra-data-with-uri.d.ts +4 -0
- package/dist/types/utils/any-evm/encode-extra-data-with-uri.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +6 -1
- package/src/cli/bin.ts +25 -0
- package/src/cli/commands/stylus/builder.ts +201 -0
- package/src/cli/commands/stylus/create.ts +51 -0
- package/src/contract/deployment/deploy-deterministic.ts +1 -1
- package/src/contract/deployment/deploy-with-abi.ts +39 -13
- package/src/contract/deployment/utils/bootstrap.ts +21 -0
- package/src/contract/deployment/utils/infra.ts +1 -1
- package/src/exports/extensions/stylus.ts +7 -0
- package/src/extensions/prebuilts/deploy-published.ts +12 -0
- package/src/extensions/stylus/__generated__/IArbWasm/write/activateProgram.ts +144 -0
- package/src/extensions/stylus/write/activateStylusContract.ts +95 -0
- package/src/utils/any-evm/compute-deployment-address.ts +7 -4
- package/src/utils/any-evm/compute-published-contract-deploy-info.ts +16 -2
- package/src/utils/any-evm/deploy-metadata.ts +1 -1
- package/src/utils/any-evm/encode-extra-data-with-uri.ts +13 -0
- package/src/version.ts +1 -1
@@ -1,5 +1,7 @@
|
|
1
1
|
import type { Abi, AbiConstructor } from "abitype";
|
2
|
+
import { activateStylusContract } from "../../extensions/stylus/write/activateStylusContract.js";
|
2
3
|
import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
|
4
|
+
import { sendTransaction } from "../../transaction/actions/send-transaction.js";
|
3
5
|
import { prepareTransaction } from "../../transaction/prepare-transaction.js";
|
4
6
|
import { encodeAbiParameters } from "../../utils/abi/encodeAbiParameters.js";
|
5
7
|
import { normalizeFunctionParams } from "../../utils/abi/normalizeFunctionParams.js";
|
@@ -24,6 +26,7 @@ export type PrepareDirectDeployTransactionOptions = Prettify<
|
|
24
26
|
abi: Abi;
|
25
27
|
bytecode: Hex;
|
26
28
|
constructorParams?: Record<string, unknown>;
|
29
|
+
extraDataWithUri?: string;
|
27
30
|
}
|
28
31
|
>;
|
29
32
|
|
@@ -70,6 +73,7 @@ export function prepareDirectDeployTransaction(
|
|
70
73
|
constructorAbi?.inputs || [], // Leave an empty array if there's no constructor
|
71
74
|
normalizeFunctionParams(constructorAbi, options.constructorParams),
|
72
75
|
),
|
76
|
+
(options.extraDataWithUri as `0x${string}`) || "0x",
|
73
77
|
]),
|
74
78
|
});
|
75
79
|
}
|
@@ -121,6 +125,8 @@ export async function deployContract(
|
|
121
125
|
options: PrepareDirectDeployTransactionOptions & {
|
122
126
|
account: Account;
|
123
127
|
salt?: string;
|
128
|
+
extraDataWithUri?: Hex;
|
129
|
+
isStylus?: boolean;
|
124
130
|
},
|
125
131
|
) {
|
126
132
|
if (await isZkSyncChain(options.chain)) {
|
@@ -135,14 +141,16 @@ export async function deployContract(
|
|
135
141
|
});
|
136
142
|
}
|
137
143
|
|
144
|
+
let address: string | null | undefined;
|
138
145
|
if (options.salt !== undefined) {
|
139
146
|
// Deploy with CREATE2 if salt is provided
|
140
147
|
const info = await computeDeploymentInfoFromBytecode(options);
|
141
|
-
|
148
|
+
address = computeDeploymentAddress({
|
142
149
|
bytecode: options.bytecode,
|
143
150
|
encodedArgs: info.encodedArgs,
|
144
151
|
create2FactoryAddress: info.create2FactoryAddress,
|
145
152
|
salt: options.salt,
|
153
|
+
extraDataWithUri: options.extraDataWithUri,
|
146
154
|
});
|
147
155
|
const isDeployed = await isContractDeployed(
|
148
156
|
getContract({
|
@@ -160,21 +168,39 @@ export async function deployContract(
|
|
160
168
|
chain: options.chain,
|
161
169
|
client: options.client,
|
162
170
|
to: info.create2FactoryAddress,
|
163
|
-
data: info.
|
171
|
+
data: info.initCalldata,
|
164
172
|
}),
|
165
173
|
});
|
166
|
-
|
174
|
+
} else {
|
175
|
+
const deployTx = prepareDirectDeployTransaction(options);
|
176
|
+
const receipt = await sendAndConfirmTransaction({
|
177
|
+
account: options.account,
|
178
|
+
transaction: deployTx,
|
179
|
+
});
|
180
|
+
address = receipt.contractAddress;
|
181
|
+
if (!address) {
|
182
|
+
throw new Error(
|
183
|
+
`Could not find deployed contract address in transaction: ${receipt.transactionHash}`,
|
184
|
+
);
|
185
|
+
}
|
167
186
|
}
|
168
187
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
188
|
+
if (options.isStylus) {
|
189
|
+
try {
|
190
|
+
const activationTransaction = await activateStylusContract({
|
191
|
+
chain: options.chain,
|
192
|
+
client: options.client,
|
193
|
+
contractAddress: address,
|
194
|
+
});
|
195
|
+
|
196
|
+
await sendTransaction({
|
197
|
+
transaction: activationTransaction,
|
198
|
+
account: options.account,
|
199
|
+
});
|
200
|
+
} catch {
|
201
|
+
console.error("Error: Contract could not be activated.");
|
202
|
+
}
|
178
203
|
}
|
179
|
-
|
204
|
+
|
205
|
+
return address;
|
180
206
|
}
|
@@ -1,4 +1,6 @@
|
|
1
|
+
import { activateStylusContract } from "../../../extensions/stylus/write/activateStylusContract.js";
|
1
2
|
import { sendAndConfirmTransaction } from "../../../transaction/actions/send-and-confirm-transaction.js";
|
3
|
+
import { sendTransaction } from "../../../transaction/actions/send-transaction.js";
|
2
4
|
import {
|
3
5
|
type FetchDeployMetadataResult,
|
4
6
|
fetchBytecodeFromCompilerMetadata,
|
@@ -255,5 +257,24 @@ export async function getOrDeployInfraContractFromMetadata(
|
|
255
257
|
if (!deployedInfraContract) {
|
256
258
|
throw new Error(`Failed to deploy ${options.contractMetadata.name}`);
|
257
259
|
}
|
260
|
+
|
261
|
+
const isStylus = options.contractMetadata.metadata.language === "rust";
|
262
|
+
if (isStylus) {
|
263
|
+
try {
|
264
|
+
const activationTransaction = await activateStylusContract({
|
265
|
+
chain: options.chain,
|
266
|
+
client: options.client,
|
267
|
+
contractAddress: deployedInfraContract.address,
|
268
|
+
});
|
269
|
+
|
270
|
+
await sendTransaction({
|
271
|
+
transaction: activationTransaction,
|
272
|
+
account: options.account,
|
273
|
+
});
|
274
|
+
} catch {
|
275
|
+
console.error("Error: Contract could not be activated.");
|
276
|
+
}
|
277
|
+
}
|
278
|
+
|
258
279
|
return deployedInfraContract;
|
259
280
|
}
|
@@ -100,7 +100,7 @@ export function prepareInfraContractDeployTransactionFromMetadata(options: {
|
|
100
100
|
data: async () => {
|
101
101
|
const infraContractInfo =
|
102
102
|
await computeDeploymentInfoFromMetadata(options);
|
103
|
-
return infraContractInfo.
|
103
|
+
return infraContractInfo.initCalldata;
|
104
104
|
},
|
105
105
|
});
|
106
106
|
}
|
@@ -16,6 +16,7 @@ import {
|
|
16
16
|
fetchBytecodeFromCompilerMetadata,
|
17
17
|
} from "../../utils/any-evm/deploy-metadata.js";
|
18
18
|
import type { FetchDeployMetadataResult } from "../../utils/any-evm/deploy-metadata.js";
|
19
|
+
import { encodeExtraDataWithUri } from "../../utils/any-evm/encode-extra-data-with-uri.js";
|
19
20
|
import type { Hex } from "../../utils/encoding/hex.js";
|
20
21
|
import type { Account } from "../../wallets/interfaces/wallet.js";
|
21
22
|
import { getAllDefaultConstructorParamsForImplementation } from "./get-required-transactions.js";
|
@@ -194,6 +195,7 @@ export async function deployContractfromDeployMetadata(
|
|
194
195
|
compilerMetadata: deployMetadata,
|
195
196
|
contractParams: processedInitializeParams,
|
196
197
|
salt,
|
198
|
+
metadataUri: deployMetadata.metadataUri,
|
197
199
|
});
|
198
200
|
}
|
199
201
|
case "autoFactory": {
|
@@ -320,6 +322,7 @@ export async function deployContractfromDeployMetadata(
|
|
320
322
|
compilerMetadata: deployMetadata,
|
321
323
|
contractParams: processedInitializeParams,
|
322
324
|
salt,
|
325
|
+
metadataUri: deployMetadata.metadataUri,
|
323
326
|
});
|
324
327
|
}
|
325
328
|
default:
|
@@ -335,6 +338,7 @@ async function directDeploy(options: {
|
|
335
338
|
compilerMetadata: CompilerMetadata;
|
336
339
|
contractParams?: Record<string, unknown>;
|
337
340
|
salt?: string;
|
341
|
+
metadataUri?: string;
|
338
342
|
}): Promise<string> {
|
339
343
|
const { account, client, chain, compilerMetadata, contractParams, salt } =
|
340
344
|
options;
|
@@ -342,6 +346,7 @@ async function directDeploy(options: {
|
|
342
346
|
const { deployContract } = await import(
|
343
347
|
"../../contract/deployment/deploy-with-abi.js"
|
344
348
|
);
|
349
|
+
const isStylus = options.compilerMetadata.metadata.language === "rust";
|
345
350
|
return deployContract({
|
346
351
|
account,
|
347
352
|
client,
|
@@ -354,6 +359,13 @@ async function directDeploy(options: {
|
|
354
359
|
abi: compilerMetadata.abi,
|
355
360
|
constructorParams: contractParams,
|
356
361
|
salt,
|
362
|
+
extraDataWithUri:
|
363
|
+
isStylus && options.metadataUri
|
364
|
+
? encodeExtraDataWithUri({
|
365
|
+
metadataUri: options.metadataUri,
|
366
|
+
})
|
367
|
+
: undefined,
|
368
|
+
isStylus,
|
357
369
|
});
|
358
370
|
}
|
359
371
|
|
@@ -0,0 +1,144 @@
|
|
1
|
+
import type { AbiParameterToPrimitiveType } from "abitype";
|
2
|
+
import type {
|
3
|
+
BaseTransactionOptions,
|
4
|
+
WithOverrides,
|
5
|
+
} from "../../../../../transaction/types.js";
|
6
|
+
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
|
7
|
+
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
|
8
|
+
import { once } from "../../../../../utils/promise/once.js";
|
9
|
+
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Represents the parameters for the "activateProgram" function.
|
13
|
+
*/
|
14
|
+
export type ActivateProgramParams = WithOverrides<{
|
15
|
+
program: AbiParameterToPrimitiveType<{ type: "address"; name: "program" }>;
|
16
|
+
}>;
|
17
|
+
|
18
|
+
export const FN_SELECTOR = "0x58c780c2" as const;
|
19
|
+
const FN_INPUTS = [
|
20
|
+
{
|
21
|
+
type: "address",
|
22
|
+
name: "program",
|
23
|
+
},
|
24
|
+
] as const;
|
25
|
+
const FN_OUTPUTS = [
|
26
|
+
{
|
27
|
+
type: "uint16",
|
28
|
+
},
|
29
|
+
{
|
30
|
+
type: "uint256",
|
31
|
+
},
|
32
|
+
] as const;
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Checks if the `activateProgram` method is supported by the given contract.
|
36
|
+
* @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
|
37
|
+
* @returns A boolean indicating if the `activateProgram` method is supported.
|
38
|
+
* @extension STYLUS
|
39
|
+
* @example
|
40
|
+
* ```ts
|
41
|
+
* import { isActivateProgramSupported } from "thirdweb/extensions/stylus";
|
42
|
+
*
|
43
|
+
* const supported = isActivateProgramSupported(["0x..."]);
|
44
|
+
* ```
|
45
|
+
*/
|
46
|
+
export function isActivateProgramSupported(availableSelectors: string[]) {
|
47
|
+
return detectMethod({
|
48
|
+
availableSelectors,
|
49
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
50
|
+
});
|
51
|
+
}
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Encodes the parameters for the "activateProgram" function.
|
55
|
+
* @param options - The options for the activateProgram function.
|
56
|
+
* @returns The encoded ABI parameters.
|
57
|
+
* @extension STYLUS
|
58
|
+
* @example
|
59
|
+
* ```ts
|
60
|
+
* import { encodeActivateProgramParams } from "thirdweb/extensions/stylus";
|
61
|
+
* const result = encodeActivateProgramParams({
|
62
|
+
* program: ...,
|
63
|
+
* });
|
64
|
+
* ```
|
65
|
+
*/
|
66
|
+
export function encodeActivateProgramParams(options: ActivateProgramParams) {
|
67
|
+
return encodeAbiParameters(FN_INPUTS, [options.program]);
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Encodes the "activateProgram" function into a Hex string with its parameters.
|
72
|
+
* @param options - The options for the activateProgram function.
|
73
|
+
* @returns The encoded hexadecimal string.
|
74
|
+
* @extension STYLUS
|
75
|
+
* @example
|
76
|
+
* ```ts
|
77
|
+
* import { encodeActivateProgram } from "thirdweb/extensions/stylus";
|
78
|
+
* const result = encodeActivateProgram({
|
79
|
+
* program: ...,
|
80
|
+
* });
|
81
|
+
* ```
|
82
|
+
*/
|
83
|
+
export function encodeActivateProgram(options: ActivateProgramParams) {
|
84
|
+
// we do a "manual" concat here to avoid the overhead of the "concatHex" function
|
85
|
+
// we can do this because we know the specific formats of the values
|
86
|
+
return (FN_SELECTOR +
|
87
|
+
encodeActivateProgramParams(options).slice(
|
88
|
+
2,
|
89
|
+
)) as `${typeof FN_SELECTOR}${string}`;
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Prepares a transaction to call the "activateProgram" function on the contract.
|
94
|
+
* @param options - The options for the "activateProgram" function.
|
95
|
+
* @returns A prepared transaction object.
|
96
|
+
* @extension STYLUS
|
97
|
+
* @example
|
98
|
+
* ```ts
|
99
|
+
* import { sendTransaction } from "thirdweb";
|
100
|
+
* import { activateProgram } from "thirdweb/extensions/stylus";
|
101
|
+
*
|
102
|
+
* const transaction = activateProgram({
|
103
|
+
* contract,
|
104
|
+
* program: ...,
|
105
|
+
* overrides: {
|
106
|
+
* ...
|
107
|
+
* }
|
108
|
+
* });
|
109
|
+
*
|
110
|
+
* // Send the transaction
|
111
|
+
* await sendTransaction({ transaction, account });
|
112
|
+
* ```
|
113
|
+
*/
|
114
|
+
export function activateProgram(
|
115
|
+
options: BaseTransactionOptions<
|
116
|
+
| ActivateProgramParams
|
117
|
+
| {
|
118
|
+
asyncParams: () => Promise<ActivateProgramParams>;
|
119
|
+
}
|
120
|
+
>,
|
121
|
+
) {
|
122
|
+
const asyncOptions = once(async () => {
|
123
|
+
return "asyncParams" in options ? await options.asyncParams() : options;
|
124
|
+
});
|
125
|
+
|
126
|
+
return prepareContractCall({
|
127
|
+
contract: options.contract,
|
128
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
129
|
+
params: async () => {
|
130
|
+
const resolvedOptions = await asyncOptions();
|
131
|
+
return [resolvedOptions.program] as const;
|
132
|
+
},
|
133
|
+
value: async () => (await asyncOptions()).overrides?.value,
|
134
|
+
accessList: async () => (await asyncOptions()).overrides?.accessList,
|
135
|
+
gas: async () => (await asyncOptions()).overrides?.gas,
|
136
|
+
gasPrice: async () => (await asyncOptions()).overrides?.gasPrice,
|
137
|
+
maxFeePerGas: async () => (await asyncOptions()).overrides?.maxFeePerGas,
|
138
|
+
maxPriorityFeePerGas: async () =>
|
139
|
+
(await asyncOptions()).overrides?.maxPriorityFeePerGas,
|
140
|
+
nonce: async () => (await asyncOptions()).overrides?.nonce,
|
141
|
+
extraGas: async () => (await asyncOptions()).overrides?.extraGas,
|
142
|
+
erc20Value: async () => (await asyncOptions()).overrides?.erc20Value,
|
143
|
+
});
|
144
|
+
}
|
@@ -0,0 +1,95 @@
|
|
1
|
+
import {
|
2
|
+
decodeAbiParameters,
|
3
|
+
formatTransactionRequest,
|
4
|
+
parseEther,
|
5
|
+
} from "viem";
|
6
|
+
import type { Chain } from "../../../chains/types.js";
|
7
|
+
import type { ThirdwebClient } from "../../../client/client.js";
|
8
|
+
import { getContract } from "../../../contract/contract.js";
|
9
|
+
import { eth_call } from "../../../rpc/actions/eth_call.js";
|
10
|
+
import { getRpcClient } from "../../../rpc/rpc.js";
|
11
|
+
import { encode } from "../../../transaction/actions/encode.js";
|
12
|
+
import type { PreparedTransaction } from "../../../transaction/prepare-transaction.js";
|
13
|
+
import { activateProgram } from "../__generated__/IArbWasm/write/activateProgram.js";
|
14
|
+
|
15
|
+
const ARB_WASM_ADDRESS = "0x0000000000000000000000000000000000000071";
|
16
|
+
|
17
|
+
export type ActivateStylusContractOptions = {
|
18
|
+
chain: Chain;
|
19
|
+
client: ThirdwebClient;
|
20
|
+
contractAddress: string;
|
21
|
+
};
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Activate a stylus contract by calling ArbWasm Precompile
|
25
|
+
* @param options - The options for activating the contract
|
26
|
+
* @returns A prepared transaction to send
|
27
|
+
* @example
|
28
|
+
* ```ts
|
29
|
+
* import { activateStylusContract } from "thirdweb/stylus";
|
30
|
+
* const transaction = activateStylusContract({
|
31
|
+
* client,
|
32
|
+
* chain,
|
33
|
+
* contractAddress,
|
34
|
+
* });
|
35
|
+
* await sendTransaction({ transaction, account });
|
36
|
+
* ```
|
37
|
+
*/
|
38
|
+
export async function activateStylusContract(
|
39
|
+
options: ActivateStylusContractOptions,
|
40
|
+
) {
|
41
|
+
const { chain, client, contractAddress } = options;
|
42
|
+
const arbWasmPrecompile = getContract({
|
43
|
+
client,
|
44
|
+
chain,
|
45
|
+
address: ARB_WASM_ADDRESS,
|
46
|
+
});
|
47
|
+
|
48
|
+
const dataFee = await estimateDataFee({
|
49
|
+
transaction: activateProgram({
|
50
|
+
program: contractAddress,
|
51
|
+
contract: arbWasmPrecompile,
|
52
|
+
}),
|
53
|
+
});
|
54
|
+
|
55
|
+
return activateProgram({
|
56
|
+
program: contractAddress,
|
57
|
+
contract: arbWasmPrecompile,
|
58
|
+
overrides: {
|
59
|
+
value: dataFee,
|
60
|
+
},
|
61
|
+
});
|
62
|
+
}
|
63
|
+
|
64
|
+
async function estimateDataFee(options: {
|
65
|
+
// biome-ignore lint/suspicious/noExplicitAny:
|
66
|
+
transaction: PreparedTransaction<any>;
|
67
|
+
}) {
|
68
|
+
const data = await encode(options.transaction);
|
69
|
+
|
70
|
+
const serializedTx = formatTransactionRequest({
|
71
|
+
data,
|
72
|
+
to: ARB_WASM_ADDRESS,
|
73
|
+
value: parseEther("1"), // only for simulation. it will be replaced with estimated data fee.
|
74
|
+
});
|
75
|
+
|
76
|
+
const rpcRequest = getRpcClient(options.transaction);
|
77
|
+
try {
|
78
|
+
const result = await eth_call(rpcRequest, serializedTx);
|
79
|
+
const [, dataFee] = decodeAbiParameters(
|
80
|
+
[
|
81
|
+
{
|
82
|
+
type: "uint16",
|
83
|
+
},
|
84
|
+
{
|
85
|
+
type: "uint256",
|
86
|
+
},
|
87
|
+
],
|
88
|
+
result,
|
89
|
+
);
|
90
|
+
|
91
|
+
return (dataFee * BigInt(100 + 10)) / BigInt(100); // bump 10%
|
92
|
+
} catch {
|
93
|
+
return 0n;
|
94
|
+
}
|
95
|
+
}
|
@@ -11,6 +11,7 @@ type ComputeDeploymentAddressOptions = {
|
|
11
11
|
encodedArgs: Hex;
|
12
12
|
create2FactoryAddress: string;
|
13
13
|
salt?: string;
|
14
|
+
extraDataWithUri?: Hex;
|
14
15
|
};
|
15
16
|
|
16
17
|
/**
|
@@ -40,10 +41,12 @@ export function computeDeploymentAddress(
|
|
40
41
|
: getSaltHash(bytecode);
|
41
42
|
|
42
43
|
// 1. create init bytecode hash with contract's bytecode and encoded args
|
43
|
-
const initBytecode =
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
const initBytecode = options.extraDataWithUri
|
45
|
+
? encodePacked(
|
46
|
+
["bytes", "bytes", "bytes"],
|
47
|
+
[bytecode, options.encodedArgs, options.extraDataWithUri],
|
48
|
+
)
|
49
|
+
: encodePacked(["bytes", "bytes"], [bytecode, options.encodedArgs]);
|
47
50
|
|
48
51
|
// 2. abi-encode pack the deployer address, salt, and bytecode hash
|
49
52
|
const deployInfoPacked = encodePacked(
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { Abi, AbiConstructor } from "abitype";
|
2
|
+
import { encodePacked } from "viem";
|
2
3
|
import type { Chain } from "../../chains/types.js";
|
3
4
|
import type { ThirdwebClient } from "../../client/client.js";
|
4
5
|
import { fetchPublishedContractMetadata } from "../../contract/deployment/publisher.js";
|
@@ -13,6 +14,7 @@ import {
|
|
13
14
|
type FetchDeployMetadataResult,
|
14
15
|
fetchBytecodeFromCompilerMetadata,
|
15
16
|
} from "./deploy-metadata.js";
|
17
|
+
import { encodeExtraDataWithUri } from "./encode-extra-data-with-uri.js";
|
16
18
|
import { getInitBytecodeWithSalt } from "./get-init-bytecode-with-salt.js";
|
17
19
|
|
18
20
|
/**
|
@@ -70,6 +72,7 @@ export async function computeDeploymentInfoFromMetadata(args: {
|
|
70
72
|
}
|
71
73
|
}
|
72
74
|
|
75
|
+
const isStylus = contractMetadata.metadata.language === "rust";
|
73
76
|
return computeDeploymentInfoFromBytecode({
|
74
77
|
client: args.client,
|
75
78
|
chain: args.chain,
|
@@ -81,6 +84,11 @@ export async function computeDeploymentInfoFromMetadata(args: {
|
|
81
84
|
}),
|
82
85
|
constructorParams: processedConstructorParams,
|
83
86
|
salt: args.salt,
|
87
|
+
extraDataWithUri: isStylus
|
88
|
+
? encodeExtraDataWithUri({
|
89
|
+
metadataUri: contractMetadata.metadataUri,
|
90
|
+
})
|
91
|
+
: undefined,
|
84
92
|
});
|
85
93
|
}
|
86
94
|
|
@@ -91,8 +99,9 @@ export async function computeDeploymentInfoFromBytecode(args: {
|
|
91
99
|
bytecode: Hex;
|
92
100
|
constructorParams?: Record<string, unknown>;
|
93
101
|
salt?: string;
|
102
|
+
extraDataWithUri?: Hex;
|
94
103
|
}) {
|
95
|
-
const { client, chain, constructorParams, salt } = args;
|
104
|
+
const { client, chain, constructorParams, salt, extraDataWithUri } = args;
|
96
105
|
const create2FactoryAddress = await computeCreate2FactoryAddress({
|
97
106
|
client,
|
98
107
|
chain,
|
@@ -110,11 +119,16 @@ export async function computeDeploymentInfoFromBytecode(args: {
|
|
110
119
|
encodedArgs,
|
111
120
|
salt,
|
112
121
|
});
|
122
|
+
|
123
|
+
const initCalldata = extraDataWithUri
|
124
|
+
? encodePacked(["bytes", "bytes"], [initBytecodeWithsalt, extraDataWithUri])
|
125
|
+
: initBytecodeWithsalt;
|
113
126
|
return {
|
114
127
|
bytecode,
|
115
|
-
|
128
|
+
initCalldata,
|
116
129
|
encodedArgs,
|
117
130
|
create2FactoryAddress,
|
118
131
|
salt,
|
132
|
+
extraDataWithUri,
|
119
133
|
};
|
120
134
|
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { encodePacked } from "ox/AbiParameters";
|
2
|
+
import { numberToHex, stringToHex } from "../encoding/hex.js";
|
3
|
+
|
4
|
+
export function encodeExtraDataWithUri(options: {
|
5
|
+
metadataUri: string;
|
6
|
+
}) {
|
7
|
+
const uriHex = stringToHex(options.metadataUri);
|
8
|
+
const lengthHex = numberToHex(uriHex.replace("0x", "").length / 2, {
|
9
|
+
size: 1,
|
10
|
+
});
|
11
|
+
|
12
|
+
return encodePacked(["bytes", "bytes"], [uriHex, lengthHex]);
|
13
|
+
}
|
package/src/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = "5.93.
|
1
|
+
export const version = "5.93.7-nightly-12bcfc596ae789cbeb8918896f18033258cee15f-20250329000332";
|