Skip to content

Commit e087405

Browse files
committed
check custom gas when deploying create2 factory
1 parent 17b5c52 commit e087405

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

packages/thirdweb/src/contract/deployment/utils/create-2-factory.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ const SIGNATURE = {
3232
s: "0x2222222222222222222222222222222222222222222222222222222222222222",
3333
} as const;
3434

35+
type Create2FactoryDeploymentInfo = {
36+
valueToSend: bigint;
37+
predictedAddress: `0x${string}`;
38+
signerAddress: string;
39+
transaction: `0x${string}`;
40+
};
41+
3542
/**
3643
* Computes the address of the Create2 factory contract and checks if it is deployed.
3744
* @param options - The options for retrieving the Create2 factory address.
@@ -155,15 +162,30 @@ export async function deployCreate2Factory(options: ClientAndChainAndAccount) {
155162
chain,
156163
});
157164

158-
const gasPriceFetched = await getGasPrice(options);
159-
const bin = _getNearestGasPriceBin(gasPriceFetched);
160-
const deploymentInfo = await _getCreate2FactoryDeploymentInfo(eipChain, {
161-
gasPrice: bin,
162-
});
165+
let deploymentInfo: Create2FactoryDeploymentInfo;
166+
167+
if (CUSTOM_GAS_FOR_CHAIN[chainId]) {
168+
const gasPrice = CUSTOM_GAS_FOR_CHAIN[chainId.toString()]?.gasPrice;
169+
const gasLimit = CUSTOM_GAS_FOR_CHAIN[chainId.toString()]?.gasLimit;
170+
171+
deploymentInfo = await _getCreate2FactoryDeploymentInfo(eipChain, {
172+
gasPrice,
173+
gasLimit,
174+
});
175+
176+
return deploymentInfo.predictedAddress;
177+
} else {
178+
const gasPriceFetched = await getGasPrice(options);
179+
const bin = _getNearestGasPriceBin(gasPriceFetched);
180+
deploymentInfo = await _getCreate2FactoryDeploymentInfo(eipChain, {
181+
gasPrice: bin,
182+
});
183+
}
163184

164185
const balance = await eth_getBalance(rpcRequest, {
165186
address: deploymentInfo.signerAddress,
166187
});
188+
167189
if (balance < deploymentInfo.valueToSend) {
168190
const transaction = prepareTransaction({
169191
chain,
@@ -193,7 +215,7 @@ export async function deployCreate2Factory(options: ClientAndChainAndAccount) {
193215
async function _getCreate2FactoryDeploymentInfo(
194216
chainId: number,
195217
gasOptions: { gasPrice?: bigint; gasLimit?: bigint },
196-
) {
218+
): Promise<Create2FactoryDeploymentInfo> {
197219
// 100000 is default deployment gas limit and 100 gwei is default gas price for create2 factory deployment
198220
// (See: https://github.com/Arachnid/deterministic-deployment-proxy?tab=readme-ov-file#deployment-gas-limit)
199221
const gasPrice = gasOptions.gasPrice ? gasOptions.gasPrice : 100n * 10n ** 9n;

0 commit comments

Comments
 (0)