@gearbox-protocol/sdk 14.1.1 → 15.0.0-next.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.
Files changed (30) hide show
  1. package/dist/cjs/plugins/accounts/AccountsPlugin.js +1 -2
  2. package/dist/cjs/sdk/OnchainSDK.js +12 -0
  3. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +1448 -23
  4. package/dist/cjs/sdk/accounts/index.js +0 -4
  5. package/dist/cjs/sdk/market/credit/CreditFacadeV310Contract.js +6 -0
  6. package/dist/cjs/sdk/market/oracle/PriceOracleV310Contract.js +26 -0
  7. package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -0
  8. package/dist/esm/plugins/accounts/AccountsPlugin.js +2 -7
  9. package/dist/esm/sdk/OnchainSDK.js +14 -0
  10. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +1466 -23
  11. package/dist/esm/sdk/accounts/index.js +0 -2
  12. package/dist/esm/sdk/accounts/multicall-utils.js +1 -5
  13. package/dist/esm/sdk/market/credit/CreditFacadeV310Contract.js +6 -0
  14. package/dist/esm/sdk/market/oracle/PriceOracleV310Contract.js +26 -0
  15. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -0
  16. package/dist/types/sdk/OnchainSDK.d.ts +10 -0
  17. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +181 -3
  18. package/dist/types/sdk/accounts/index.d.ts +0 -2
  19. package/dist/types/sdk/accounts/types.d.ts +56 -0
  20. package/dist/types/sdk/market/credit/CreditFacadeV310Contract.d.ts +2 -0
  21. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +5 -0
  22. package/dist/types/sdk/market/oracle/PriceOracleV310Contract.d.ts +4 -0
  23. package/dist/types/sdk/market/oracle/types.d.ts +9 -0
  24. package/package.json +1 -1
  25. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +0 -1411
  26. package/dist/cjs/sdk/accounts/createCreditAccountService.js +0 -35
  27. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +0 -1405
  28. package/dist/esm/sdk/accounts/createCreditAccountService.js +0 -11
  29. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +0 -226
  30. package/dist/types/sdk/accounts/createCreditAccountService.d.ts +0 -9
@@ -15,14 +15,10 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
15
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
16
  var accounts_exports = {};
17
17
  module.exports = __toCommonJS(accounts_exports);
18
- __reExport(accounts_exports, require("./AbstractCreditAccountsService.js"), module.exports);
19
18
  __reExport(accounts_exports, require("./CreditAccountsServiceV310.js"), module.exports);
20
- __reExport(accounts_exports, require("./createCreditAccountService.js"), module.exports);
21
19
  __reExport(accounts_exports, require("./types.js"), module.exports);
22
20
  // Annotate the CommonJS export names for ESM import in node:
23
21
  0 && (module.exports = {
24
- ...require("./AbstractCreditAccountsService.js"),
25
22
  ...require("./CreditAccountsServiceV310.js"),
26
- ...require("./createCreditAccountService.js"),
27
23
  ...require("./types.js")
28
24
  });
@@ -79,6 +79,12 @@ class CreditFacadeV310Contract extends import_CreditFacadeV310BaseContract.Credi
79
79
  args: lossPolicyData ? [ca, to, calls, lossPolicyData] : [ca, to, calls]
80
80
  });
81
81
  }
82
+ partiallyLiquidateCreditAccount(ca, token, repaidAmount, minSeizedAmount, to, updates) {
83
+ return this.createRawTx({
84
+ functionName: "partiallyLiquidateCreditAccount",
85
+ args: [ca, token, repaidAmount, minSeizedAmount, to, updates]
86
+ });
87
+ }
82
88
  closeCreditAccount(ca, calls) {
83
89
  return this.createRawTx({
84
90
  functionName: "closeCreditAccount",
@@ -23,6 +23,7 @@ __export(PriceOracleV310Contract_exports, {
23
23
  module.exports = __toCommonJS(PriceOracleV310Contract_exports);
24
24
  var import_viem = require("viem");
25
25
  var import_generated = require("../../../abi/310/generated.js");
26
+ var import_simulateWithPriceUpdates = require("../../utils/viem/simulateWithPriceUpdates.js");
26
27
  var import_pricefeeds = require("../pricefeeds/index.js");
27
28
  var import_PriceOracleBaseContract = require("./PriceOracleBaseContract.js");
28
29
  const abi = import_generated.iPriceOracleV310Abi;
@@ -64,6 +65,31 @@ class PriceOracleV310Contract extends import_PriceOracleBaseContract.PriceOracle
64
65
  ]
65
66
  };
66
67
  }
68
+ /**
69
+ * {@inheritDoc IPriceOracleContract.updateAndConvert}
70
+ **/
71
+ async updateAndConvert(from, to, amount) {
72
+ const fromFeed = this.mainPriceFeeds.mustGet(from).priceFeed;
73
+ const toFeed = this.mainPriceFeeds.mustGet(to).priceFeed;
74
+ const updates = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs([
75
+ fromFeed,
76
+ toFeed
77
+ ]);
78
+ const [result] = await (0, import_simulateWithPriceUpdates.simulateWithPriceUpdates)(this.sdk.client, {
79
+ priceUpdates: updates.txs,
80
+ contracts: [
81
+ {
82
+ abi: this.contract.abi,
83
+ functionName: "convert",
84
+ args: [amount, from, to],
85
+ address: this.contract.address
86
+ }
87
+ ],
88
+ strictPrices: true,
89
+ gas: this.sdk.gasLimit
90
+ });
91
+ return result;
92
+ }
67
93
  processLog(log) {
68
94
  switch (log.eventName) {
69
95
  case "SetPriceFeed":
@@ -101,6 +101,9 @@ class PriceFeedRegister extends import_base.SDKConstruct {
101
101
  updateables = this.sdk.marketRegister.priceOracles.flatMap((o) => o.reservePriceFeeds.values()).flatMap((pf) => pf.priceFeed.updatableDependencies());
102
102
  }
103
103
  }
104
+ if (updateables.length === 0) {
105
+ return { txs: [], timestamp: 0 };
106
+ }
104
107
  const txs = [];
105
108
  const latestUpdate = {
106
109
  updates: [],
@@ -1,8 +1,4 @@
1
- import {
2
- AddressMap,
3
- BasePlugin,
4
- createCreditAccountService
5
- } from "../../sdk/index.js";
1
+ import { AddressMap, BasePlugin } from "../../sdk/index.js";
6
2
  class AccountsPlugin extends BasePlugin {
7
3
  #accounts;
8
4
  #byCreditManager;
@@ -31,8 +27,7 @@ class AccountsPlugin extends BasePlugin {
31
27
  if (!force && this.loaded) {
32
28
  return this.state;
33
29
  }
34
- const service = createCreditAccountService(this.sdk, 310);
35
- const accounts = await service.getCreditAccounts(
30
+ const accounts = await this.sdk.accounts.getCreditAccounts(
36
31
  this.#options,
37
32
  this.sdk.currentBlock
38
33
  );
@@ -4,6 +4,9 @@ import {
4
4
  http,
5
5
  parseEventLogs
6
6
  } from "viem";
7
+ import {
8
+ CreditAccountsServiceV310
9
+ } from "./accounts/index.js";
7
10
  import { ChainContractsRegister } from "./base/index.js";
8
11
  import { getChain } from "./chain/index.js";
9
12
  import {
@@ -26,6 +29,7 @@ import { KYCRegistry } from "./market/index.js";
26
29
  import { MarketRegister } from "./market/MarketRegister.js";
27
30
  import { PriceFeedRegister } from "./market/pricefeeds/index.js";
28
31
  import { PluginStateVersionError } from "./plugins/index.js";
32
+ import { PoolService } from "./pools/index.js";
29
33
  import { createRouter } from "./router/index.js";
30
34
  import { formatTimestamp, TypedObjectUtils, toAddress } from "./utils/index.js";
31
35
  import {
@@ -70,6 +74,14 @@ class OnchainSDK extends ChainContractsRegister {
70
74
  * When `true`, the SDK throws on unrecognised contract types.
71
75
  **/
72
76
  strictContractTypes;
77
+ /**
78
+ * Namespace for credit accounts operations.
79
+ */
80
+ accounts;
81
+ /**
82
+ * Namespace for pool operations.
83
+ */
84
+ pools;
73
85
  /**
74
86
  * @param network - Gearbox network type (e.g. `"Mainnet"`, `"Monad"`).
75
87
  * @param clientOptions - Connection options (RPC URLs, transport, or client).
@@ -94,6 +106,8 @@ class OnchainSDK extends ChainContractsRegister {
94
106
  if (options?.gasLimit !== null) {
95
107
  this.gasLimit = options?.gasLimit ?? getChain(this.networkType).gasLimit;
96
108
  }
109
+ this.accounts = new CreditAccountsServiceV310(this);
110
+ this.pools = new PoolService(this);
97
111
  }
98
112
  /**
99
113
  * Initialises the SDK by reading live on-chain state.