@gearbox-protocol/sdk 13.0.0-beta.3 → 13.0.0-beta.4

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.
Files changed (53) hide show
  1. package/dist/cjs/abi/iPriceFeed.js +84 -0
  2. package/dist/cjs/permissionless/bindings/cross-chain-multisig.js +3 -3
  3. package/dist/cjs/permissionless/bindings/instance-manager.js +2 -2
  4. package/dist/cjs/plugins/adapters/contracts/MellowDepositQueueAdapterContract.js +0 -6
  5. package/dist/cjs/plugins/adapters/contracts/MellowRedeemQueueAdapterContract.js +0 -6
  6. package/dist/cjs/sdk/GearboxSDK.js +0 -2
  7. package/dist/cjs/sdk/base/BaseContract.js +5 -2
  8. package/dist/cjs/sdk/base/ChainContractsRegister.js +2 -10
  9. package/dist/cjs/sdk/base/Construct.js +25 -19
  10. package/dist/cjs/sdk/base/SDKConstruct.js +1 -1
  11. package/dist/cjs/sdk/market/adapters/PlaceholderAdapterContracts.js +16 -0
  12. package/dist/cjs/sdk/market/pricefeeds/updates/PriceUpdatesCache.js +0 -17
  13. package/dist/cjs/sdk/market/pricefeeds/updates/PythUpdater.js +1 -1
  14. package/dist/cjs/sdk/market/pricefeeds/updates/RedstoneUpdater.js +1 -1
  15. package/dist/cjs/sdk/market/pricefeeds/updates/fetchPythPayloads.js +2 -2
  16. package/dist/cjs/sdk/utils/assetsMath.js +10 -9
  17. package/dist/cjs/sdk/utils/creditAccount.js +42 -40
  18. package/dist/cjs/sdk/utils/endpoints.js +2 -2
  19. package/dist/cjs/sdk/utils/formatter.js +3 -3
  20. package/dist/cjs/sdk/utils/priceMath.js +3 -3
  21. package/dist/esm/abi/iPriceFeed.js +60 -0
  22. package/dist/esm/permissionless/bindings/cross-chain-multisig.js +3 -3
  23. package/dist/esm/permissionless/bindings/instance-manager.js +2 -2
  24. package/dist/esm/plugins/adapters/contracts/MellowDepositQueueAdapterContract.js +0 -6
  25. package/dist/esm/plugins/adapters/contracts/MellowRedeemQueueAdapterContract.js +0 -6
  26. package/dist/esm/sdk/GearboxSDK.js +0 -2
  27. package/dist/esm/sdk/base/BaseContract.js +5 -2
  28. package/dist/esm/sdk/base/ChainContractsRegister.js +2 -10
  29. package/dist/esm/sdk/base/Construct.js +25 -19
  30. package/dist/esm/sdk/base/SDKConstruct.js +1 -1
  31. package/dist/esm/sdk/market/adapters/PlaceholderAdapterContracts.js +16 -0
  32. package/dist/esm/sdk/market/pricefeeds/updates/PriceUpdatesCache.js +0 -17
  33. package/dist/esm/sdk/market/pricefeeds/updates/PythUpdater.js +1 -1
  34. package/dist/esm/sdk/market/pricefeeds/updates/RedstoneUpdater.js +1 -1
  35. package/dist/esm/sdk/market/pricefeeds/updates/fetchPythPayloads.js +2 -2
  36. package/dist/esm/sdk/utils/assetsMath.js +2 -1
  37. package/dist/esm/sdk/utils/creditAccount.js +3 -3
  38. package/dist/esm/sdk/utils/endpoints.js +1 -1
  39. package/dist/esm/sdk/utils/formatter.js +1 -1
  40. package/dist/esm/sdk/utils/priceMath.js +1 -1
  41. package/dist/types/abi/iPriceFeed.d.ts +87 -0
  42. package/dist/types/permissionless/bindings/cross-chain-multisig.d.ts +3 -3
  43. package/dist/types/permissionless/bindings/instance-manager.d.ts +3 -3
  44. package/dist/types/plugins/adapters/contracts/MellowDepositQueueAdapterContract.d.ts +1 -4
  45. package/dist/types/plugins/adapters/contracts/MellowRedeemQueueAdapterContract.d.ts +1 -4
  46. package/dist/types/sdk/base/ChainContractsRegister.d.ts +0 -2
  47. package/dist/types/sdk/base/Construct.d.ts +7 -10
  48. package/dist/types/sdk/market/adapters/PlaceholderAdapterContracts.d.ts +2 -1
  49. package/dist/types/sdk/market/pricefeeds/updates/PriceUpdatesCache.d.ts +1 -8
  50. package/dist/types/sdk/utils/assetsMath.d.ts +1 -1
  51. package/dist/types/sdk/utils/creditAccount.d.ts +1 -1
  52. package/dist/types/sdk/utils/endpoints.d.ts +1 -1
  53. package/package.json +6 -2
@@ -0,0 +1,84 @@
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 iPriceFeed_exports = {};
20
+ __export(iPriceFeed_exports, {
21
+ iPriceFeedAbi: () => iPriceFeedAbi
22
+ });
23
+ module.exports = __toCommonJS(iPriceFeed_exports);
24
+ const iPriceFeedAbi = [
25
+ {
26
+ type: "function",
27
+ name: "contractType",
28
+ inputs: [],
29
+ outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
30
+ stateMutability: "view"
31
+ },
32
+ {
33
+ type: "function",
34
+ name: "decimals",
35
+ inputs: [],
36
+ outputs: [{ name: "", type: "uint8", internalType: "uint8" }],
37
+ stateMutability: "view"
38
+ },
39
+ {
40
+ type: "function",
41
+ name: "description",
42
+ inputs: [],
43
+ outputs: [{ name: "", type: "string", internalType: "string" }],
44
+ stateMutability: "view"
45
+ },
46
+ {
47
+ type: "function",
48
+ name: "latestRoundData",
49
+ inputs: [],
50
+ outputs: [
51
+ { name: "", type: "uint80", internalType: "uint80" },
52
+ { name: "answer", type: "int256", internalType: "int256" },
53
+ { name: "", type: "uint256", internalType: "uint256" },
54
+ { name: "updatedAt", type: "uint256", internalType: "uint256" },
55
+ { name: "", type: "uint80", internalType: "uint80" }
56
+ ],
57
+ stateMutability: "view"
58
+ },
59
+ {
60
+ type: "function",
61
+ name: "serialize",
62
+ inputs: [],
63
+ outputs: [{ name: "serializedData", type: "bytes", internalType: "bytes" }],
64
+ stateMutability: "view"
65
+ },
66
+ {
67
+ type: "function",
68
+ name: "skipPriceCheck",
69
+ inputs: [],
70
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
71
+ stateMutability: "view"
72
+ },
73
+ {
74
+ type: "function",
75
+ name: "version",
76
+ inputs: [],
77
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
78
+ stateMutability: "view"
79
+ }
80
+ ];
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ iPriceFeedAbi
84
+ });
@@ -31,8 +31,8 @@ var import_instance_manager = require("./instance-manager.js");
31
31
  var import_market_configurator_factory = require("./market-configurator-factory.js");
32
32
  const abi = import_crossChainMultisig.crossChainMultisigAbi;
33
33
  class CrossChainMultisigContract extends import_sdk.BaseContract {
34
- constructor(addr, client) {
35
- super({ client }, { abi, addr, name: "CrossChainMultisig" });
34
+ constructor(addr, register) {
35
+ super({ register }, { abi, addr, name: "CrossChainMultisig" });
36
36
  }
37
37
  async getExecutedBatches(fromBlock, toBlock) {
38
38
  const events = await this.getEvents("ExecuteBatch", fromBlock, toBlock);
@@ -185,7 +185,7 @@ class CrossChainMultisigContract extends import_sdk.BaseContract {
185
185
  case import_addresses.Addresses.INSTANCE_MANAGER.toLowerCase(): {
186
186
  const instanceManager = new import_instance_manager.InstanceManagerContract(
187
187
  target,
188
- this.client
188
+ this.register
189
189
  );
190
190
  return instanceManager.parseFunctionData(calldata);
191
191
  }
@@ -38,8 +38,8 @@ var import_router = require("./router/index.js");
38
38
  var import_treasury_splitter = require("./treasury-splitter.js");
39
39
  const abi = import_instanceManager.instanceManagerAbi;
40
40
  class InstanceManagerContract extends import_sdk.BaseContract {
41
- constructor(addr, client) {
42
- super({ client }, { abi, addr, name: "InstanceManager" });
41
+ constructor(addr, register) {
42
+ super({ register }, { abi, addr, name: "InstanceManager" });
43
43
  }
44
44
  // TODO:
45
45
  #decodeFunctionData(target, calldata) {
@@ -69,12 +69,6 @@ class MellowDepositQueueAdapterContract extends import_AbstractAdapter.AbstractA
69
69
  referral: this.#referral ? this.labelAddress(this.#referral) : void 0
70
70
  };
71
71
  }
72
- /** Legacy adapter not present in integrations-v3. */
73
- classifyLegacyOperation(_parsed, _transfers) {
74
- throw new Error(
75
- `classifyLegacyOperation is not supported for legacy adapter: ${this.contractType}`
76
- );
77
- }
78
72
  }
79
73
  // Annotate the CommonJS export names for ESM import in node:
80
74
  0 && (module.exports = {
@@ -61,12 +61,6 @@ class MellowRedeemQueueAdapterContract extends import_AbstractAdapter.AbstractAd
61
61
  phantomToken: this.#phantomToken ? this.labelAddress(this.#phantomToken) : void 0
62
62
  };
63
63
  }
64
- /** Legacy adapter not present in integrations-v3. */
65
- classifyLegacyOperation(_parsed, _transfers) {
66
- throw new Error(
67
- `classifyLegacyOperation is not supported for legacy adapter: ${this.contractType}`
68
- );
69
- }
70
64
  }
71
65
  // Annotate the CommonJS export names for ESM import in node:
72
66
  0 && (module.exports = {
@@ -153,8 +153,6 @@ class GearboxSDK extends import_base.ChainContractsRegister {
153
153
  if (options.gasLimit !== null) {
154
154
  this.gasLimit = options.gasLimit || 550000000n;
155
155
  }
156
- Object.assign(this, import_base.ChainContractsRegister.for(this.client, this.logger));
157
- this.resetContracts();
158
156
  }
159
157
  async #attach(opts) {
160
158
  const {
@@ -67,8 +67,11 @@ class BaseContract extends import_Construct.Construct {
67
67
  this.contractType = (0, import_utils.bytes32ToString)(this.contractType);
68
68
  }
69
69
  this.name = args.name || this.contractType || this.address || this.constructor.name;
70
- this.register.setContract(this.address, this);
71
- this.register.setAddressLabel(this.address, this.name);
70
+ const register = this.safeGetRegister();
71
+ if (register) {
72
+ register.setContract(this.address, this);
73
+ register.setAddressLabel(this.address, this.name);
74
+ }
72
75
  }
73
76
  stateHuman(_ = true) {
74
77
  return {
@@ -25,16 +25,6 @@ var import_addresses = require("../constants/addresses.js");
25
25
  var import_AddressMap = require("../utils/AddressMap.js");
26
26
  var import_TokensMeta = require("./TokensMeta.js");
27
27
  class ChainContractsRegister {
28
- static #chains = /* @__PURE__ */ new Map();
29
- static for(client, logger) {
30
- const chainId = client.chain.id;
31
- let result = ChainContractsRegister.#chains.get(chainId);
32
- if (!result) {
33
- result = new ChainContractsRegister(client, logger);
34
- ChainContractsRegister.#chains.set(chainId, result);
35
- }
36
- return result;
37
- }
38
28
  contracts = new import_AddressMap.AddressMap(
39
29
  [],
40
30
  "contracts"
@@ -55,7 +45,9 @@ class ChainContractsRegister {
55
45
  this.logger?.debug(
56
46
  `resetting contacts register with ${this.contracts.size} contracts`
57
47
  );
48
+ this.labels.clear();
58
49
  this.contracts.clear();
50
+ this.tokensMeta.reset();
59
51
  }
60
52
  getContract(address) {
61
53
  return this.contracts.get(address);
@@ -26,27 +26,41 @@ var import_ChainContractsRegister = require("./ChainContractsRegister.js");
26
26
  class Construct {
27
27
  logger;
28
28
  client;
29
- register;
29
+ #register;
30
30
  /**
31
31
  * Indicates that contract state needs to be updated
32
32
  */
33
33
  #dirty = false;
34
34
  constructor(options) {
35
- const { logger } = options;
36
- if ("client" in options) {
37
- const { client } = options;
38
- this.client = client;
39
- this.register = import_ChainContractsRegister.ChainContractsRegister.for(client, logger);
35
+ if (options instanceof import_ChainContractsRegister.ChainContractsRegister) {
36
+ this.#register = options;
37
+ this.client = options.client;
38
+ } else if ("register" in options) {
39
+ this.#register = options.register;
40
+ this.client = options.register.client;
40
41
  } else {
41
- const { register } = options;
42
- this.register = register;
43
- this.client = register.client;
42
+ this.client = options.client;
44
43
  }
45
44
  this.logger = (0, import_utils.childLogger)(
46
45
  this.constructor.name,
47
- this.register.logger ?? logger
46
+ this.#register?.logger ?? options.logger
48
47
  );
49
48
  }
49
+ /**
50
+ * Throws if register was not provided in constructor options
51
+ * Ephemeral contracts that do not need to access other contracts may not need it
52
+ */
53
+ get register() {
54
+ if (!this.#register) {
55
+ throw new Error(
56
+ "contracts register not available, it must be provided if contract needs to access other contracts"
57
+ );
58
+ }
59
+ return this.#register;
60
+ }
61
+ safeGetRegister() {
62
+ return this.#register;
63
+ }
50
64
  get chain() {
51
65
  return this.client.chain;
52
66
  }
@@ -68,19 +82,11 @@ class Construct {
68
82
  set dirty(value) {
69
83
  this.#dirty = value;
70
84
  }
71
- /**
72
- * Syntax sugar for rgister.tokensMeta
73
- */
74
85
  get tokensMeta() {
75
86
  return this.register.tokensMeta;
76
87
  }
77
- /**
78
- * Syntax suggar for getting contract labels
79
- * @param address
80
- * @returns
81
- */
82
88
  labelAddress(address, omitAddress) {
83
- return this.register.labelAddress(address, omitAddress);
89
+ return this.#register?.labelAddress(address, omitAddress) ?? address;
84
90
  }
85
91
  /**
86
92
  * Returns list of addresses that should be watched for events to sync state
@@ -25,7 +25,7 @@ var import_Construct = require("./Construct.js");
25
25
  class SDKConstruct extends import_Construct.Construct {
26
26
  sdk;
27
27
  constructor(sdk) {
28
- super(sdk);
28
+ super({ register: sdk });
29
29
  this.sdk = sdk;
30
30
  }
31
31
  }
@@ -21,11 +21,21 @@ __export(PlaceholderAdapterContracts_exports, {
21
21
  PlaceholderAdapterContract: () => PlaceholderAdapterContract
22
22
  });
23
23
  module.exports = __toCommonJS(PlaceholderAdapterContracts_exports);
24
+ var import_viem = require("viem");
24
25
  var import_base = require("../../base/index.js");
25
26
  class PlaceholderAdapterContract extends import_base.PlaceholderContract {
26
27
  #targetContract;
28
+ #creditManager;
27
29
  constructor(options, args) {
28
30
  super(options, args.baseParams);
31
+ if (args.baseParams.serializedParams) {
32
+ const [cm, tc] = (0, import_viem.decodeAbiParameters)(
33
+ [{ type: "address" }, { type: "address" }],
34
+ args.baseParams.serializedParams
35
+ );
36
+ this.#creditManager = cm;
37
+ this.#targetContract = tc;
38
+ }
29
39
  }
30
40
  get targetContract() {
31
41
  if (!this.#targetContract) {
@@ -33,6 +43,12 @@ class PlaceholderAdapterContract extends import_base.PlaceholderContract {
33
43
  }
34
44
  return this.#targetContract;
35
45
  }
46
+ get creditManager() {
47
+ if (!this.#creditManager) {
48
+ throw new import_base.MissingSerializedParamsError("creditManager");
49
+ }
50
+ return this.#creditManager;
51
+ }
36
52
  }
37
53
  // Annotate the CommonJS export names for ESM import in node:
38
54
  0 && (module.exports = {
@@ -22,23 +22,6 @@ __export(PriceUpdatesCache_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(PriceUpdatesCache_exports);
24
24
  class PriceUpdatesCache {
25
- static #caches = /* @__PURE__ */ new Map();
26
- /**
27
- * Price update caches can be shared across networks
28
- * @param id - unique key to identify the cache
29
- * @param opts
30
- * @returns
31
- */
32
- static get(id, opts) {
33
- const key = `${id}:${opts.historical ? "historical" : "latest"}:${opts.ttl}`;
34
- const cache = PriceUpdatesCache.#caches.get(key);
35
- if (cache) {
36
- return cache;
37
- }
38
- const newCache = new PriceUpdatesCache(opts);
39
- PriceUpdatesCache.#caches.set(key, newCache);
40
- return newCache;
41
- }
42
25
  #cache = /* @__PURE__ */ new Map();
43
26
  #ttlMs;
44
27
  #historical;
@@ -68,7 +68,7 @@ class PythUpdater extends import_base.SDKConstruct {
68
68
  `using historical timestamp ${this.#historicalTimestamp}`
69
69
  );
70
70
  }
71
- this.#cache = import_PriceUpdatesCache.PriceUpdatesCache.get("pyth", {
71
+ this.#cache = new import_PriceUpdatesCache.PriceUpdatesCache({
72
72
  // currently staleness period is 240 seconds on all networks, add some buffer
73
73
  // this period of 4 minutes is selected based on time that is required for user to sign transaction with wallet
74
74
  // so it's unlikely to decrease
@@ -76,7 +76,7 @@ class RedstoneUpdater extends import_base.SDKConstruct {
76
76
  `using historical timestamp ${this.#historicalTimestampMs}`
77
77
  );
78
78
  }
79
- this.#cache = import_PriceUpdatesCache.PriceUpdatesCache.get("redstone", {
79
+ this.#cache = new import_PriceUpdatesCache.PriceUpdatesCache({
80
80
  // currently staleness period is 240 seconds on all networks, add some buffer
81
81
  // this period of 4 minutes is selected based on time that is required for user to sign transaction with wallet
82
82
  // so it's unlikely to decrease
@@ -35,7 +35,7 @@ async function fetchPythPayloads(options) {
35
35
  customFetch = fetch,
36
36
  returnPrices
37
37
  } = options;
38
- const ids = Array.from(new Set(dataFeedsIds));
38
+ const ids = Array.from(new Set(dataFeedsIds)).sort();
39
39
  if (ids.length === 0) {
40
40
  return [];
41
41
  }
@@ -46,7 +46,7 @@ async function fetchPythPayloads(options) {
46
46
  if (ignoreMissingFeeds) {
47
47
  url.searchParams.append("ignore_invalid_price_ids", "true");
48
48
  }
49
- for (const id of dataFeedsIds) {
49
+ for (const id of ids) {
50
50
  url.searchParams.append("ids[]", id);
51
51
  }
52
52
  const resp = await (0, import_utils.retry)(
@@ -21,8 +21,9 @@ __export(assetsMath_exports, {
21
21
  AssetUtils: () => AssetUtils
22
22
  });
23
23
  module.exports = __toCommonJS(assetsMath_exports);
24
- var import__ = require("../index.js");
24
+ var import_bigintMath = require("./bigintMath.js");
25
25
  var import_creditAccount = require("./creditAccount.js");
26
+ var import_priceMath = require("./priceMath.js");
26
27
  class AssetUtils {
27
28
  static nextAsset({
28
29
  allowedTokens,
@@ -77,10 +78,10 @@ class AssetUtils {
77
78
  const unwrappedPrice = prices[unwrappedAddress] || 0n;
78
79
  const wrappedToken = tokensList[wrappedAddress];
79
80
  const wrappedPrice = prices[wrappedAddress] || 0n;
80
- const unwrappedInWrapped = import__.PriceUtils.convertByPrice(
81
- import__.PriceUtils.calcTotalPrice(
81
+ const unwrappedInWrapped = import_priceMath.PriceUtils.convertByPrice(
82
+ import_priceMath.PriceUtils.calcTotalPrice(
82
83
  unwrappedPrice,
83
- import__.BigIntMath.max(0n, unwrappedAmount),
84
+ import_bigintMath.BigIntMath.max(0n, unwrappedAmount),
84
85
  unwrappedToken.decimals
85
86
  ),
86
87
  {
@@ -90,7 +91,7 @@ class AssetUtils {
90
91
  );
91
92
  assetsRecord[wrappedAddress] = {
92
93
  token: wrappedAddress,
93
- balance: import__.BigIntMath.max(0n, wrappedAmount) + unwrappedInWrapped
94
+ balance: import_bigintMath.BigIntMath.max(0n, wrappedAmount) + unwrappedInWrapped
94
95
  };
95
96
  delete assetsRecord[unwrappedAddress];
96
97
  return [Object.values(assetsRecord), unwrappedInWrapped, wrappedAmount];
@@ -106,7 +107,7 @@ class AssetUtils {
106
107
  const resRecord = b.reduce((acc, bAsset) => {
107
108
  const aAsset = acc[bAsset.token];
108
109
  const { balance: amount = 0n } = aAsset || {};
109
- const amountSum = import__.BigIntMath.max(0n, bAsset.balance) + import__.BigIntMath.max(0n, amount);
110
+ const amountSum = import_bigintMath.BigIntMath.max(0n, bAsset.balance) + import_bigintMath.BigIntMath.max(0n, amount);
110
111
  const aOrB = aAsset || bAsset;
111
112
  acc[bAsset.token] = {
112
113
  ...aOrB,
@@ -125,7 +126,7 @@ class AssetUtils {
125
126
  return a.map((asset) => {
126
127
  const bAsset = bRecord[asset.token];
127
128
  const { balance: bAmount = 0n } = bAsset || {};
128
- const amountSum = import__.BigIntMath.max(0n, asset.balance) + import__.BigIntMath.max(0n, bAmount);
129
+ const amountSum = import_bigintMath.BigIntMath.max(0n, asset.balance) + import_bigintMath.BigIntMath.max(0n, bAmount);
129
130
  return { ...asset, balance: amountSum };
130
131
  });
131
132
  }
@@ -138,8 +139,8 @@ class AssetUtils {
138
139
  return a.map((asset) => {
139
140
  const bAsset = bRecord[asset.token];
140
141
  const { balance: bAmount = 0n } = bAsset || {};
141
- const amountSub = import__.BigIntMath.max(0n, asset.balance) - import__.BigIntMath.max(0n, bAmount);
142
- return { ...asset, balance: import__.BigIntMath.max(0n, amountSub) };
142
+ const amountSub = import_bigintMath.BigIntMath.max(0n, asset.balance) - import_bigintMath.BigIntMath.max(0n, bAmount);
143
+ return { ...asset, balance: import_bigintMath.BigIntMath.max(0n, amountSub) };
143
144
  });
144
145
  }
145
146
  }