@gearbox-protocol/sdk 3.0.0-vfour.365 → 3.0.0-vfour.366

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.
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var create2_exports = {};
20
20
  __export(create2_exports, {
21
+ Create2Deployer: () => Create2Deployer,
21
22
  DEFAULT_CREATE2_SALT: () => DEFAULT_CREATE2_SALT,
22
23
  PUBLIC_CREATE2_FACTORY: () => PUBLIC_CREATE2_FACTORY,
23
24
  deployUsingPublicCreate2: () => deployUsingPublicCreate2,
@@ -27,8 +28,47 @@ __export(create2_exports, {
27
28
  module.exports = __toCommonJS(create2_exports);
28
29
  var import_viem = require("viem");
29
30
  var import_actions = require("viem/actions");
31
+ var import_sdk = require("../sdk/index.js");
30
32
  const PUBLIC_CREATE2_FACTORY = "0x4e59b44847b379578588920ca78fbf26c0b4956c";
31
33
  const DEFAULT_CREATE2_SALT = "GEARBOX";
34
+ class Create2Deployer extends import_sdk.SDKConstruct {
35
+ #walletClient;
36
+ #logger;
37
+ constructor(sdk, walletClient) {
38
+ super(sdk);
39
+ this.#logger = sdk.logger?.child?.({
40
+ name: "Create2Deployer"
41
+ }) ?? sdk.logger;
42
+ this.#walletClient = walletClient;
43
+ }
44
+ async ensureExists(parameters) {
45
+ const { abi, args, bytecode } = parameters;
46
+ const address = getPublicCreate2Address({ abi, bytecode, args });
47
+ this.#logger?.info(`will deploy contract at ${address}`);
48
+ const isDeployed = await isDeployedUsingPublicCreate2(this.client, {
49
+ abi,
50
+ bytecode,
51
+ args
52
+ });
53
+ if (isDeployed) {
54
+ this.#logger?.info(`already deployed at ${address}`);
55
+ return { address };
56
+ }
57
+ const hash = await deployUsingPublicCreate2(this.#walletClient, parameters);
58
+ this.#logger?.debug(`waiting for contract to deploy, tx hash: ${hash}`);
59
+ const receipt = await this.client.waitForTransactionReceipt({
60
+ hash,
61
+ timeout: 12e4
62
+ });
63
+ if (receipt.status !== "success") {
64
+ throw new Error(`contract deploy reverted, tx hash: ${hash}`);
65
+ }
66
+ this.#logger?.info(
67
+ `deployed in tx ${hash} in block ${receipt.blockNumber}`
68
+ );
69
+ return { address, hash };
70
+ }
71
+ }
32
72
  async function deployUsingPublicCreate2(walletClient, parameters) {
33
73
  const {
34
74
  abi,
@@ -68,6 +108,7 @@ async function isDeployedUsingPublicCreate2(client, params) {
68
108
  }
69
109
  // Annotate the CommonJS export names for ESM import in node:
70
110
  0 && (module.exports = {
111
+ Create2Deployer,
71
112
  DEFAULT_CREATE2_SALT,
72
113
  PUBLIC_CREATE2_FACTORY,
73
114
  deployUsingPublicCreate2,
@@ -5,8 +5,47 @@ import {
5
5
  stringToHex
6
6
  } from "viem";
7
7
  import { getCode, sendTransaction } from "viem/actions";
8
+ import { SDKConstruct } from "../sdk/index.js";
8
9
  const PUBLIC_CREATE2_FACTORY = "0x4e59b44847b379578588920ca78fbf26c0b4956c";
9
10
  const DEFAULT_CREATE2_SALT = "GEARBOX";
11
+ class Create2Deployer extends SDKConstruct {
12
+ #walletClient;
13
+ #logger;
14
+ constructor(sdk, walletClient) {
15
+ super(sdk);
16
+ this.#logger = sdk.logger?.child?.({
17
+ name: "Create2Deployer"
18
+ }) ?? sdk.logger;
19
+ this.#walletClient = walletClient;
20
+ }
21
+ async ensureExists(parameters) {
22
+ const { abi, args, bytecode } = parameters;
23
+ const address = getPublicCreate2Address({ abi, bytecode, args });
24
+ this.#logger?.info(`will deploy contract at ${address}`);
25
+ const isDeployed = await isDeployedUsingPublicCreate2(this.client, {
26
+ abi,
27
+ bytecode,
28
+ args
29
+ });
30
+ if (isDeployed) {
31
+ this.#logger?.info(`already deployed at ${address}`);
32
+ return { address };
33
+ }
34
+ const hash = await deployUsingPublicCreate2(this.#walletClient, parameters);
35
+ this.#logger?.debug(`waiting for contract to deploy, tx hash: ${hash}`);
36
+ const receipt = await this.client.waitForTransactionReceipt({
37
+ hash,
38
+ timeout: 12e4
39
+ });
40
+ if (receipt.status !== "success") {
41
+ throw new Error(`contract deploy reverted, tx hash: ${hash}`);
42
+ }
43
+ this.#logger?.info(
44
+ `deployed in tx ${hash} in block ${receipt.blockNumber}`
45
+ );
46
+ return { address, hash };
47
+ }
48
+ }
10
49
  async function deployUsingPublicCreate2(walletClient, parameters) {
11
50
  const {
12
51
  abi,
@@ -45,6 +84,7 @@ async function isDeployedUsingPublicCreate2(client, params) {
45
84
  return !!code;
46
85
  }
47
86
  export {
87
+ Create2Deployer,
48
88
  DEFAULT_CREATE2_SALT,
49
89
  PUBLIC_CREATE2_FACTORY,
50
90
  deployUsingPublicCreate2,
@@ -1,5 +1,7 @@
1
1
  import type { Abi } from "abitype";
2
- import type { Account, Address, Chain, Client, ContractConstructorArgs, GetChainParameter, Hex, SendTransactionParameters, SendTransactionReturnType, Transport, UnionEvaluate, UnionOmit } from "viem";
2
+ import type { Account, Address, Chain, Client, ContractConstructorArgs, GetChainParameter, Hash, Hex, SendTransactionParameters, SendTransactionReturnType, Transport, UnionEvaluate, UnionOmit, WalletClient } from "viem";
3
+ import type { GearboxSDK } from "../sdk/index.js";
4
+ import { SDKConstruct } from "../sdk/index.js";
3
5
  export declare const PUBLIC_CREATE2_FACTORY: Address;
4
6
  export declare const DEFAULT_CREATE2_SALT = "GEARBOX";
5
7
  export type Create2Parameters<abi extends Abi | readonly unknown[] = Abi, chain extends Chain | undefined = Chain | undefined, account extends Account | undefined = Account | undefined, chainOverride extends Chain | undefined = Chain | undefined, allArgs = ContractConstructorArgs<abi>> = UnionOmit<SendTransactionParameters<chain, account, chainOverride>, "accessList" | "chain" | "to" | "data"> & GetChainParameter<chain, chainOverride> & UnionEvaluate<readonly [] extends allArgs ? {
@@ -18,6 +20,15 @@ export type Create2Parameters<abi extends Abi | readonly unknown[] = Abi, chain
18
20
  */
19
21
  salt?: string;
20
22
  };
23
+ export interface EnsureExistsUsingPublicCreate2ReturnType {
24
+ address: Address;
25
+ hash?: Hash;
26
+ }
27
+ export declare class Create2Deployer extends SDKConstruct {
28
+ #private;
29
+ constructor(sdk: GearboxSDK, walletClient: WalletClient);
30
+ ensureExists(parameters: Create2Parameters): Promise<EnsureExistsUsingPublicCreate2ReturnType>;
31
+ }
21
32
  /**
22
33
  * Viem action that deploys a contract using the public CREATE2 factory
23
34
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-vfour.365",
3
+ "version": "3.0.0-vfour.366",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",