@gearbox-protocol/sdk 13.6.0 → 13.7.0-kyc.1

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 (109) hide show
  1. package/dist/cjs/abi/kyc/iDSRegistryService.js +70 -0
  2. package/dist/cjs/abi/kyc/iDSToken.js +71 -0
  3. package/dist/cjs/abi/kyc/iKYCCompressor.js +196 -0
  4. package/dist/cjs/abi/kyc/iKYCFactory.js +122 -0
  5. package/dist/cjs/abi/kyc/iKYCUnderlying.js +401 -0
  6. package/dist/cjs/abi/kyc/iSecuritizeDegenNFT.js +326 -0
  7. package/dist/cjs/abi/kyc/iSecuritizeKYCFactory.js +319 -0
  8. package/dist/cjs/dev/AccountOpener.js +45 -5
  9. package/dist/cjs/history/errors.js +2 -0
  10. package/dist/cjs/sdk/GearboxSDK.js +51 -4
  11. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +324 -16
  12. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +7 -1
  13. package/dist/cjs/sdk/base/TokensMeta.js +32 -43
  14. package/dist/cjs/sdk/base/token-types.js +9 -0
  15. package/dist/cjs/sdk/chain/chains.js +2 -1
  16. package/dist/cjs/sdk/constants/address-provider.js +3 -0
  17. package/dist/cjs/sdk/market/MarketRegister.js +70 -116
  18. package/dist/cjs/sdk/market/MarketSuite.js +3 -0
  19. package/dist/cjs/sdk/market/index.js +2 -0
  20. package/dist/cjs/sdk/market/kyc/KYCRegistry.js +269 -0
  21. package/dist/cjs/sdk/market/kyc/index.js +26 -0
  22. package/dist/cjs/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +244 -0
  23. package/dist/cjs/sdk/market/kyc/securitize/constants.js +28 -0
  24. package/dist/cjs/sdk/market/kyc/securitize/index.js +26 -0
  25. package/dist/cjs/sdk/market/kyc/securitize/types.js +16 -0
  26. package/dist/cjs/sdk/market/kyc/types.js +34 -0
  27. package/dist/cjs/sdk/market/pool/PoolSuite.js +3 -0
  28. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +11 -2
  29. package/dist/cjs/sdk/market/pool/index.js +2 -0
  30. package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -3
  31. package/dist/cjs/sdk/options.js +6 -0
  32. package/dist/cjs/sdk/pools/PoolService.js +104 -12
  33. package/dist/cjs/sdk/utils/viem/executeDelegatedMulticalls.js +38 -0
  34. package/dist/cjs/sdk/utils/viem/index.js +2 -0
  35. package/dist/esm/abi/kyc/iDSRegistryService.js +46 -0
  36. package/dist/esm/abi/kyc/iDSToken.js +47 -0
  37. package/dist/esm/abi/kyc/iKYCCompressor.js +172 -0
  38. package/dist/esm/abi/kyc/iKYCFactory.js +98 -0
  39. package/dist/esm/abi/kyc/iKYCUnderlying.js +377 -0
  40. package/dist/esm/abi/kyc/iSecuritizeDegenNFT.js +302 -0
  41. package/dist/esm/abi/kyc/iSecuritizeKYCFactory.js +295 -0
  42. package/dist/esm/dev/AccountOpener.js +47 -6
  43. package/dist/esm/history/errors.js +2 -0
  44. package/dist/esm/sdk/GearboxSDK.js +55 -5
  45. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +328 -17
  46. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +7 -1
  47. package/dist/esm/sdk/base/TokensMeta.js +32 -45
  48. package/dist/esm/sdk/base/token-types.js +6 -0
  49. package/dist/esm/sdk/chain/chains.js +2 -1
  50. package/dist/esm/sdk/constants/address-provider.js +2 -0
  51. package/dist/esm/sdk/market/MarketRegister.js +74 -118
  52. package/dist/esm/sdk/market/MarketSuite.js +3 -0
  53. package/dist/esm/sdk/market/index.js +1 -0
  54. package/dist/esm/sdk/market/kyc/KYCRegistry.js +253 -0
  55. package/dist/esm/sdk/market/kyc/index.js +3 -0
  56. package/dist/esm/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +220 -0
  57. package/dist/esm/sdk/market/kyc/securitize/constants.js +4 -0
  58. package/dist/esm/sdk/market/kyc/securitize/index.js +3 -0
  59. package/dist/esm/sdk/market/kyc/securitize/types.js +0 -0
  60. package/dist/esm/sdk/market/kyc/types.js +9 -0
  61. package/dist/esm/sdk/market/pool/PoolSuite.js +3 -0
  62. package/dist/esm/sdk/market/pool/PoolV310Contract.js +11 -2
  63. package/dist/esm/sdk/market/pool/index.js +1 -0
  64. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -3
  65. package/dist/esm/sdk/options.js +6 -0
  66. package/dist/esm/sdk/pools/PoolService.js +109 -13
  67. package/dist/esm/sdk/utils/viem/executeDelegatedMulticalls.js +14 -0
  68. package/dist/esm/sdk/utils/viem/index.js +1 -0
  69. package/dist/types/abi/kyc/iDSRegistryService.d.ts +71 -0
  70. package/dist/types/abi/kyc/iDSToken.d.ts +67 -0
  71. package/dist/types/abi/kyc/iKYCCompressor.d.ts +228 -0
  72. package/dist/types/abi/kyc/iKYCFactory.d.ts +139 -0
  73. package/dist/types/abi/kyc/iKYCUnderlying.d.ts +548 -0
  74. package/dist/types/abi/kyc/iSecuritizeDegenNFT.d.ts +404 -0
  75. package/dist/types/abi/kyc/iSecuritizeKYCFactory.d.ts +376 -0
  76. package/dist/types/sdk/GearboxSDK.d.ts +7 -0
  77. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +52 -2
  78. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
  79. package/dist/types/sdk/accounts/types.d.ts +93 -13
  80. package/dist/types/sdk/base/TokensMeta.d.ts +14 -3
  81. package/dist/types/sdk/base/token-types.d.ts +44 -4
  82. package/dist/types/sdk/base/types.d.ts +116 -2
  83. package/dist/types/sdk/chain/chains.d.ts +5 -1
  84. package/dist/types/sdk/constants/address-provider.d.ts +1 -0
  85. package/dist/types/sdk/market/MarketRegister.d.ts +6 -9
  86. package/dist/types/sdk/market/MarketSuite.d.ts +2 -0
  87. package/dist/types/sdk/market/index.d.ts +1 -0
  88. package/dist/types/sdk/market/kyc/KYCRegistry.d.ts +52 -0
  89. package/dist/types/sdk/market/kyc/index.d.ts +3 -0
  90. package/dist/types/sdk/market/kyc/securitize/SecuritizeKYCFactory.d.ts +428 -0
  91. package/dist/types/sdk/market/kyc/securitize/constants.d.ts +1 -0
  92. package/dist/types/sdk/market/kyc/securitize/index.d.ts +3 -0
  93. package/dist/types/sdk/market/kyc/securitize/types.d.ts +127 -0
  94. package/dist/types/sdk/market/kyc/types.d.ts +170 -0
  95. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +3 -2
  96. package/dist/types/sdk/market/oracle/types.d.ts +3 -10
  97. package/dist/types/sdk/market/pool/PoolSuite.d.ts +2 -0
  98. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +6 -2
  99. package/dist/types/sdk/market/pool/index.d.ts +1 -0
  100. package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +1 -1
  101. package/dist/types/sdk/market/types.d.ts +1 -1
  102. package/dist/types/sdk/options.d.ts +1 -0
  103. package/dist/types/sdk/pools/PoolService.d.ts +8 -8
  104. package/dist/types/sdk/pools/types.d.ts +1 -1
  105. package/dist/types/sdk/types/state-human.d.ts +2 -0
  106. package/dist/types/sdk/types/state.d.ts +5 -0
  107. package/dist/types/sdk/utils/viem/executeDelegatedMulticalls.d.ts +28 -0
  108. package/dist/types/sdk/utils/viem/index.d.ts +1 -0
  109. package/package.json +8 -7
@@ -0,0 +1,295 @@
1
+ const iSecuritizeKYCFactoryAbi = [
2
+ {
3
+ type: "function",
4
+ name: "contractType",
5
+ inputs: [],
6
+ outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
7
+ stateMutability: "view"
8
+ },
9
+ {
10
+ type: "function",
11
+ name: "getCreditAccounts",
12
+ inputs: [{ name: "investor", type: "address", internalType: "address" }],
13
+ outputs: [{ name: "", type: "address[]", internalType: "address[]" }],
14
+ stateMutability: "view"
15
+ },
16
+ {
17
+ type: "function",
18
+ name: "getDegenNFT",
19
+ inputs: [],
20
+ outputs: [{ name: "", type: "address", internalType: "address" }],
21
+ stateMutability: "view"
22
+ },
23
+ {
24
+ type: "function",
25
+ name: "getInvestor",
26
+ inputs: [
27
+ { name: "creditAccount", type: "address", internalType: "address" }
28
+ ],
29
+ outputs: [{ name: "", type: "address", internalType: "address" }],
30
+ stateMutability: "view"
31
+ },
32
+ {
33
+ type: "function",
34
+ name: "getTokens",
35
+ inputs: [],
36
+ outputs: [{ name: "", type: "address[]", internalType: "address[]" }],
37
+ stateMutability: "view"
38
+ },
39
+ {
40
+ type: "function",
41
+ name: "getWallet",
42
+ inputs: [
43
+ { name: "creditAccount", type: "address", internalType: "address" }
44
+ ],
45
+ outputs: [{ name: "", type: "address", internalType: "address" }],
46
+ stateMutability: "view"
47
+ },
48
+ {
49
+ type: "function",
50
+ name: "isCreditAccount",
51
+ inputs: [
52
+ { name: "creditAccount", type: "address", internalType: "address" }
53
+ ],
54
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
55
+ stateMutability: "view"
56
+ },
57
+ {
58
+ type: "function",
59
+ name: "isFrozen",
60
+ inputs: [
61
+ { name: "creditAccount", type: "address", internalType: "address" }
62
+ ],
63
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
64
+ stateMutability: "view"
65
+ },
66
+ {
67
+ type: "function",
68
+ name: "multicall",
69
+ inputs: [
70
+ { name: "creditAccount", type: "address", internalType: "address" },
71
+ {
72
+ name: "calls",
73
+ type: "tuple[]",
74
+ internalType: "struct MultiCall[]",
75
+ components: [
76
+ { name: "target", type: "address", internalType: "address" },
77
+ { name: "callData", type: "bytes", internalType: "bytes" }
78
+ ]
79
+ },
80
+ {
81
+ name: "tokensToRegister",
82
+ type: "address[]",
83
+ internalType: "address[]"
84
+ },
85
+ {
86
+ name: "signaturesToCache",
87
+ type: "tuple[]",
88
+ internalType: "struct ISecuritizeDegenNFT.RegisterMessage[]",
89
+ components: [
90
+ { name: "token", type: "address", internalType: "address" },
91
+ {
92
+ name: "signature",
93
+ type: "tuple",
94
+ internalType: "struct ISecuritizeDegenNFT.Signature",
95
+ components: [
96
+ { name: "deadline", type: "uint256", internalType: "uint256" },
97
+ { name: "signature", type: "bytes", internalType: "bytes" }
98
+ ]
99
+ }
100
+ ]
101
+ }
102
+ ],
103
+ outputs: [],
104
+ stateMutability: "nonpayable"
105
+ },
106
+ {
107
+ type: "function",
108
+ name: "openCreditAccount",
109
+ inputs: [
110
+ { name: "creditManager", type: "address", internalType: "address" },
111
+ {
112
+ name: "calls",
113
+ type: "tuple[]",
114
+ internalType: "struct MultiCall[]",
115
+ components: [
116
+ { name: "target", type: "address", internalType: "address" },
117
+ { name: "callData", type: "bytes", internalType: "bytes" }
118
+ ]
119
+ },
120
+ {
121
+ name: "tokensToRegister",
122
+ type: "address[]",
123
+ internalType: "address[]"
124
+ },
125
+ {
126
+ name: "signaturesToCache",
127
+ type: "tuple[]",
128
+ internalType: "struct ISecuritizeDegenNFT.RegisterMessage[]",
129
+ components: [
130
+ { name: "token", type: "address", internalType: "address" },
131
+ {
132
+ name: "signature",
133
+ type: "tuple",
134
+ internalType: "struct ISecuritizeDegenNFT.Signature",
135
+ components: [
136
+ { name: "deadline", type: "uint256", internalType: "uint256" },
137
+ { name: "signature", type: "bytes", internalType: "bytes" }
138
+ ]
139
+ }
140
+ ]
141
+ }
142
+ ],
143
+ outputs: [
144
+ { name: "creditAccount", type: "address", internalType: "address" },
145
+ { name: "wallet", type: "address", internalType: "address" }
146
+ ],
147
+ stateMutability: "nonpayable"
148
+ },
149
+ {
150
+ type: "function",
151
+ name: "precomputeWalletAddress",
152
+ inputs: [
153
+ { name: "creditManager", type: "address", internalType: "address" },
154
+ { name: "investor", type: "address", internalType: "address" }
155
+ ],
156
+ outputs: [{ name: "", type: "address", internalType: "address" }],
157
+ stateMutability: "view"
158
+ },
159
+ {
160
+ type: "function",
161
+ name: "serialize",
162
+ inputs: [],
163
+ outputs: [{ name: "serializedData", type: "bytes", internalType: "bytes" }],
164
+ stateMutability: "view"
165
+ },
166
+ {
167
+ type: "function",
168
+ name: "setFrozenStatus",
169
+ inputs: [
170
+ { name: "creditAccount", type: "address", internalType: "address" },
171
+ { name: "frozen", type: "bool", internalType: "bool" }
172
+ ],
173
+ outputs: [],
174
+ stateMutability: "nonpayable"
175
+ },
176
+ {
177
+ type: "function",
178
+ name: "setInvestor",
179
+ inputs: [
180
+ { name: "creditAccount", type: "address", internalType: "address" },
181
+ { name: "investor", type: "address", internalType: "address" }
182
+ ],
183
+ outputs: [],
184
+ stateMutability: "nonpayable"
185
+ },
186
+ {
187
+ type: "function",
188
+ name: "version",
189
+ inputs: [],
190
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
191
+ stateMutability: "view"
192
+ },
193
+ {
194
+ type: "event",
195
+ name: "CreateWallet",
196
+ inputs: [
197
+ {
198
+ name: "creditAccount",
199
+ type: "address",
200
+ indexed: true,
201
+ internalType: "address"
202
+ },
203
+ {
204
+ name: "wallet",
205
+ type: "address",
206
+ indexed: true,
207
+ internalType: "address"
208
+ },
209
+ {
210
+ name: "investor",
211
+ type: "address",
212
+ indexed: true,
213
+ internalType: "address"
214
+ }
215
+ ],
216
+ anonymous: false
217
+ },
218
+ {
219
+ type: "event",
220
+ name: "SetFrozenStatus",
221
+ inputs: [
222
+ {
223
+ name: "creditAccount",
224
+ type: "address",
225
+ indexed: true,
226
+ internalType: "address"
227
+ },
228
+ { name: "frozen", type: "bool", indexed: false, internalType: "bool" }
229
+ ],
230
+ anonymous: false
231
+ },
232
+ {
233
+ type: "event",
234
+ name: "SetInvestor",
235
+ inputs: [
236
+ {
237
+ name: "creditAccount",
238
+ type: "address",
239
+ indexed: true,
240
+ internalType: "address"
241
+ },
242
+ {
243
+ name: "oldInvestor",
244
+ type: "address",
245
+ indexed: true,
246
+ internalType: "address"
247
+ },
248
+ {
249
+ name: "newInvestor",
250
+ type: "address",
251
+ indexed: true,
252
+ internalType: "address"
253
+ }
254
+ ],
255
+ anonymous: false
256
+ },
257
+ {
258
+ type: "error",
259
+ name: "CallerIsNotInvestorException",
260
+ inputs: [
261
+ { name: "caller", type: "address", internalType: "address" },
262
+ { name: "creditAccount", type: "address", internalType: "address" }
263
+ ]
264
+ },
265
+ {
266
+ type: "error",
267
+ name: "FrozenCreditAccountException",
268
+ inputs: [
269
+ { name: "creditAccount", type: "address", internalType: "address" }
270
+ ]
271
+ },
272
+ {
273
+ type: "error",
274
+ name: "InvalidCreditManagerException",
275
+ inputs: [
276
+ { name: "creditManager", type: "address", internalType: "address" }
277
+ ]
278
+ },
279
+ {
280
+ type: "error",
281
+ name: "InvalidUnderlyingTokenException",
282
+ inputs: [{ name: "underlying", type: "address", internalType: "address" }]
283
+ },
284
+ {
285
+ type: "error",
286
+ name: "UnknownCreditAccountException",
287
+ inputs: [
288
+ { name: "creditAccount", type: "address", internalType: "address" }
289
+ ]
290
+ },
291
+ { type: "error", name: "ZeroAddressException", inputs: [] }
292
+ ];
293
+ export {
294
+ iSecuritizeKYCFactoryAbi
295
+ };
@@ -6,7 +6,7 @@ import {
6
6
  parseEventLogs
7
7
  } from "viem";
8
8
  import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
9
- import { iCreditFacadeV310Abi, iPoolV310Abi } from "../abi/310/generated.js";
9
+ import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
10
10
  import { ierc20Abi } from "../abi/iERC20.js";
11
11
  import {
12
12
  ADDRESS_0X0,
@@ -15,6 +15,7 @@ import {
15
15
  childLogger,
16
16
  MAX_UINT256,
17
17
  PERCENTAGE_FACTOR,
18
+ PoolService,
18
19
  SDKConstruct,
19
20
  sendRawTx
20
21
  } from "../sdk/index.js";
@@ -43,6 +44,7 @@ class AccountOpener extends SDKConstruct {
43
44
  #minDebtMultiplier;
44
45
  #allowMint;
45
46
  #leverageDelta;
47
+ #poolService;
46
48
  constructor(service, options_ = {}) {
47
49
  super(service.sdk);
48
50
  const {
@@ -68,6 +70,7 @@ class AccountOpener extends SDKConstruct {
68
70
  this.#poolDepositMultiplier = BigInt(poolDepositMultiplier);
69
71
  this.#minDebtMultiplier = BigInt(minDebtMultiplier);
70
72
  this.#leverageDelta = BigInt(leverageDelta);
73
+ this.#poolService = new PoolService(service.sdk);
71
74
  this.#logger?.info(
72
75
  {
73
76
  borrower: privateKeyToAccount(this.borrowerKey).address,
@@ -105,6 +108,10 @@ class AccountOpener extends SDKConstruct {
105
108
  },
106
109
  "opening credit accounts"
107
110
  );
111
+ await Promise.all([
112
+ this.sdk.tokensMeta.loadTokenData(),
113
+ this.sdk.marketRegister.loadZappers()
114
+ ]);
108
115
  let deposits = [];
109
116
  if (depositIntoPools) {
110
117
  try {
@@ -456,9 +463,34 @@ class AccountOpener extends SDKConstruct {
456
463
  this.#logger?.debug(
457
464
  `depositor balance in underlying: ${this.sdk.tokensMeta.formatBN(pool.underlying, allowance, { symbol: true })}`
458
465
  );
466
+ const tokensOut = this.#poolService.getDepositTokensOut(
467
+ address,
468
+ underlying
469
+ );
470
+ this.#logger?.debug(
471
+ { tokensOut: tokensOut.map((t) => this.labelAddress(t)) },
472
+ "deposit tokens out"
473
+ );
474
+ if (tokensOut.length === 0) {
475
+ throw new Error(`no tokens out found for pool ${poolName}`);
476
+ }
477
+ const tokenOut = tokensOut[0];
478
+ const metadata = this.#poolService.getDepositMetadata(
479
+ address,
480
+ underlying,
481
+ tokenOut
482
+ );
483
+ this.logger?.debug(
484
+ {
485
+ underlying: this.labelAddress(underlying),
486
+ tokenOut: this.labelAddress(tokenOut),
487
+ ...metadata
488
+ },
489
+ "pool deposit metadata"
490
+ );
459
491
  txHash = await this.#anvil.writeContract({
460
492
  account: depositor,
461
- address: underlying,
493
+ address: metadata.approveTarget,
462
494
  abi: ierc20Abi,
463
495
  functionName: "approve",
464
496
  args: [address, allowance],
@@ -475,12 +507,21 @@ class AccountOpener extends SDKConstruct {
475
507
  this.#logger?.debug(
476
508
  `depositor approved underlying for pool ${poolName}: ${txHash}`
477
509
  );
510
+ const depositCall = this.#poolService.addLiquidity({
511
+ collateral: { token: underlying, balance: amount },
512
+ pool: address,
513
+ wallet: depositor.address,
514
+ meta: metadata
515
+ });
516
+ if (!depositCall) {
517
+ throw new Error(`no deposit call could be created for ${poolName}`);
518
+ }
478
519
  txHash = await this.#anvil.writeContract({
479
520
  account: depositor,
480
- address,
481
- abi: iPoolV310Abi,
482
- functionName: "deposit",
483
- args: [amount, depositor.address],
521
+ address: depositCall.target,
522
+ abi: depositCall.abi,
523
+ functionName: depositCall.functionName,
524
+ args: depositCall.args,
484
525
  chain: this.#anvil.chain
485
526
  });
486
527
  receipt = await this.#anvil.waitForTransactionReceipt({ hash: txHash });
@@ -33,6 +33,8 @@ class AdapterTraceAlignmentError extends Error {
33
33
  this.actual = actual;
34
34
  this.name = "AdapterTracesAlignmentError";
35
35
  }
36
+ expected;
37
+ actual;
36
38
  }
37
39
  class UnexpectedFacadeEventOrderError extends Error {
38
40
  constructor(e) {
@@ -16,6 +16,7 @@ import {
16
16
  VERSION_RANGE_310
17
17
  } from "./constants/index.js";
18
18
  import { createAddressProvider, hydrateAddressProvider } from "./core/index.js";
19
+ import { KYCRegistry } from "./market/kyc/index.js";
19
20
  import { MarketRegister } from "./market/MarketRegister.js";
20
21
  import { PriceFeedRegister } from "./market/pricefeeds/index.js";
21
22
  import {
@@ -24,7 +25,10 @@ import {
24
25
  import { createRouter } from "./router/index.js";
25
26
  import { formatTimestamp, TypedObjectUtils, toAddress } from "./utils/index.js";
26
27
  import { Hooks } from "./utils/internal/index.js";
27
- import { getLogsSafe } from "./utils/viem/index.js";
28
+ import {
29
+ executeDelegatedMulticalls,
30
+ getLogsSafe
31
+ } from "./utils/viem/index.js";
28
32
  const ERR_NOT_ATTACHED = new Error("Gearbox SDK not attached");
29
33
  const STATE_VERSION = 1;
30
34
  function createClient(opts, network) {
@@ -77,6 +81,7 @@ class GearboxSDK extends ChainContractsRegister {
77
81
  #addressProvider;
78
82
  #attachConfig;
79
83
  #marketRegister;
84
+ #kyc;
80
85
  #priceFeeds;
81
86
  /**
82
87
  * Gas limit applied to read-only `eth_call` requests.
@@ -121,6 +126,7 @@ class GearboxSDK extends ChainContractsRegister {
121
126
  ignoreUpdateablePrices,
122
127
  ignoreMarkets,
123
128
  marketConfigurators: mcs,
129
+ kycFactories: kfs,
124
130
  strictContractTypes,
125
131
  gasLimit
126
132
  } = options;
@@ -130,6 +136,7 @@ class GearboxSDK extends ChainContractsRegister {
130
136
  addressProvider = ADDRESS_PROVIDER_V310;
131
137
  }
132
138
  const marketConfigurators = mcs ?? TypedObjectUtils.keys(client.chain.defaultMarketConfigurators);
139
+ const kycFactories = kfs ?? client.chain.kycFactories;
133
140
  return new GearboxSDK({
134
141
  client,
135
142
  logger,
@@ -142,6 +149,7 @@ class GearboxSDK extends ChainContractsRegister {
142
149
  ignoreUpdateablePrices,
143
150
  ignoreMarkets,
144
151
  marketConfigurators,
152
+ kycFactories,
145
153
  redstone,
146
154
  pyth
147
155
  });
@@ -191,6 +199,7 @@ class GearboxSDK extends ChainContractsRegister {
191
199
  ignoreUpdateablePrices,
192
200
  ignoreMarkets,
193
201
  marketConfigurators,
202
+ kycFactories,
194
203
  redstone,
195
204
  pyth
196
205
  } = opts;
@@ -201,6 +210,7 @@ class GearboxSDK extends ChainContractsRegister {
201
210
  chainId: this.chainId,
202
211
  addressProvider,
203
212
  marketConfigurators,
213
+ kycFactories,
204
214
  blockNumber,
205
215
  ignoreMarkets
206
216
  },
@@ -235,10 +245,34 @@ class GearboxSDK extends ChainContractsRegister {
235
245
  );
236
246
  await this.#addressProvider.syncState(this.currentBlock);
237
247
  this.#marketRegister = new MarketRegister(this, ignoreMarkets);
238
- await this.#marketRegister.loadMarkets(
239
- marketConfigurators,
240
- ignoreUpdateablePrices
241
- );
248
+ this.#kyc = new KYCRegistry(this);
249
+ if (!marketConfigurators.length) {
250
+ this.logger?.warn(
251
+ "no market configurators provided, skipping market loading"
252
+ );
253
+ } else {
254
+ const delegated = [
255
+ ...this.#marketRegister.getLoadMulticalls(marketConfigurators),
256
+ ...this.#kyc.getLoadMulticalls(marketConfigurators, kycFactories)
257
+ ];
258
+ let txs = [];
259
+ if (!ignoreUpdateablePrices) {
260
+ const updatables = await this.#priceFeeds.getPartialUpdatablePriceFeeds(
261
+ marketConfigurators
262
+ );
263
+ const updates = await this.#priceFeeds.generatePriceFeedsUpdateTxs(updatables);
264
+ txs = updates.txs;
265
+ }
266
+ this.logger?.debug(
267
+ { configurators: marketConfigurators },
268
+ `calling getMarkets with ${txs.length} price updates in block ${this.currentBlock}`
269
+ );
270
+ await executeDelegatedMulticalls(this.client, delegated, {
271
+ priceUpdates: txs,
272
+ blockNumber: this.currentBlock,
273
+ gas: this.gasLimit
274
+ });
275
+ }
242
276
  const pluginsList = TypedObjectUtils.entries(this.plugins);
243
277
  const pluginResponse = await Promise.allSettled(
244
278
  pluginsList.map(([name, plugin]) => {
@@ -284,12 +318,15 @@ class GearboxSDK extends ChainContractsRegister {
284
318
  );
285
319
  this.#marketRegister = new MarketRegister(this, ignoreMarkets);
286
320
  this.#marketRegister.hydrate(state.markets);
321
+ this.#kyc = new KYCRegistry(this);
322
+ this.#kyc.setState(state.kyc);
287
323
  this.#attachConfig = {
288
324
  ...opts,
289
325
  addressProvider: this.addressProvider.address,
290
326
  marketConfigurators: this.marketRegister.marketConfigurators.map(
291
327
  (m) => m.address
292
328
  ),
329
+ kycFactories: this.kyc.factories.map((f) => f.address),
293
330
  blockNumber: this.currentBlock
294
331
  };
295
332
  for (const [name, plugin] of TypedObjectUtils.entries(this.plugins)) {
@@ -373,6 +410,7 @@ class GearboxSDK extends ChainContractsRegister {
373
410
  addressProviderV3: this.addressProvider.stateHuman(raw)
374
411
  },
375
412
  tokens: this.tokensMeta.values(),
413
+ kyc: this.kyc.stateHuman(raw),
376
414
  plugins: Object.fromEntries(
377
415
  TypedObjectUtils.entries(this.plugins).map(([name, plugin]) => [
378
416
  name,
@@ -398,6 +436,7 @@ class GearboxSDK extends ChainContractsRegister {
398
436
  timestamp: this.timestamp,
399
437
  addressProvider: this.addressProvider.state,
400
438
  markets: this.marketRegister.state,
439
+ kyc: this.kyc.state,
401
440
  plugins: Object.fromEntries(
402
441
  TypedObjectUtils.entries(this.plugins).map(([name, plugin]) => [
403
442
  name,
@@ -594,6 +633,17 @@ class GearboxSDK extends ChainContractsRegister {
594
633
  }
595
634
  return this.#marketRegister;
596
635
  }
636
+ /**
637
+ * KYC register for KYC-wrapped underlying tokens and factories.
638
+ *
639
+ * @throws If the SDK has not been attached or hydrated yet.
640
+ **/
641
+ get kyc() {
642
+ if (this.#kyc === void 0) {
643
+ throw ERR_NOT_ATTACHED;
644
+ }
645
+ return this.#kyc;
646
+ }
597
647
  /**
598
648
  * Resolves the appropriate router contract for a given credit manager,
599
649
  * credit facade, or explicit version range.