Skip to content

Commit 7c40fda

Browse files
committed
Custom create2 factory deployment for skale chains (#5693)
TOOL-2779 (XPROT-931) ## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR introduces a custom `create2` factory deployment for SKALE chains, enhancing gas management and testing functionalities. ### Detailed summary - Added tests for `create2` factory address computation and deployment in `create-2-factory.test.ts`. - Introduced `Create2FactoryDeploymentInfo` type in `create-2-factory.ts`. - Implemented custom gas price and limit handling for specific SKALE chains. - Updated `deployCreate2Factory` to utilize custom gas settings. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 00b6c2e commit 7c40fda

File tree

3 files changed

+88
-4
lines changed

3 files changed

+88
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Custom create2 factory deployment for skale chains
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { describe, expect, it } from "vitest";
2+
import { ANVIL_CHAIN } from "../../../../test/src/chains.js";
3+
import { TEST_CLIENT } from "../../../../test/src/test-clients.js";
4+
import { TEST_ACCOUNT_A } from "../../../../test/src/test-wallets.js";
5+
import { defineChain } from "../../../chains/utils.js";
6+
import {
7+
computeCreate2FactoryAddress,
8+
deployCreate2Factory,
9+
getDeployedCreate2Factory,
10+
} from "./create-2-factory.js";
11+
12+
describe.runIf(process.env.TW_SECRET_KEY)("create2 factory tests", () => {
13+
it("should compute create2 factory address", async () => {
14+
const addr = await computeCreate2FactoryAddress({
15+
client: TEST_CLIENT,
16+
chain: defineChain(1),
17+
});
18+
19+
expect(addr).to.eq("0x4e59b44847b379578588920cA78FbF26c0B4956C");
20+
});
21+
22+
it("should compute create2 factory address with custom gas", async () => {
23+
const addr = await computeCreate2FactoryAddress({
24+
client: TEST_CLIENT,
25+
chain: defineChain(1564830818),
26+
});
27+
28+
expect(addr).to.eq("0x50620b64D9524aC7dC8c967123E87e5b6dB98f0c");
29+
});
30+
31+
it("should deploy create2 factory", async () => {
32+
await deployCreate2Factory({
33+
client: TEST_CLIENT,
34+
account: TEST_ACCOUNT_A,
35+
chain: ANVIL_CHAIN,
36+
});
37+
38+
const create2Factory = await getDeployedCreate2Factory({
39+
chain: ANVIL_CHAIN,
40+
client: TEST_CLIENT,
41+
});
42+
expect(create2Factory).not.toBeNull();
43+
});
44+
});

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

Lines changed: 39 additions & 4 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,26 @@ export async function deployCreate2Factory(options: ClientAndChainAndAccount) {
155162
chain,
156163
});
157164

158-
const gasPriceFetched = await getGasPrice(options);
159-
const bin = _getNearestGasPriceBin(gasPriceFetched);
165+
let gasPrice: bigint | undefined;
166+
let gasLimit: bigint | undefined;
167+
168+
if (CUSTOM_GAS_FOR_CHAIN[chainId]) {
169+
gasPrice = CUSTOM_GAS_FOR_CHAIN[chainId.toString()]?.gasPrice;
170+
gasLimit = CUSTOM_GAS_FOR_CHAIN[chainId.toString()]?.gasLimit;
171+
} else {
172+
const gasPriceFetched = await getGasPrice(options);
173+
gasPrice = _getNearestGasPriceBin(gasPriceFetched);
174+
}
175+
160176
const deploymentInfo = await _getCreate2FactoryDeploymentInfo(eipChain, {
161-
gasPrice: bin,
177+
gasPrice,
178+
gasLimit,
162179
});
163180

164181
const balance = await eth_getBalance(rpcRequest, {
165182
address: deploymentInfo.signerAddress,
166183
});
184+
167185
if (balance < deploymentInfo.valueToSend) {
168186
const transaction = prepareTransaction({
169187
chain,
@@ -193,7 +211,7 @@ export async function deployCreate2Factory(options: ClientAndChainAndAccount) {
193211
async function _getCreate2FactoryDeploymentInfo(
194212
chainId: number,
195213
gasOptions: { gasPrice?: bigint; gasLimit?: bigint },
196-
) {
214+
): Promise<Create2FactoryDeploymentInfo> {
197215
// 100000 is default deployment gas limit and 100 gwei is default gas price for create2 factory deployment
198216
// (See: https://github.com/Arachnid/deterministic-deployment-proxy?tab=readme-ov-file#deployment-gas-limit)
199217
const gasPrice = gasOptions.gasPrice ? gasOptions.gasPrice : 100n * 10n ** 9n;
@@ -278,6 +296,23 @@ const CUSTOM_GAS_FOR_CHAIN: Record<string, CustomChain> = {
278296
gasPrice: 2500n * 10n ** 9n,
279297
gasLimit: 200000n,
280298
},
299+
// SKALE chains
300+
"1350216234": {
301+
name: "Titan",
302+
gasPrice: 110000n,
303+
},
304+
"1482601649": {
305+
name: "Nebula",
306+
gasPrice: 110000n,
307+
},
308+
"1564830818": {
309+
name: "Calypso",
310+
gasPrice: 110000n,
311+
},
312+
"2046399126": {
313+
name: "Europa",
314+
gasPrice: 110000n,
315+
},
281316
};
282317

283318
const CUSTOM_GAS_BINS = [

0 commit comments

Comments
 (0)