@gearbox-protocol/sdk 13.7.0-kyc.3 → 13.7.0-kyc.5

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.
@@ -87,8 +87,14 @@ const revolverTransportConfigSchema = import_v4.z.union([
87
87
  })
88
88
  ]);
89
89
  class NoAvailableTransportsError extends import_viem.BaseError {
90
- constructor(cause) {
91
- super("no available transports", { cause });
90
+ statuses;
91
+ constructor(statuses, cause) {
92
+ super("No available transports", {
93
+ cause,
94
+ metaMessages: statuses.length > 0 ? statuses.map((s) => `- ${s.id}: ${s.status}`) : ["No transports configured"],
95
+ name: "NoAvailableTransportsError"
96
+ });
97
+ this.statuses = statuses;
92
98
  }
93
99
  }
94
100
  class RevolverTransport {
@@ -146,7 +152,7 @@ class RevolverTransport {
146
152
  );
147
153
  }
148
154
  if (transports.length === 0) {
149
- throw new NoAvailableTransportsError();
155
+ throw new NoAvailableTransportsError([]);
150
156
  }
151
157
  this.#isSingle = transports.length === 1;
152
158
  const selectionStrategy = config.selectionStrategy ?? "simple";
@@ -197,7 +203,7 @@ class RevolverTransport {
197
203
  }
198
204
  } while (this.#selector.canRotate());
199
205
  this.#requests.delete(r);
200
- throw new NoAvailableTransportsError(error);
206
+ throw new NoAvailableTransportsError(this.#selector.statuses(), error);
201
207
  };
202
208
  get config() {
203
209
  return {
@@ -43,7 +43,9 @@ const RANGE_ERROR_PATTERNS = [
43
43
  /eth_getLogs is limited to/i,
44
44
  /eth_getLogs requests with up to/i,
45
45
  /range is too large/i,
46
- /exceeded max allowed range/i
46
+ /exceeded max allowed range/i,
47
+ // Encountered on DRPC: "query exceeds max results 20000, retry with the range …"
48
+ /exceeds max results/i
47
49
  ];
48
50
  function isRangeError(error) {
49
51
  const msg = errorMessage(error);
@@ -51,10 +53,17 @@ function isRangeError(error) {
51
53
  }
52
54
  const GENERIC_BLOCKS_RE = /(\d+)\s*block/i;
53
55
  const ALCHEMY_RANGE_RE = /this block range should work: \[(0x[0-9a-fA-F]+),\s*(0x[0-9a-fA-F]+)\]/;
56
+ const DRPC_RANGE_RE = /retry with the range (\d+)-(\d+)/;
54
57
  function parsePageSizeHint(error) {
55
58
  const alchemy = tryAlchemyHint(error);
56
59
  if (alchemy != null) return alchemy;
57
60
  const msg = errorMessage(error);
61
+ const drpc = msg.match(DRPC_RANGE_RE);
62
+ if (drpc) {
63
+ const from = Number(drpc[1]);
64
+ const to = Number(drpc[2]);
65
+ return to - from + 1;
66
+ }
58
67
  const m = msg.match(GENERIC_BLOCKS_RE);
59
68
  return m ? Number(m[1]) : null;
60
69
  }
@@ -35,7 +35,6 @@ var import_base = require("../base/index.js");
35
35
  var import_chains = require("../chain/chains.js");
36
36
  var import_constants = require("../constants/index.js");
37
37
  var import_market = require("../market/index.js");
38
- var import_kyc = require("../market/kyc/index.js");
39
38
  var import_router = require("../router/index.js");
40
39
  var import_utils = require("../utils/index.js");
41
40
  var import_viem2 = require("../utils/viem/index.js");
@@ -817,13 +816,12 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
817
816
  /**
818
817
  * {@inheritDoc ICreditAccountsService.getOpenAccountRequirements}
819
818
  */
820
- async getOpenAccountRequirements(borrower, props) {
821
- const { creditManager } = props;
819
+ async getOpenAccountRequirements(borrower, creditManager, props) {
822
820
  const { kycFactory } = this.sdk.marketRegister.findByCreditManager(creditManager);
823
821
  if (!kycFactory) {
824
822
  return void 0;
825
823
  }
826
- return kycFactory.getOpenAccountRequirements(borrower);
824
+ return kycFactory.getOpenAccountRequirements(borrower, props);
827
825
  }
828
826
  /**
829
827
  * {@inheritDoc ICreditAccountsService.openCA}
@@ -1338,19 +1336,21 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
1338
1336
  * @param to
1339
1337
  * @param calls
1340
1338
  * @param referralCode
1339
+ * @param kycOptions
1341
1340
  * @returns
1342
1341
  */
1343
- async openCreditAccountTx(suite, to, calls, referralCode) {
1342
+ async openCreditAccountTx(suite, to, calls, referralCode, kycOptions) {
1344
1343
  const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
1345
1344
  const factory = marketSuite.kycFactory;
1346
- if (factory && (0, import_kyc.isKYCFactory)(factory, import_kyc.KYC_FACTORY_SECURITIZE)) {
1347
- const tokensToRegister = factory.dsTokens.map(
1348
- (t) => t.address
1345
+ if (factory) {
1346
+ if (!kycOptions) {
1347
+ throw new Error("KYC options are required for KYC factories");
1348
+ }
1349
+ return factory.openCreditAccount(
1350
+ suite.creditManager.address,
1351
+ calls,
1352
+ kycOptions
1349
1353
  );
1350
- return factory.openCreditAccount(suite.creditManager.address, calls, {
1351
- tokensToRegister,
1352
- signaturesToCache: []
1353
- });
1354
1354
  }
1355
1355
  return suite.creditFacade.openCreditAccount(to, calls, referralCode ?? 0n);
1356
1356
  }
@@ -1359,15 +1359,19 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
1359
1359
  * @param suite
1360
1360
  * @param creditAccount
1361
1361
  * @param calls
1362
+ * @param options
1362
1363
  * @returns
1363
1364
  */
1364
- async multicallTx(suite, creditAccount, calls) {
1365
+ async multicallTx(suite, creditAccount, calls, kycOptions) {
1365
1366
  const marketSuite = this.sdk.marketRegister.findByCreditManager(
1366
1367
  suite.creditManager.address
1367
1368
  );
1368
1369
  const factory = marketSuite.kycFactory;
1369
1370
  if (factory) {
1370
- return factory.multicall(creditAccount, calls);
1371
+ if (!kycOptions) {
1372
+ throw new Error("KYC options are required for KYC factories");
1373
+ }
1374
+ return factory.multicall(creditAccount, calls, kycOptions);
1371
1375
  }
1372
1376
  return suite.creditFacade.multicall(creditAccount, calls);
1373
1377
  }
@@ -1377,9 +1381,10 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
1377
1381
  * @param creditAccount
1378
1382
  * @param calls
1379
1383
  * @param operation
1384
+ * @param kycOptions
1380
1385
  * @returns
1381
1386
  */
1382
- async closeCreditAccountTx(suite, creditAccount, calls, operation) {
1387
+ async closeCreditAccountTx(suite, creditAccount, calls, operation, kycOptions) {
1383
1388
  const marketSuite = this.sdk.marketRegister.findByCreditManager(
1384
1389
  suite.creditManager.address
1385
1390
  );
@@ -1393,7 +1398,10 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
1393
1398
  return suite.creditFacade.closeCreditAccount(creditAccount, calls);
1394
1399
  }
1395
1400
  if (factory) {
1396
- return factory.multicall(creditAccount, calls);
1401
+ if (!kycOptions) {
1402
+ throw new Error("KYC options are required for KYC factories");
1403
+ }
1404
+ return factory.multicall(creditAccount, calls, kycOptions);
1397
1405
  }
1398
1406
  return suite.creditFacade.multicall(creditAccount, calls);
1399
1407
  }
@@ -141,7 +141,7 @@ class SecuritizeKYCFactory extends import_base.BaseContract {
141
141
  * {@inheritDoc IKYCFactory.multicall}
142
142
  */
143
143
  multicall(creditAccount, calls, options) {
144
- const { tokensToRegister = [], signaturesToCache = [] } = options ?? {};
144
+ const { tokensToRegister, signaturesToCache } = options;
145
145
  return this.createRawTx({
146
146
  functionName: "multicall",
147
147
  args: [creditAccount, calls, tokensToRegister, signaturesToCache]
@@ -150,12 +150,11 @@ class SecuritizeKYCFactory extends import_base.BaseContract {
150
150
  /**
151
151
  * {@inheritDoc IKYCFactory.getOpenAccountRequirements}
152
152
  */
153
- async getOpenAccountRequirements(investor) {
153
+ async getOpenAccountRequirements(investor, props) {
154
154
  const [investorData] = await this.#sdk.kyc.getInvestorData(investor, [
155
155
  this.address
156
156
  ]);
157
- const dsTokens = new import_utils.AddressSet(this.dsTokens.map((t) => t.address));
158
- const desiredTokens = dsTokens;
157
+ const desiredTokens = new import_utils.AddressSet([props.tokenOutAddress]);
159
158
  const registredTokens = new import_utils.AddressSet(investorData.registeredTokens);
160
159
  const signedTokens = new import_utils.AddressSet(
161
160
  investorData.cachedSignatures.map((s) => s.token)
@@ -178,7 +177,7 @@ class SecuritizeKYCFactory extends import_base.BaseContract {
178
177
  * {@inheritDoc IKYCFactory.openCreditAccount}
179
178
  */
180
179
  openCreditAccount(creditManager, calls, options) {
181
- const { tokensToRegister = [], signaturesToCache = [] } = options ?? {};
180
+ const { tokensToRegister, signaturesToCache } = options;
182
181
  return this.createRawTx({
183
182
  functionName: "openCreditAccount",
184
183
  args: [creditManager, calls, tokensToRegister, signaturesToCache]
@@ -70,8 +70,14 @@ const revolverTransportConfigSchema = z.union([
70
70
  })
71
71
  ]);
72
72
  class NoAvailableTransportsError extends BaseError {
73
- constructor(cause) {
74
- super("no available transports", { cause });
73
+ statuses;
74
+ constructor(statuses, cause) {
75
+ super("No available transports", {
76
+ cause,
77
+ metaMessages: statuses.length > 0 ? statuses.map((s) => `- ${s.id}: ${s.status}`) : ["No transports configured"],
78
+ name: "NoAvailableTransportsError"
79
+ });
80
+ this.statuses = statuses;
75
81
  }
76
82
  }
77
83
  class RevolverTransport {
@@ -129,7 +135,7 @@ class RevolverTransport {
129
135
  );
130
136
  }
131
137
  if (transports.length === 0) {
132
- throw new NoAvailableTransportsError();
138
+ throw new NoAvailableTransportsError([]);
133
139
  }
134
140
  this.#isSingle = transports.length === 1;
135
141
  const selectionStrategy = config.selectionStrategy ?? "simple";
@@ -180,7 +186,7 @@ class RevolverTransport {
180
186
  }
181
187
  } while (this.#selector.canRotate());
182
188
  this.#requests.delete(r);
183
- throw new NoAvailableTransportsError(error);
189
+ throw new NoAvailableTransportsError(this.#selector.statuses(), error);
184
190
  };
185
191
  get config() {
186
192
  return {
@@ -21,7 +21,9 @@ const RANGE_ERROR_PATTERNS = [
21
21
  /eth_getLogs is limited to/i,
22
22
  /eth_getLogs requests with up to/i,
23
23
  /range is too large/i,
24
- /exceeded max allowed range/i
24
+ /exceeded max allowed range/i,
25
+ // Encountered on DRPC: "query exceeds max results 20000, retry with the range …"
26
+ /exceeds max results/i
25
27
  ];
26
28
  function isRangeError(error) {
27
29
  const msg = errorMessage(error);
@@ -29,10 +31,17 @@ function isRangeError(error) {
29
31
  }
30
32
  const GENERIC_BLOCKS_RE = /(\d+)\s*block/i;
31
33
  const ALCHEMY_RANGE_RE = /this block range should work: \[(0x[0-9a-fA-F]+),\s*(0x[0-9a-fA-F]+)\]/;
34
+ const DRPC_RANGE_RE = /retry with the range (\d+)-(\d+)/;
32
35
  function parsePageSizeHint(error) {
33
36
  const alchemy = tryAlchemyHint(error);
34
37
  if (alchemy != null) return alchemy;
35
38
  const msg = errorMessage(error);
39
+ const drpc = msg.match(DRPC_RANGE_RE);
40
+ if (drpc) {
41
+ const from = Number(drpc[1]);
42
+ const to = Number(drpc[2]);
43
+ return to - from + 1;
44
+ }
36
45
  const m = msg.match(GENERIC_BLOCKS_RE);
37
46
  return m ? Number(m[1]) : null;
38
47
  }
@@ -26,10 +26,6 @@ import {
26
26
  import {
27
27
  getRawPriceUpdates
28
28
  } from "../market/index.js";
29
- import {
30
- isKYCFactory,
31
- KYC_FACTORY_SECURITIZE
32
- } from "../market/kyc/index.js";
33
29
  import { assetsMap } from "../router/index.js";
34
30
  import { AddressMap, AddressSet, hexEq } from "../utils/index.js";
35
31
  import { simulateWithPriceUpdates } from "../utils/viem/index.js";
@@ -815,13 +811,12 @@ class AbstractCreditAccountService extends SDKConstruct {
815
811
  /**
816
812
  * {@inheritDoc ICreditAccountsService.getOpenAccountRequirements}
817
813
  */
818
- async getOpenAccountRequirements(borrower, props) {
819
- const { creditManager } = props;
814
+ async getOpenAccountRequirements(borrower, creditManager, props) {
820
815
  const { kycFactory } = this.sdk.marketRegister.findByCreditManager(creditManager);
821
816
  if (!kycFactory) {
822
817
  return void 0;
823
818
  }
824
- return kycFactory.getOpenAccountRequirements(borrower);
819
+ return kycFactory.getOpenAccountRequirements(borrower, props);
825
820
  }
826
821
  /**
827
822
  * {@inheritDoc ICreditAccountsService.openCA}
@@ -1336,19 +1331,21 @@ class AbstractCreditAccountService extends SDKConstruct {
1336
1331
  * @param to
1337
1332
  * @param calls
1338
1333
  * @param referralCode
1334
+ * @param kycOptions
1339
1335
  * @returns
1340
1336
  */
1341
- async openCreditAccountTx(suite, to, calls, referralCode) {
1337
+ async openCreditAccountTx(suite, to, calls, referralCode, kycOptions) {
1342
1338
  const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
1343
1339
  const factory = marketSuite.kycFactory;
1344
- if (factory && isKYCFactory(factory, KYC_FACTORY_SECURITIZE)) {
1345
- const tokensToRegister = factory.dsTokens.map(
1346
- (t) => t.address
1340
+ if (factory) {
1341
+ if (!kycOptions) {
1342
+ throw new Error("KYC options are required for KYC factories");
1343
+ }
1344
+ return factory.openCreditAccount(
1345
+ suite.creditManager.address,
1346
+ calls,
1347
+ kycOptions
1347
1348
  );
1348
- return factory.openCreditAccount(suite.creditManager.address, calls, {
1349
- tokensToRegister,
1350
- signaturesToCache: []
1351
- });
1352
1349
  }
1353
1350
  return suite.creditFacade.openCreditAccount(to, calls, referralCode ?? 0n);
1354
1351
  }
@@ -1357,15 +1354,19 @@ class AbstractCreditAccountService extends SDKConstruct {
1357
1354
  * @param suite
1358
1355
  * @param creditAccount
1359
1356
  * @param calls
1357
+ * @param options
1360
1358
  * @returns
1361
1359
  */
1362
- async multicallTx(suite, creditAccount, calls) {
1360
+ async multicallTx(suite, creditAccount, calls, kycOptions) {
1363
1361
  const marketSuite = this.sdk.marketRegister.findByCreditManager(
1364
1362
  suite.creditManager.address
1365
1363
  );
1366
1364
  const factory = marketSuite.kycFactory;
1367
1365
  if (factory) {
1368
- return factory.multicall(creditAccount, calls);
1366
+ if (!kycOptions) {
1367
+ throw new Error("KYC options are required for KYC factories");
1368
+ }
1369
+ return factory.multicall(creditAccount, calls, kycOptions);
1369
1370
  }
1370
1371
  return suite.creditFacade.multicall(creditAccount, calls);
1371
1372
  }
@@ -1375,9 +1376,10 @@ class AbstractCreditAccountService extends SDKConstruct {
1375
1376
  * @param creditAccount
1376
1377
  * @param calls
1377
1378
  * @param operation
1379
+ * @param kycOptions
1378
1380
  * @returns
1379
1381
  */
1380
- async closeCreditAccountTx(suite, creditAccount, calls, operation) {
1382
+ async closeCreditAccountTx(suite, creditAccount, calls, operation, kycOptions) {
1381
1383
  const marketSuite = this.sdk.marketRegister.findByCreditManager(
1382
1384
  suite.creditManager.address
1383
1385
  );
@@ -1391,7 +1393,10 @@ class AbstractCreditAccountService extends SDKConstruct {
1391
1393
  return suite.creditFacade.closeCreditAccount(creditAccount, calls);
1392
1394
  }
1393
1395
  if (factory) {
1394
- return factory.multicall(creditAccount, calls);
1396
+ if (!kycOptions) {
1397
+ throw new Error("KYC options are required for KYC factories");
1398
+ }
1399
+ return factory.multicall(creditAccount, calls, kycOptions);
1395
1400
  }
1396
1401
  return suite.creditFacade.multicall(creditAccount, calls);
1397
1402
  }
@@ -118,7 +118,7 @@ class SecuritizeKYCFactory extends BaseContract {
118
118
  * {@inheritDoc IKYCFactory.multicall}
119
119
  */
120
120
  multicall(creditAccount, calls, options) {
121
- const { tokensToRegister = [], signaturesToCache = [] } = options ?? {};
121
+ const { tokensToRegister, signaturesToCache } = options;
122
122
  return this.createRawTx({
123
123
  functionName: "multicall",
124
124
  args: [creditAccount, calls, tokensToRegister, signaturesToCache]
@@ -127,12 +127,11 @@ class SecuritizeKYCFactory extends BaseContract {
127
127
  /**
128
128
  * {@inheritDoc IKYCFactory.getOpenAccountRequirements}
129
129
  */
130
- async getOpenAccountRequirements(investor) {
130
+ async getOpenAccountRequirements(investor, props) {
131
131
  const [investorData] = await this.#sdk.kyc.getInvestorData(investor, [
132
132
  this.address
133
133
  ]);
134
- const dsTokens = new AddressSet(this.dsTokens.map((t) => t.address));
135
- const desiredTokens = dsTokens;
134
+ const desiredTokens = new AddressSet([props.tokenOutAddress]);
136
135
  const registredTokens = new AddressSet(investorData.registeredTokens);
137
136
  const signedTokens = new AddressSet(
138
137
  investorData.cachedSignatures.map((s) => s.token)
@@ -155,7 +154,7 @@ class SecuritizeKYCFactory extends BaseContract {
155
154
  * {@inheritDoc IKYCFactory.openCreditAccount}
156
155
  */
157
156
  openCreditAccount(creditManager, calls, options) {
158
- const { tokensToRegister = [], signaturesToCache = [] } = options ?? {};
157
+ const { tokensToRegister, signaturesToCache } = options;
159
158
  return this.createRawTx({
160
159
  functionName: "openCreditAccount",
161
160
  args: [creditManager, calls, tokensToRegister, signaturesToCache]
@@ -167,7 +167,8 @@ export type RevolverTransportConfig = {
167
167
  onRotateFailed?: (oldTransportName: string, reason?: BaseError) => void | Promise<void>;
168
168
  } & z.infer<typeof revolverTransportConfigSchema>;
169
169
  export declare class NoAvailableTransportsError extends BaseError {
170
- constructor(cause?: Error);
170
+ statuses: ProviderStatus[];
171
+ constructor(statuses: ProviderStatus[], cause?: Error);
171
172
  }
172
173
  export interface RevolverTransportValue {
173
174
  /**
@@ -56,7 +56,9 @@ export declare function isRangeError(error: unknown): boolean;
56
56
  * 1. **Alchemy JSON details** — parses the `details` field of a
57
57
  * {@link HttpRequestError} for a suggested `[fromHex, toHex]` range and
58
58
  * computes the span as `toHex - fromHex + 1`.
59
- * 2. **Generic N-blocks pattern** — matches `/<number> block(s)/i` in the
59
+ * 2. **DRPC decimal range** — matches `retry with the range <from>-<to>` and
60
+ * computes the span as `to - from + 1`.
61
+ * 3. **Generic N-blocks pattern** — matches `/<number> block(s)/i` in the
60
62
  * error message.
61
63
  *
62
64
  * @param error - Any thrown value.
@@ -2,12 +2,12 @@ import type { Address } from "viem";
2
2
  import type { CreditAccountData } from "../base/index.js";
3
3
  import { SDKConstruct } from "../base/index.js";
4
4
  import type { GearboxSDK } from "../GearboxSDK.js";
5
- import type { CreditSuite } from "../market/index.js";
5
+ import type { CreditSuite, KYCOperationParams } from "../market/index.js";
6
6
  import { type PriceUpdate, type UpdatePriceFeedsResult } from "../market/index.js";
7
- import { type OpenAccountRequirements } from "../market/kyc/index.js";
7
+ import { type KYCOpenAccountRequirements } from "../market/kyc/index.js";
8
8
  import { type Asset, type RouterCASlice } from "../router/index.js";
9
9
  import type { MultiCall, RawTx } from "../types/index.js";
10
- import type { AccountToCheck, AddCollateralProps, ChangeDeptProps, ClaimDelayedProps, CloseCreditAccountProps, CloseCreditAccountResult, CloseOptions, CreditAccountOperationResult, CreditAccountTokensSlice, ExecuteSwapProps, FullyLiquidateProps, FullyLiquidateResult, GetApprovalAddressProps, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsOptions, GetPendingWithdrawalsProps, GetPendingWithdrawalsResult, OpenCAProps, PermitResult, PrepareUpdateQuotasProps, PreviewDelayedWithdrawalProps, PreviewDelayedWithdrawalResult, Rewards, StartDelayedWithdrawalProps, UpdateQuotasProps } from "./types.js";
10
+ import type { AccountToCheck, AddCollateralProps, ChangeDeptProps, ClaimDelayedProps, CloseCreditAccountProps, CloseCreditAccountResult, CloseOptions, CreditAccountOperationResult, CreditAccountTokensSlice, ExecuteSwapProps, FullyLiquidateProps, FullyLiquidateResult, GetApprovalAddressProps, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsOptions, GetOpenAccountRequirementsProps, GetPendingWithdrawalsProps, GetPendingWithdrawalsResult, OpenCAProps, PermitResult, PrepareUpdateQuotasProps, PreviewDelayedWithdrawalProps, PreviewDelayedWithdrawalResult, Rewards, StartDelayedWithdrawalProps, UpdateQuotasProps } from "./types.js";
11
11
  /**
12
12
  * Options for configuring the credit account service.
13
13
  **/
@@ -101,7 +101,7 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
101
101
  /**
102
102
  * {@inheritDoc ICreditAccountsService.getOpenAccountRequirements}
103
103
  */
104
- getOpenAccountRequirements(borrower: Address, props: Pick<OpenCAProps, "creditManager">): Promise<OpenAccountRequirements | undefined>;
104
+ getOpenAccountRequirements(borrower: Address, creditManager: Address, props: GetOpenAccountRequirementsProps): Promise<KYCOpenAccountRequirements | undefined>;
105
105
  /**
106
106
  * {@inheritDoc ICreditAccountsService.openCA}
107
107
  **/
@@ -200,24 +200,27 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
200
200
  * @param to
201
201
  * @param calls
202
202
  * @param referralCode
203
+ * @param kycOptions
203
204
  * @returns
204
205
  */
205
- protected openCreditAccountTx(suite: CreditSuite, to: Address, calls: MultiCall[], referralCode?: bigint): Promise<RawTx>;
206
+ protected openCreditAccountTx(suite: CreditSuite, to: Address, calls: MultiCall[], referralCode?: bigint, kycOptions?: KYCOperationParams): Promise<RawTx>;
206
207
  /**
207
208
  * Wrapper that selects between credit facade and KYC factory
208
209
  * @param suite
209
210
  * @param creditAccount
210
211
  * @param calls
212
+ * @param options
211
213
  * @returns
212
214
  */
213
- protected multicallTx(suite: CreditSuite, creditAccount: Address, calls: MultiCall[]): Promise<RawTx>;
215
+ protected multicallTx(suite: CreditSuite, creditAccount: Address, calls: MultiCall[], kycOptions?: KYCOperationParams): Promise<RawTx>;
214
216
  /**
215
217
  * Wrapper that selects between credit facade and KYC factory
216
218
  * @param suite
217
219
  * @param creditAccount
218
220
  * @param calls
219
221
  * @param operation
222
+ * @param kycOptions
220
223
  * @returns
221
224
  */
222
- protected closeCreditAccountTx(suite: CreditSuite, creditAccount: Address, calls: MultiCall[], operation: CloseOptions): Promise<RawTx>;
225
+ protected closeCreditAccountTx(suite: CreditSuite, creditAccount: Address, calls: MultiCall[], operation: CloseOptions, kycOptions?: KYCOperationParams): Promise<RawTx>;
223
226
  }
@@ -4,7 +4,7 @@ import type { iWithdrawalCompressorV310Abi } from "../../abi/IWithdrawalCompress
4
4
  import type { ConnectedBotData, Construct, CreditAccountData } from "../base/index.js";
5
5
  import type { GearboxSDK } from "../GearboxSDK.js";
6
6
  import type { CreditSuite, PriceUpdate } from "../market/index.js";
7
- import type { OpenAccountRequirements } from "../market/kyc/index.js";
7
+ import type { KYCOpenAccountRequirements } from "../market/kyc/index.js";
8
8
  import type { Asset, RouterCASlice, RouterCloseResult } from "../router/index.js";
9
9
  import type { MultiCall, RawTx } from "../types/index.js";
10
10
  /**
@@ -541,6 +541,16 @@ export interface Rewards {
541
541
  **/
542
542
  rewards: Array<Asset>;
543
543
  }
544
+ /**
545
+ * Options to get open account requirements
546
+ * Compatible with StrategyConfigPayload
547
+ */
548
+ export interface GetOpenAccountRequirementsProps {
549
+ /**
550
+ * Token address of the strategy
551
+ */
552
+ tokenOutAddress: Address;
553
+ }
544
554
  interface CMSlice {
545
555
  creditManager: Address;
546
556
  creditFacade: Address;
@@ -734,10 +744,11 @@ export interface ICreditAccountsService extends Construct {
734
744
  /**
735
745
  * Returns open account requirements for a borrower
736
746
  * @param borrower - Borrower address
737
- * @param props - {@link OpenCAProps}
747
+ * @param creditManager - Credit manager address
748
+ * @param props - {@link GetOpenAccountRequirementsProps} you can pass StrategyConfigPayload here
738
749
  * @returns Open account requirements or undefined if the user can open a credit account without any further actions
739
750
  */
740
- getOpenAccountRequirements(borrower: Address, props: Pick<OpenCAProps, "creditManager">): Promise<OpenAccountRequirements | undefined>;
751
+ getOpenAccountRequirements(borrower: Address, creditManager: Address, props: GetOpenAccountRequirementsProps): Promise<KYCOpenAccountRequirements | undefined>;
741
752
  /**
742
753
  * Executes swap specified by given calls, update quotas of affected tokens
743
754
  * - Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
@@ -2,7 +2,7 @@ import type { Address } from "abitype";
2
2
  import { SDKConstruct } from "../../base/index.js";
3
3
  import type { DelegatedMulticall } from "../../utils/viem/index.js";
4
4
  import { SecuritizeKYCFactory } from "./securitize/index.js";
5
- import type { InvestorData, KYCCompressorResponse, KYCState, KYCStateHuman } from "./types.js";
5
+ import type { KYCCompressorResponse, KYCInvestorData, KYCState, KYCStateHuman } from "./types.js";
6
6
  /**
7
7
  * Registry of KYC underlying tokens and KYC factory contracts.
8
8
  *
@@ -32,7 +32,7 @@ export declare class KYCRegistry extends SDKConstruct {
32
32
  * @param factories_ - Optional subset of factory addresses to query.
33
33
  * When omitted, all loaded factories are used.
34
34
  */
35
- getInvestorData(investor: Address, factories_?: Address[]): Promise<InvestorData[]>;
35
+ getInvestorData(investor: Address, factories_?: Address[]): Promise<KYCInvestorData[]>;
36
36
  /** All loaded KYC factory instances. */
37
37
  get factories(): SecuritizeKYCFactory[];
38
38
  /** Raw KYC compressor response, or `undefined` before attach/hydrate. */
@@ -1,10 +1,11 @@
1
1
  import { type Address } from "viem";
2
+ import type { GetOpenAccountRequirementsProps } from "../../../accounts/types.js";
2
3
  import { BaseContract } from "../../../base/index.js";
3
4
  import type { GearboxSDK } from "../../../GearboxSDK.js";
4
5
  import type { MultiCall, RawTx } from "../../../types/index.js";
5
6
  import type { IKYCFactory, KYCCompressorInvestorData, KYCFactoryData } from "../types.js";
6
7
  import { KYC_FACTORY_SECURITIZE } from "./constants.js";
7
- import type { DStokenData, SecuritizeInvestorData, SecuritizeKYCFactoryStateHuman, SecuritizeMulticallParams, SecuritizeOpenAccountRequirements } from "./types.js";
8
+ import type { DStokenData, SecuritizeInvestorData, SecuritizeKYCFactoryStateHuman, SecuritizeOpenAccountRequirements, SecuritizeOperationParams } from "./types.js";
8
9
  declare const abi: readonly [{
9
10
  readonly type: "function";
10
11
  readonly name: "contractType";
@@ -414,15 +415,15 @@ export declare class SecuritizeKYCFactory extends BaseContract<abi> implements I
414
415
  /**
415
416
  * {@inheritDoc IKYCFactory.multicall}
416
417
  */
417
- multicall(creditAccount: Address, calls: MultiCall[], options?: SecuritizeMulticallParams): RawTx;
418
+ multicall(creditAccount: Address, calls: MultiCall[], options: SecuritizeOperationParams): RawTx;
418
419
  /**
419
420
  * {@inheritDoc IKYCFactory.getOpenAccountRequirements}
420
421
  */
421
- getOpenAccountRequirements(investor: Address): Promise<SecuritizeOpenAccountRequirements | undefined>;
422
+ getOpenAccountRequirements(investor: Address, props: GetOpenAccountRequirementsProps): Promise<SecuritizeOpenAccountRequirements | undefined>;
422
423
  /**
423
424
  * {@inheritDoc IKYCFactory.openCreditAccount}
424
425
  */
425
- openCreditAccount(creditManager: Address, calls: MultiCall[], options?: SecuritizeMulticallParams): RawTx;
426
+ openCreditAccount(creditManager: Address, calls: MultiCall[], options: SecuritizeOperationParams): RawTx;
426
427
  stateHuman(_raw?: boolean): SecuritizeKYCFactoryStateHuman;
427
428
  }
428
429
  export {};
@@ -107,7 +107,8 @@ export interface SecuritizeKYCFactoryStateHuman extends BaseContractStateHuman {
107
107
  * Factory-specific parameters for {@link SecuritizeKYCFactory.multicall}
108
108
  * and {@link SecuritizeKYCFactory.openCreditAccount}.
109
109
  **/
110
- export interface SecuritizeMulticallParams {
110
+ export interface SecuritizeOperationParams {
111
+ type: typeof KYC_FACTORY_SECURITIZE;
111
112
  /** DSToken addresses to register for this operation. */
112
113
  tokensToRegister: Address[];
113
114
  /** Cached EIP-712 registration signatures to store on-chain. */
@@ -1,9 +1,10 @@
1
1
  import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype";
2
2
  import type { Address, ContractFunctionParameters } from "viem";
3
3
  import type { iKYCCompressorAbi } from "../../../abi/kyc/iKYCCompressor.js";
4
+ import type { GetOpenAccountRequirementsProps } from "../../accounts/types.js";
4
5
  import type { IBaseContract, Unarray } from "../../base/index.js";
5
6
  import type { MultiCall, RawTx } from "../../types/index.js";
6
- import type { SecuritizeInvestorData, SecuritizeKYCFactoryStateHuman, SecuritizeMulticallParams, SecuritizeOpenAccountRequirements } from "./securitize/index.js";
7
+ import type { SecuritizeInvestorData, SecuritizeKYCFactoryStateHuman, SecuritizeOpenAccountRequirements, SecuritizeOperationParams } from "./securitize/index.js";
7
8
  import { KYC_FACTORY_SECURITIZE } from "./securitize/index.js";
8
9
  /**
9
10
  * Discriminated union of all known KYC factory contract type strings.
@@ -18,23 +19,28 @@ export type KYCFactoryType = (typeof KYC_FACTORY_TYPES)[number];
18
19
  *
19
20
  * Type-level registry mapping each {@link KYCFactoryType} to its associated
20
21
  * data types. Adding a new KYC factory requires a single new entry here;
21
- * all derived types ({@link InvestorData}, {@link AnyOpenAccountRequirements},
22
- * etc.) update automatically.
22
+ * all derived types update automatically.
23
23
  **/
24
24
  interface KYCFactoryTypeMap {
25
25
  [KYC_FACTORY_SECURITIZE]: {
26
26
  investorData: SecuritizeInvestorData;
27
27
  openAccountRequirements: SecuritizeOpenAccountRequirements;
28
28
  stateHuman: SecuritizeKYCFactoryStateHuman;
29
- multicallParams: SecuritizeMulticallParams;
29
+ operationParams: SecuritizeOperationParams;
30
30
  };
31
31
  }
32
- /** Extracts the investor data type for a specific factory type `T`. */
33
- type KYCInvestorDataFor<T extends KYCFactoryType> = KYCFactoryTypeMap[T]["investorData"];
34
- /** Extracts the open-account requirements type for a specific factory type `T`. */
35
- type KYCOpenAccountReqFor<T extends KYCFactoryType> = KYCFactoryTypeMap[T]["openAccountRequirements"];
36
- /** Extracts the multicall/openCreditAccount extra params type for a specific factory type `T`. */
37
- type KYCMulticallParamsFor<T extends KYCFactoryType> = KYCFactoryTypeMap[T]["multicallParams"];
32
+ /**
33
+ * Investor data decoded from the KYC compressor, defaults to union of all factory types
34
+ **/
35
+ export type KYCInvestorData<T extends KYCFactoryType = KYCFactoryType> = KYCFactoryTypeMap[T]["investorData"];
36
+ /**
37
+ * Open-account requirements for a KYC factory, defaults to union of all factory types
38
+ **/
39
+ export type KYCOpenAccountRequirements<T extends KYCFactoryType = KYCFactoryType> = KYCFactoryTypeMap[T]["openAccountRequirements"];
40
+ /**
41
+ * Open credit account/Multicall extra params type for a KYC factory, defaults to union of all factory types
42
+ **/
43
+ export type KYCOperationParams<T extends KYCFactoryType = KYCFactoryType> = KYCFactoryTypeMap[T]["operationParams"];
38
44
  /**
39
45
  * Raw return type of `KYCCompressor.getKYCMarketsData`.
40
46
  **/
@@ -60,10 +66,6 @@ export type KYCCompressorInvestorData = Unarray<AbiParametersToPrimitiveTypes<Ex
60
66
  * Full KYC compressor response, used as the persisted/hydrated state.
61
67
  **/
62
68
  export type KYCState = KYCCompressorResponse;
63
- /**
64
- * Investor data decoded from the KYC compressor, union of all factory types.
65
- **/
66
- export type InvestorData = KYCFactoryTypeMap[KYCFactoryType]["investorData"];
67
69
  /**
68
70
  * Human-readable KYC factory state, union of all factory types.
69
71
  **/
@@ -75,10 +77,6 @@ export interface KYCStateHuman {
75
77
  /** State of each loaded KYC factory. */
76
78
  factories: KYCFactoryStateHuman[];
77
79
  }
78
- /**
79
- * Open-account requirements for any KYC factory (union of all factory types).
80
- **/
81
- export type OpenAccountRequirements = KYCFactoryTypeMap[KYCFactoryType]["openAccountRequirements"];
82
80
  /**
83
81
  * Shared interface for all KYC factory contracts.
84
82
  *
@@ -100,7 +98,7 @@ export interface IKYCFactory<T extends KYCFactoryType = KYCFactoryType> extends
100
98
  *
101
99
  * @param data - raw KYCCompressor InvestorData
102
100
  **/
103
- decodeInvestorData(data: KYCCompressorInvestorData): KYCInvestorDataFor<T>;
101
+ decodeInvestorData(data: KYCCompressorInvestorData): KYCInvestorData<T>;
104
102
  /**
105
103
  * Returns the investor address for a credit account.
106
104
  * @param creditAccount - credit account address
@@ -135,29 +133,28 @@ export interface IKYCFactory<T extends KYCFactoryType = KYCFactoryType> extends
135
133
  *
136
134
  * @param creditAccount - credit account address
137
135
  * @param calls - calls to perform
138
- * @param options - optional factory-specific parameters (e.g. tokens to
139
- * register, signatures to cache). When omitted the implementation
140
- * uses sensible defaults (typically empty arrays).
136
+ * @param options - factory-specific parameters (e.g. tokens to
137
+ * register, signatures to cache).
141
138
  **/
142
- multicall(creditAccount: Address, calls: MultiCall[], options?: KYCMulticallParamsFor<T>): RawTx;
139
+ multicall(creditAccount: Address, calls: MultiCall[], options: KYCOperationParams<T>): RawTx;
143
140
  /**
144
141
  * Checks if the user can open a credit account with this factory.
145
142
  * @param investor - investor address
143
+ * @param props - {@link GetOpenAccountRequirementsProps}
146
144
  * @returns open account requirements for the investor, or `undefined` if the
147
145
  * user can open a credit account without any further actions
148
146
  **/
149
- getOpenAccountRequirements(investor: Address): Promise<KYCOpenAccountReqFor<T> | undefined>;
147
+ getOpenAccountRequirements(investor: Address, props: GetOpenAccountRequirementsProps): Promise<KYCOpenAccountRequirements<T> | undefined>;
150
148
  /**
151
149
  * Creates a raw transaction to open a credit account.
152
150
  * Similar to {@link CreditFacadeV310Contract.openCreditAccount}.
153
151
  *
154
152
  * @param creditManager - credit manager address
155
153
  * @param calls - initial calls to perform
156
- * @param options - optional factory-specific parameters (e.g. tokens to
157
- * register, signatures to cache). When omitted the implementation
158
- * uses sensible defaults (typically empty arrays).
154
+ * @param options - factory-specific parameters (e.g. tokens to
155
+ * register, signatures to cache).
159
156
  **/
160
- openCreditAccount(creditManager: Address, calls: MultiCall[], options?: KYCMulticallParamsFor<T>): RawTx;
157
+ openCreditAccount(creditManager: Address, calls: MultiCall[], options: KYCOperationParams<T>): RawTx;
161
158
  }
162
159
  /**
163
160
  * Narrows an {@link IKYCFactory} to a specific factory type.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "13.7.0-kyc.3",
3
+ "version": "13.7.0-kyc.5",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",
@@ -1,38 +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 utils_exports = {};
20
- __export(utils_exports, {
21
- stringifyGetCreditAccountsArgs: () => stringifyGetCreditAccountsArgs
22
- });
23
- module.exports = __toCommonJS(utils_exports);
24
- function stringifyGetCreditAccountsArgs(args) {
25
- const s = JSON.stringify(args, replacer);
26
- return JSON.parse(s);
27
- }
28
- function replacer(_key, value) {
29
- if (typeof value === "bigint") {
30
- return value.toString();
31
- } else {
32
- return value;
33
- }
34
- }
35
- // Annotate the CommonJS export names for ESM import in node:
36
- 0 && (module.exports = {
37
- stringifyGetCreditAccountsArgs
38
- });
@@ -1,14 +0,0 @@
1
- function stringifyGetCreditAccountsArgs(args) {
2
- const s = JSON.stringify(args, replacer);
3
- return JSON.parse(s);
4
- }
5
- function replacer(_key, value) {
6
- if (typeof value === "bigint") {
7
- return value.toString();
8
- } else {
9
- return value;
10
- }
11
- }
12
- export {
13
- stringifyGetCreditAccountsArgs
14
- };
@@ -1,2 +0,0 @@
1
- import type { GetCreditAccountsArgs } from "./types.js";
2
- export declare function stringifyGetCreditAccountsArgs(args: GetCreditAccountsArgs): Record<any, any>;