@gearbox-protocol/sdk 12.9.0-txparser.1 → 12.9.0-txparser.2

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.
@@ -23,16 +23,16 @@ __export(history_exports, {
23
23
  toLegacyOperations: () => import_toLegacyOperation.toLegacyOperations
24
24
  });
25
25
  module.exports = __toCommonJS(history_exports);
26
- __reExport(history_exports, require("./ContractRegister.js"), module.exports);
27
26
  __reExport(history_exports, require("./inner-operations.js"), module.exports);
28
27
  var import_parseCreditAccountTransaction = require("./parseCreditAccountTransaction.js");
28
+ __reExport(history_exports, require("./populateContractsRegister.js"), module.exports);
29
29
  var import_toLegacyOperation = require("./toLegacyOperation.js");
30
30
  __reExport(history_exports, require("./types.js"), module.exports);
31
31
  // Annotate the CommonJS export names for ESM import in node:
32
32
  0 && (module.exports = {
33
33
  parseCreditAccountTransaction,
34
34
  toLegacyOperations,
35
- ...require("./ContractRegister.js"),
36
35
  ...require("./inner-operations.js"),
36
+ ...require("./populateContractsRegister.js"),
37
37
  ...require("./types.js")
38
38
  });
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var populateContractsRegister_exports = {};
20
+ __export(populateContractsRegister_exports, {
21
+ populateContractsRegister: () => populateContractsRegister
22
+ });
23
+ module.exports = __toCommonJS(populateContractsRegister_exports);
24
+ var import_viem = require("viem");
25
+ var import_createAdapter = require("../plugins/adapters/createAdapter.js");
26
+ var import_sdk = require("../sdk/index.js");
27
+ function populateContractsRegister(options) {
28
+ const { client, deployments, tokens, logger, strict } = options;
29
+ const register = import_sdk.ChainContractsRegister.for(client, logger);
30
+ for (const d of deployments) {
31
+ let contractType;
32
+ if ("contractType" in d) {
33
+ contractType = (0, import_viem.isHex)(d.contractType) ? (0, import_sdk.bytes32ToString)(d.contractType) : d.contractType;
34
+ } else {
35
+ contractType = [d.contractTypePrefix, d.contractTypeSuffix].filter(Boolean).join("::");
36
+ }
37
+ if (contractType === "CREDIT_FACADE" && (0, import_sdk.isV310)(d.version)) {
38
+ new import_sdk.CreditFacadeV310BaseContract(
39
+ { client: register.client, logger },
40
+ { addr: d.address, version: d.version, contractType }
41
+ );
42
+ } else if (contractType.startsWith("ADAPTER::")) {
43
+ (0, import_createAdapter.createAdapter)(
44
+ {
45
+ client: register.client,
46
+ logger
47
+ },
48
+ {
49
+ baseParams: {
50
+ addr: d.address,
51
+ version: d.version,
52
+ contractType
53
+ }
54
+ },
55
+ strict
56
+ );
57
+ }
58
+ }
59
+ const tMetas = tokens instanceof import_sdk.TokensMeta ? tokens.values() : tokens;
60
+ for (const t of tMetas) {
61
+ register.tokensMeta.upsert(t.addr, t);
62
+ }
63
+ return register;
64
+ }
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ populateContractsRegister
68
+ });
@@ -21,6 +21,7 @@ __export(createAdapter_exports, {
21
21
  createAdapter: () => createAdapter
22
22
  });
23
23
  module.exports = __toCommonJS(createAdapter_exports);
24
+ var import_viem = require("viem");
24
25
  var import_sdk = require("../../sdk/index.js");
25
26
  var import_AccountMigratorAdapterContract = require("./contracts/AccountMigratorAdapterContract.js");
26
27
  var import_InfinifiGatewayAdapterContract = require("./contracts/InfinifiGatewayAdapterContract.js");
@@ -28,9 +29,8 @@ var import_InfinifiUnwindingGatewayAdapterContract = require("./contracts/Infini
28
29
  var import_contracts = require("./contracts/index.js");
29
30
  var import_UniswapV4AdapterContract = require("./contracts/UniswapV4AdapterContract.js");
30
31
  function createAdapter(options, data, strict) {
31
- const adapterType = (0, import_sdk.bytes32ToString)(
32
- data.baseParams.contractType
33
- );
32
+ const contractType = data.baseParams.contractType;
33
+ const adapterType = (0, import_viem.isHex)(contractType) ? (0, import_sdk.bytes32ToString)(contractType) : contractType;
34
34
  switch (adapterType) {
35
35
  case "ADAPTER::ACCOUNT_MIGRATOR":
36
36
  return new import_AccountMigratorAdapterContract.AccountMigratorAdapterContract(options, data);
@@ -1,6 +1,6 @@
1
- export * from "./ContractRegister.js";
2
1
  export * from "./inner-operations.js";
3
2
  import { parseCreditAccountTransaction } from "./parseCreditAccountTransaction.js";
3
+ export * from "./populateContractsRegister.js";
4
4
  import { toLegacyOperations } from "./toLegacyOperation.js";
5
5
  export * from "./types.js";
6
6
  export {
@@ -0,0 +1,52 @@
1
+ import {
2
+ isHex
3
+ } from "viem";
4
+ import { createAdapter } from "../plugins/adapters/createAdapter.js";
5
+ import {
6
+ bytes32ToString,
7
+ ChainContractsRegister,
8
+ CreditFacadeV310BaseContract,
9
+ isV310,
10
+ TokensMeta
11
+ } from "../sdk/index.js";
12
+ function populateContractsRegister(options) {
13
+ const { client, deployments, tokens, logger, strict } = options;
14
+ const register = ChainContractsRegister.for(client, logger);
15
+ for (const d of deployments) {
16
+ let contractType;
17
+ if ("contractType" in d) {
18
+ contractType = isHex(d.contractType) ? bytes32ToString(d.contractType) : d.contractType;
19
+ } else {
20
+ contractType = [d.contractTypePrefix, d.contractTypeSuffix].filter(Boolean).join("::");
21
+ }
22
+ if (contractType === "CREDIT_FACADE" && isV310(d.version)) {
23
+ new CreditFacadeV310BaseContract(
24
+ { client: register.client, logger },
25
+ { addr: d.address, version: d.version, contractType }
26
+ );
27
+ } else if (contractType.startsWith("ADAPTER::")) {
28
+ createAdapter(
29
+ {
30
+ client: register.client,
31
+ logger
32
+ },
33
+ {
34
+ baseParams: {
35
+ addr: d.address,
36
+ version: d.version,
37
+ contractType
38
+ }
39
+ },
40
+ strict
41
+ );
42
+ }
43
+ }
44
+ const tMetas = tokens instanceof TokensMeta ? tokens.values() : tokens;
45
+ for (const t of tMetas) {
46
+ register.tokensMeta.upsert(t.addr, t);
47
+ }
48
+ return register;
49
+ }
50
+ export {
51
+ populateContractsRegister
52
+ };
@@ -1,3 +1,4 @@
1
+ import { isHex } from "viem";
1
2
  import { bytes32ToString } from "../../sdk/index.js";
2
3
  import { AccountMigratorAdapterContract } from "./contracts/AccountMigratorAdapterContract.js";
3
4
  import { InfinifiGatewayAdapterContract } from "./contracts/InfinifiGatewayAdapterContract.js";
@@ -47,9 +48,8 @@ import {
47
48
  } from "./contracts/index.js";
48
49
  import { UniswapV4AdapterContract } from "./contracts/UniswapV4AdapterContract.js";
49
50
  function createAdapter(options, data, strict) {
50
- const adapterType = bytes32ToString(
51
- data.baseParams.contractType
52
- );
51
+ const contractType = data.baseParams.contractType;
52
+ const adapterType = isHex(contractType) ? bytes32ToString(contractType) : contractType;
53
53
  switch (adapterType) {
54
54
  case "ADAPTER::ACCOUNT_MIGRATOR":
55
55
  return new AccountMigratorAdapterContract(options, data);
@@ -1,6 +1,6 @@
1
1
  export type { TokenInfo } from "../plugins/adapters/types.js";
2
- export * from "./ContractRegister.js";
3
2
  export * from "./inner-operations.js";
4
3
  export { parseCreditAccountTransaction } from "./parseCreditAccountTransaction.js";
4
+ export * from "./populateContractsRegister.js";
5
5
  export { toLegacyOperations } from "./toLegacyOperation.js";
6
6
  export * from "./types.js";
@@ -0,0 +1,19 @@
1
+ import { type Address, type Chain, type PublicClient, type Transport } from "viem";
2
+ import { ChainContractsRegister, type ILogger, type TokenMetaData, TokensMeta } from "../sdk/index.js";
3
+ export type Deployment = {
4
+ address: Address;
5
+ version: number;
6
+ } & ({
7
+ contractTypePrefix: string;
8
+ contractTypeSuffix: string;
9
+ } | {
10
+ contractType: string;
11
+ });
12
+ export interface PopulateContractsRegisterOptions {
13
+ client: PublicClient<Transport, Chain>;
14
+ deployments: Deployment[];
15
+ tokens: TokensMeta | Iterable<TokenMetaData>;
16
+ logger?: ILogger;
17
+ strict?: boolean;
18
+ }
19
+ export declare function populateContractsRegister(options: PopulateContractsRegisterOptions): ChainContractsRegister;
@@ -1,10 +1,10 @@
1
1
  import { type Abi, type Address, type Hex, type PartialBy } from "viem";
2
- import type { ConstructOptions, ParsedCallV2, TypedVersionedAddress } from "../../../sdk/index.js";
2
+ import type { ConstructOptions, ParsedCallV2, RelaxedBaseParams } from "../../../sdk/index.js";
3
3
  import { BaseContract } from "../../../sdk/index.js";
4
4
  import type { LegacyAdapterOperation, Transfers } from "../legacyAdapterOperations.js";
5
5
  import type { AdapterContractType, AdapterOperation, TokenTransfer } from "../types.js";
6
6
  export interface ConcreteAdapterContractOptions {
7
- baseParams: TypedVersionedAddress;
7
+ baseParams: RelaxedBaseParams;
8
8
  targetContract?: Address;
9
9
  name?: string;
10
10
  }
@@ -1,7 +1,7 @@
1
- import type { Address } from "viem";
2
- import type { ConstructOptions, IBaseContract, TypedVersionedAddress } from "../../sdk/index.js";
1
+ import { type Address } from "viem";
2
+ import type { ConstructOptions, IBaseContract, RelaxedBaseParams } from "../../sdk/index.js";
3
3
  export interface AdapterFactoryArgs {
4
- baseParams: TypedVersionedAddress;
4
+ baseParams: RelaxedBaseParams;
5
5
  targetContract?: Address;
6
6
  }
7
7
  export declare function createAdapter(options: ConstructOptions, data: AdapterFactoryArgs, strict?: boolean): IBaseContract;
@@ -1,5 +1,5 @@
1
1
  import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype";
2
- import type { Address, Hex, PartialBy } from "viem";
2
+ import type { Address, Hex } from "viem";
3
3
  import type { creditAccountCompressorAbi } from "../../abi/compressors/creditAccountCompressor.js";
4
4
  import type { gaugeCompressorAbi } from "../../abi/compressors/gaugeCompressor.js";
5
5
  import type { marketCompressorAbi } from "../../abi/compressors/marketCompressor.js";
@@ -12,10 +12,18 @@ export interface BaseParams {
12
12
  contractType: Hex;
13
13
  serializedParams: Hex;
14
14
  }
15
+ export interface RelaxedBaseParams {
16
+ addr: Address;
17
+ version: number | bigint;
18
+ /**
19
+ * Hex or parsed hex32 string
20
+ */
21
+ contractType: string;
22
+ serializedParams?: Hex;
23
+ }
15
24
  export interface BaseState {
16
25
  baseParams: BaseParams;
17
26
  }
18
- export type TypedVersionedAddress = PartialBy<BaseParams, "serializedParams">;
19
27
  export type MarketFilter = AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof marketCompressorAbi, "getMarkets">["inputs"]>[0];
20
28
  export type CreditAccountData = Unarray<AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof creditAccountCompressorAbi, "getCreditAccountData">["outputs"]>>;
21
29
  export type RewardInfo = Unarray<AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof rewardsCompressorAbi, "getRewards">["outputs"]>>;
@@ -1,10 +1,10 @@
1
1
  import type { Address } from "viem";
2
2
  import type { ConstructOptions } from "../../base/index.js";
3
3
  import { PlaceholderContract } from "../../base/index.js";
4
- import type { TypedVersionedAddress } from "../../index.js";
4
+ import type { RelaxedBaseParams } from "../../index.js";
5
5
  import type { IAdapterContract } from "./types.js";
6
6
  export interface PlaceholderAdapterContractOptions {
7
- baseParams: TypedVersionedAddress;
7
+ baseParams: RelaxedBaseParams;
8
8
  targetContract?: Address;
9
9
  }
10
10
  export declare class PlaceholderAdapterContract extends PlaceholderContract implements IAdapterContract {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "12.9.0-txparser.1",
3
+ "version": "12.9.0-txparser.2",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",
@@ -1,69 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var ContractRegister_exports = {};
20
- __export(ContractRegister_exports, {
21
- ContractRegister: () => ContractRegister
22
- });
23
- module.exports = __toCommonJS(ContractRegister_exports);
24
- var import_sdk = require("../sdk/index.js");
25
- class ContractRegister {
26
- #client;
27
- #logger;
28
- #register;
29
- #factories = [];
30
- constructor(client, logger) {
31
- this.#client = client;
32
- this.#logger = logger;
33
- this.#register = import_sdk.ChainContractsRegister.for(client, logger);
34
- }
35
- get register() {
36
- return this.#register;
37
- }
38
- registerFactory(factory) {
39
- this.#factories.push(factory);
40
- }
41
- createContract(args) {
42
- const { addr, version } = args;
43
- const existing = this.#register.getContract(addr);
44
- if (existing) {
45
- return existing;
46
- }
47
- const contractType = (0, import_sdk.bytes32ToString)(args.contractType);
48
- if (contractType === "CREDIT_FACADE" && (0, import_sdk.isV310)(version)) {
49
- return new import_sdk.CreditFacadeV310BaseContract(
50
- { client: this.#client, logger: this.#logger },
51
- { ...args, name: `CreditFacadeV310(${addr})` }
52
- );
53
- }
54
- for (const factory of this.#factories) {
55
- const contract = factory(
56
- { client: this.#client, logger: this.#logger },
57
- args
58
- );
59
- if (contract) {
60
- return contract;
61
- }
62
- }
63
- throw new Error(`unknown contract ${contractType} v${version}`);
64
- }
65
- }
66
- // Annotate the CommonJS export names for ESM import in node:
67
- 0 && (module.exports = {
68
- ContractRegister
69
- });
@@ -1,50 +0,0 @@
1
- import {
2
- bytes32ToString,
3
- ChainContractsRegister,
4
- CreditFacadeV310BaseContract,
5
- isV310
6
- } from "../sdk/index.js";
7
- class ContractRegister {
8
- #client;
9
- #logger;
10
- #register;
11
- #factories = [];
12
- constructor(client, logger) {
13
- this.#client = client;
14
- this.#logger = logger;
15
- this.#register = ChainContractsRegister.for(client, logger);
16
- }
17
- get register() {
18
- return this.#register;
19
- }
20
- registerFactory(factory) {
21
- this.#factories.push(factory);
22
- }
23
- createContract(args) {
24
- const { addr, version } = args;
25
- const existing = this.#register.getContract(addr);
26
- if (existing) {
27
- return existing;
28
- }
29
- const contractType = bytes32ToString(args.contractType);
30
- if (contractType === "CREDIT_FACADE" && isV310(version)) {
31
- return new CreditFacadeV310BaseContract(
32
- { client: this.#client, logger: this.#logger },
33
- { ...args, name: `CreditFacadeV310(${addr})` }
34
- );
35
- }
36
- for (const factory of this.#factories) {
37
- const contract = factory(
38
- { client: this.#client, logger: this.#logger },
39
- args
40
- );
41
- if (contract) {
42
- return contract;
43
- }
44
- }
45
- throw new Error(`unknown contract ${contractType} v${version}`);
46
- }
47
- }
48
- export {
49
- ContractRegister
50
- };
@@ -1,11 +0,0 @@
1
- import type { Chain, PublicClient, Transport } from "viem";
2
- import type { ConstructOptions, IBaseContract, ILogger, TypedVersionedAddress } from "../sdk/index.js";
3
- import { ChainContractsRegister } from "../sdk/index.js";
4
- export type ContractFactory = (options: ConstructOptions, args: TypedVersionedAddress) => IBaseContract;
5
- export declare class ContractRegister {
6
- #private;
7
- constructor(client: PublicClient<Transport, Chain>, logger?: ILogger);
8
- get register(): ChainContractsRegister;
9
- registerFactory(factory: ContractFactory): void;
10
- createContract(args: TypedVersionedAddress): IBaseContract;
11
- }