@gearbox-protocol/sdk 13.0.0-next.2 → 13.0.0-next.20

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 (49) hide show
  1. package/dist/cjs/abi/310/iSecuritizeKYCFactory.js +356 -0
  2. package/dist/cjs/dev/AccountOpener.js +45 -5
  3. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +138 -118
  4. package/dist/cjs/sdk/accounts/CreditAccountsServiceV300.js +9 -4
  5. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +9 -4
  6. package/dist/cjs/sdk/base/ChainContractsRegister.js +1 -1
  7. package/dist/cjs/sdk/base/TokensMeta.js +158 -19
  8. package/dist/cjs/sdk/market/MarketRegister.js +2 -2
  9. package/dist/cjs/sdk/{pools/extraZappers.js → market/ZapperRegister.js} +110 -6
  10. package/dist/cjs/sdk/market/index.js +5 -1
  11. package/dist/cjs/sdk/market/kyc/SecuritizeKYCFactory.js +64 -0
  12. package/dist/cjs/sdk/market/kyc/index.js +22 -0
  13. package/dist/cjs/sdk/market/types.js +16 -0
  14. package/dist/cjs/sdk/pools/PoolService.js +180 -99
  15. package/dist/cjs/sdk/utils/AddressMap.js +1 -1
  16. package/dist/cjs/sdk/utils/viem/sendRawTx.js +16 -0
  17. package/dist/esm/abi/310/iSecuritizeKYCFactory.js +332 -0
  18. package/dist/esm/dev/AccountOpener.js +47 -6
  19. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +140 -118
  20. package/dist/esm/sdk/accounts/CreditAccountsServiceV300.js +9 -4
  21. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +9 -4
  22. package/dist/esm/sdk/base/ChainContractsRegister.js +1 -1
  23. package/dist/esm/sdk/base/TokensMeta.js +162 -18
  24. package/dist/esm/sdk/market/MarketRegister.js +2 -2
  25. package/dist/esm/sdk/{pools/extraZappers.js → market/ZapperRegister.js} +109 -2
  26. package/dist/esm/sdk/market/index.js +2 -0
  27. package/dist/esm/sdk/market/kyc/SecuritizeKYCFactory.js +40 -0
  28. package/dist/esm/sdk/market/kyc/index.js +1 -0
  29. package/dist/esm/sdk/market/types.js +0 -0
  30. package/dist/esm/sdk/pools/PoolService.js +181 -106
  31. package/dist/esm/sdk/utils/AddressMap.js +1 -1
  32. package/dist/esm/sdk/utils/viem/sendRawTx.js +19 -1
  33. package/dist/types/abi/310/iSecuritizeKYCFactory.d.ts +431 -0
  34. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +45 -25
  35. package/dist/types/sdk/accounts/types.d.ts +28 -1
  36. package/dist/types/sdk/base/TokensMeta.d.ts +30 -5
  37. package/dist/types/sdk/base/token-types.d.ts +9 -2
  38. package/dist/types/sdk/market/MarketRegister.d.ts +2 -2
  39. package/dist/types/sdk/market/ZapperRegister.d.ts +17 -0
  40. package/dist/types/sdk/market/index.d.ts +2 -0
  41. package/dist/types/sdk/market/kyc/SecuritizeKYCFactory.d.ts +445 -0
  42. package/dist/types/sdk/market/kyc/index.d.ts +1 -0
  43. package/dist/types/sdk/market/types.d.ts +10 -0
  44. package/dist/types/sdk/pools/PoolService.d.ts +4 -4
  45. package/dist/types/sdk/pools/types.d.ts +25 -16
  46. package/dist/types/sdk/utils/AddressMap.d.ts +1 -1
  47. package/dist/types/sdk/utils/viem/sendRawTx.d.ts +5 -1
  48. package/package.json +1 -1
  49. package/dist/types/sdk/pools/extraZappers.d.ts +0 -9
@@ -0,0 +1,356 @@
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 iSecuritizeKYCFactory_exports = {};
20
+ __export(iSecuritizeKYCFactory_exports, {
21
+ iSecuritizeKYCFactoryAbi: () => iSecuritizeKYCFactoryAbi
22
+ });
23
+ module.exports = __toCommonJS(iSecuritizeKYCFactory_exports);
24
+ const iSecuritizeKYCFactoryAbi = [
25
+ {
26
+ type: "function",
27
+ name: "addRegistrar",
28
+ inputs: [{ name: "registrar", type: "address", internalType: "address" }],
29
+ outputs: [],
30
+ stateMutability: "nonpayable"
31
+ },
32
+ {
33
+ type: "function",
34
+ name: "contractType",
35
+ inputs: [],
36
+ outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
37
+ stateMutability: "view"
38
+ },
39
+ {
40
+ type: "function",
41
+ name: "degenNFT",
42
+ inputs: [],
43
+ outputs: [{ name: "", type: "address", internalType: "address" }],
44
+ stateMutability: "view"
45
+ },
46
+ {
47
+ type: "function",
48
+ name: "getCreditAccounts",
49
+ inputs: [{ name: "investor", type: "address", internalType: "address" }],
50
+ outputs: [{ name: "", type: "address[]", internalType: "address[]" }],
51
+ stateMutability: "view"
52
+ },
53
+ {
54
+ type: "function",
55
+ name: "getDSTokens",
56
+ inputs: [],
57
+ outputs: [{ name: "", type: "address[]", internalType: "address[]" }],
58
+ stateMutability: "view"
59
+ },
60
+ {
61
+ type: "function",
62
+ name: "getInvestor",
63
+ inputs: [
64
+ { name: "creditAccount", type: "address", internalType: "address" }
65
+ ],
66
+ outputs: [{ name: "", type: "address", internalType: "address" }],
67
+ stateMutability: "view"
68
+ },
69
+ {
70
+ type: "function",
71
+ name: "getRegisteredTokens",
72
+ inputs: [
73
+ { name: "creditAccount", type: "address", internalType: "address" }
74
+ ],
75
+ outputs: [{ name: "", type: "address[]", internalType: "address[]" }],
76
+ stateMutability: "view"
77
+ },
78
+ {
79
+ type: "function",
80
+ name: "getRegistrar",
81
+ inputs: [{ name: "token", type: "address", internalType: "address" }],
82
+ outputs: [{ name: "", type: "address", internalType: "address" }],
83
+ stateMutability: "view"
84
+ },
85
+ {
86
+ type: "function",
87
+ name: "getWallet",
88
+ inputs: [
89
+ { name: "creditAccount", type: "address", internalType: "address" }
90
+ ],
91
+ outputs: [{ name: "", type: "address", internalType: "address" }],
92
+ stateMutability: "view"
93
+ },
94
+ {
95
+ type: "function",
96
+ name: "isActiveCreditAccount",
97
+ inputs: [
98
+ { name: "creditAccount", type: "address", internalType: "address" }
99
+ ],
100
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
101
+ stateMutability: "view"
102
+ },
103
+ {
104
+ type: "function",
105
+ name: "isCreditAccount",
106
+ inputs: [
107
+ { name: "creditAccount", type: "address", internalType: "address" }
108
+ ],
109
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
110
+ stateMutability: "view"
111
+ },
112
+ {
113
+ type: "function",
114
+ name: "isFrozen",
115
+ inputs: [
116
+ { name: "creditAccount", type: "address", internalType: "address" }
117
+ ],
118
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
119
+ stateMutability: "view"
120
+ },
121
+ {
122
+ type: "function",
123
+ name: "isInactiveCreditAccount",
124
+ inputs: [
125
+ { name: "creditAccount", type: "address", internalType: "address" }
126
+ ],
127
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
128
+ stateMutability: "view"
129
+ },
130
+ {
131
+ type: "function",
132
+ name: "multicall",
133
+ inputs: [
134
+ { name: "creditAccount", type: "address", internalType: "address" },
135
+ {
136
+ name: "calls",
137
+ type: "tuple[]",
138
+ internalType: "struct MultiCall[]",
139
+ components: [
140
+ { name: "target", type: "address", internalType: "address" },
141
+ { name: "callData", type: "bytes", internalType: "bytes" }
142
+ ]
143
+ },
144
+ {
145
+ name: "tokensToRegister",
146
+ type: "address[]",
147
+ internalType: "address[]"
148
+ }
149
+ ],
150
+ outputs: [],
151
+ stateMutability: "nonpayable"
152
+ },
153
+ {
154
+ type: "function",
155
+ name: "openCreditAccount",
156
+ inputs: [
157
+ { name: "creditManager", type: "address", internalType: "address" },
158
+ {
159
+ name: "calls",
160
+ type: "tuple[]",
161
+ internalType: "struct MultiCall[]",
162
+ components: [
163
+ { name: "target", type: "address", internalType: "address" },
164
+ { name: "callData", type: "bytes", internalType: "bytes" }
165
+ ]
166
+ },
167
+ {
168
+ name: "tokensToRegister",
169
+ type: "address[]",
170
+ internalType: "address[]"
171
+ }
172
+ ],
173
+ outputs: [
174
+ { name: "creditAccount", type: "address", internalType: "address" },
175
+ { name: "wallet", type: "address", internalType: "address" }
176
+ ],
177
+ stateMutability: "nonpayable"
178
+ },
179
+ {
180
+ type: "function",
181
+ name: "precomputeWalletAddress",
182
+ inputs: [
183
+ { name: "creditManager", type: "address", internalType: "address" },
184
+ { name: "investor", type: "address", internalType: "address" }
185
+ ],
186
+ outputs: [{ name: "", type: "address", internalType: "address" }],
187
+ stateMutability: "view"
188
+ },
189
+ {
190
+ type: "function",
191
+ name: "setFrozenStatus",
192
+ inputs: [
193
+ { name: "creditAccount", type: "address", internalType: "address" },
194
+ { name: "frozen", type: "bool", internalType: "bool" }
195
+ ],
196
+ outputs: [],
197
+ stateMutability: "nonpayable"
198
+ },
199
+ {
200
+ type: "function",
201
+ name: "setInvestor",
202
+ inputs: [
203
+ { name: "creditAccount", type: "address", internalType: "address" },
204
+ { name: "investor", type: "address", internalType: "address" }
205
+ ],
206
+ outputs: [],
207
+ stateMutability: "nonpayable"
208
+ },
209
+ {
210
+ type: "function",
211
+ name: "version",
212
+ inputs: [],
213
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
214
+ stateMutability: "view"
215
+ },
216
+ {
217
+ type: "event",
218
+ name: "CreateWallet",
219
+ inputs: [
220
+ {
221
+ name: "creditAccount",
222
+ type: "address",
223
+ indexed: true,
224
+ internalType: "address"
225
+ },
226
+ {
227
+ name: "wallet",
228
+ type: "address",
229
+ indexed: true,
230
+ internalType: "address"
231
+ },
232
+ {
233
+ name: "investor",
234
+ type: "address",
235
+ indexed: true,
236
+ internalType: "address"
237
+ }
238
+ ],
239
+ anonymous: false
240
+ },
241
+ {
242
+ type: "event",
243
+ name: "SetFrozenStatus",
244
+ inputs: [
245
+ {
246
+ name: "creditAccount",
247
+ type: "address",
248
+ indexed: true,
249
+ internalType: "address"
250
+ },
251
+ { name: "frozen", type: "bool", indexed: false, internalType: "bool" }
252
+ ],
253
+ anonymous: false
254
+ },
255
+ {
256
+ type: "event",
257
+ name: "SetInvestor",
258
+ inputs: [
259
+ {
260
+ name: "creditAccount",
261
+ type: "address",
262
+ indexed: true,
263
+ internalType: "address"
264
+ },
265
+ {
266
+ name: "oldInvestor",
267
+ type: "address",
268
+ indexed: true,
269
+ internalType: "address"
270
+ },
271
+ {
272
+ name: "newInvestor",
273
+ type: "address",
274
+ indexed: true,
275
+ internalType: "address"
276
+ }
277
+ ],
278
+ anonymous: false
279
+ },
280
+ {
281
+ type: "event",
282
+ name: "SetRegistrar",
283
+ inputs: [
284
+ {
285
+ name: "token",
286
+ type: "address",
287
+ indexed: true,
288
+ internalType: "address"
289
+ },
290
+ {
291
+ name: "registrar",
292
+ type: "address",
293
+ indexed: true,
294
+ internalType: "address"
295
+ }
296
+ ],
297
+ anonymous: false
298
+ },
299
+ {
300
+ type: "error",
301
+ name: "CallerIsNotInstanceOwnerException",
302
+ inputs: [{ name: "caller", type: "address", internalType: "address" }]
303
+ },
304
+ {
305
+ type: "error",
306
+ name: "CallerIsNotInvestorException",
307
+ inputs: [
308
+ { name: "caller", type: "address", internalType: "address" },
309
+ { name: "creditAccount", type: "address", internalType: "address" }
310
+ ]
311
+ },
312
+ {
313
+ type: "error",
314
+ name: "FrozenCreditAccountException",
315
+ inputs: [
316
+ { name: "creditAccount", type: "address", internalType: "address" }
317
+ ]
318
+ },
319
+ {
320
+ type: "error",
321
+ name: "InvalidCreditManagerException",
322
+ inputs: [
323
+ { name: "creditManager", type: "address", internalType: "address" }
324
+ ]
325
+ },
326
+ {
327
+ type: "error",
328
+ name: "InvalidUnderlyingTokenException",
329
+ inputs: [{ name: "underlying", type: "address", internalType: "address" }]
330
+ },
331
+ {
332
+ type: "error",
333
+ name: "RegistrarNotSetForTokenException",
334
+ inputs: [{ name: "token", type: "address", internalType: "address" }]
335
+ },
336
+ {
337
+ type: "error",
338
+ name: "UnknownCreditAccountException",
339
+ inputs: [
340
+ { name: "creditAccount", type: "address", internalType: "address" }
341
+ ]
342
+ },
343
+ {
344
+ type: "error",
345
+ name: "WalletCallExecutionFailedException",
346
+ inputs: [
347
+ { name: "index", type: "uint256", internalType: "uint256" },
348
+ { name: "reason", type: "bytes", internalType: "bytes" }
349
+ ]
350
+ },
351
+ { type: "error", name: "ZeroAddressException", inputs: [] }
352
+ ];
353
+ // Annotate the CommonJS export names for ESM import in node:
354
+ 0 && (module.exports = {
355
+ iSecuritizeKYCFactoryAbi
356
+ });
@@ -52,6 +52,7 @@ class AccountOpener extends import_sdk.SDKConstruct {
52
52
  #minDebtMultiplier;
53
53
  #allowMint;
54
54
  #leverageDelta;
55
+ #poolService;
55
56
  constructor(service, options_ = {}) {
56
57
  super(service.sdk);
57
58
  const {
@@ -77,6 +78,7 @@ class AccountOpener extends import_sdk.SDKConstruct {
77
78
  this.#poolDepositMultiplier = BigInt(poolDepositMultiplier);
78
79
  this.#minDebtMultiplier = BigInt(minDebtMultiplier);
79
80
  this.#leverageDelta = BigInt(leverageDelta);
81
+ this.#poolService = new import_sdk.PoolService(service.sdk);
80
82
  this.#logger?.info(
81
83
  {
82
84
  borrower: (0, import_accounts.privateKeyToAccount)(this.borrowerKey).address,
@@ -114,6 +116,10 @@ class AccountOpener extends import_sdk.SDKConstruct {
114
116
  },
115
117
  "opening credit accounts"
116
118
  );
119
+ await Promise.all([
120
+ this.sdk.tokensMeta.loadTokenData(),
121
+ this.sdk.marketRegister.loadZappers()
122
+ ]);
117
123
  let deposits = [];
118
124
  if (depositIntoPools) {
119
125
  try {
@@ -465,9 +471,34 @@ class AccountOpener extends import_sdk.SDKConstruct {
465
471
  this.#logger?.debug(
466
472
  `depositor balance in underlying: ${this.sdk.tokensMeta.formatBN(pool.underlying, allowance, { symbol: true })}`
467
473
  );
474
+ const tokensOut = this.#poolService.getDepositTokensOut(
475
+ address,
476
+ underlying
477
+ );
478
+ this.#logger?.debug(
479
+ { tokensOut: tokensOut.map((t) => this.labelAddress(t)) },
480
+ "deposit tokens out"
481
+ );
482
+ if (tokensOut.length === 0) {
483
+ throw new Error(`no tokens out found for pool ${poolName}`);
484
+ }
485
+ const tokenOut = tokensOut[0];
486
+ const metadata = this.#poolService.getDepositMetadata(
487
+ address,
488
+ underlying,
489
+ tokenOut
490
+ );
491
+ this.logger?.debug(
492
+ {
493
+ underlying: this.labelAddress(underlying),
494
+ tokenOut: this.labelAddress(tokenOut),
495
+ ...metadata
496
+ },
497
+ "pool deposit metadata"
498
+ );
468
499
  txHash = await this.#anvil.writeContract({
469
500
  account: depositor,
470
- address: underlying,
501
+ address: metadata.approveTarget,
471
502
  abi: import_iERC20.ierc20Abi,
472
503
  functionName: "approve",
473
504
  args: [address, allowance],
@@ -484,12 +515,21 @@ class AccountOpener extends import_sdk.SDKConstruct {
484
515
  this.#logger?.debug(
485
516
  `depositor approved underlying for pool ${poolName}: ${txHash}`
486
517
  );
518
+ const depositCall = this.#poolService.addLiquidity({
519
+ collateral: { token: underlying, balance: amount },
520
+ pool: address,
521
+ wallet: depositor.address,
522
+ meta: metadata
523
+ });
524
+ if (!depositCall) {
525
+ throw new Error(`no deposit call could be created for ${poolName}`);
526
+ }
487
527
  txHash = await this.#anvil.writeContract({
488
528
  account: depositor,
489
- address,
490
- abi: import_v300.iPoolV300Abi,
491
- functionName: "deposit",
492
- args: [amount, depositor.address],
529
+ address: depositCall.target,
530
+ abi: depositCall.abi,
531
+ functionName: depositCall.functionName,
532
+ args: depositCall.args,
493
533
  chain: this.#anvil.chain
494
534
  });
495
535
  receipt = await this.#anvil.waitForTransactionReceipt({ hash: txHash });