@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,332 @@
1
+ const iSecuritizeKYCFactoryAbi = [
2
+ {
3
+ type: "function",
4
+ name: "addRegistrar",
5
+ inputs: [{ name: "registrar", type: "address", internalType: "address" }],
6
+ outputs: [],
7
+ stateMutability: "nonpayable"
8
+ },
9
+ {
10
+ type: "function",
11
+ name: "contractType",
12
+ inputs: [],
13
+ outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
14
+ stateMutability: "view"
15
+ },
16
+ {
17
+ type: "function",
18
+ name: "degenNFT",
19
+ inputs: [],
20
+ outputs: [{ name: "", type: "address", internalType: "address" }],
21
+ stateMutability: "view"
22
+ },
23
+ {
24
+ type: "function",
25
+ name: "getCreditAccounts",
26
+ inputs: [{ name: "investor", type: "address", internalType: "address" }],
27
+ outputs: [{ name: "", type: "address[]", internalType: "address[]" }],
28
+ stateMutability: "view"
29
+ },
30
+ {
31
+ type: "function",
32
+ name: "getDSTokens",
33
+ inputs: [],
34
+ outputs: [{ name: "", type: "address[]", internalType: "address[]" }],
35
+ stateMutability: "view"
36
+ },
37
+ {
38
+ type: "function",
39
+ name: "getInvestor",
40
+ inputs: [
41
+ { name: "creditAccount", type: "address", internalType: "address" }
42
+ ],
43
+ outputs: [{ name: "", type: "address", internalType: "address" }],
44
+ stateMutability: "view"
45
+ },
46
+ {
47
+ type: "function",
48
+ name: "getRegisteredTokens",
49
+ inputs: [
50
+ { name: "creditAccount", type: "address", internalType: "address" }
51
+ ],
52
+ outputs: [{ name: "", type: "address[]", internalType: "address[]" }],
53
+ stateMutability: "view"
54
+ },
55
+ {
56
+ type: "function",
57
+ name: "getRegistrar",
58
+ inputs: [{ name: "token", type: "address", internalType: "address" }],
59
+ outputs: [{ name: "", type: "address", internalType: "address" }],
60
+ stateMutability: "view"
61
+ },
62
+ {
63
+ type: "function",
64
+ name: "getWallet",
65
+ inputs: [
66
+ { name: "creditAccount", type: "address", internalType: "address" }
67
+ ],
68
+ outputs: [{ name: "", type: "address", internalType: "address" }],
69
+ stateMutability: "view"
70
+ },
71
+ {
72
+ type: "function",
73
+ name: "isActiveCreditAccount",
74
+ inputs: [
75
+ { name: "creditAccount", type: "address", internalType: "address" }
76
+ ],
77
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
78
+ stateMutability: "view"
79
+ },
80
+ {
81
+ type: "function",
82
+ name: "isCreditAccount",
83
+ inputs: [
84
+ { name: "creditAccount", type: "address", internalType: "address" }
85
+ ],
86
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
87
+ stateMutability: "view"
88
+ },
89
+ {
90
+ type: "function",
91
+ name: "isFrozen",
92
+ inputs: [
93
+ { name: "creditAccount", type: "address", internalType: "address" }
94
+ ],
95
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
96
+ stateMutability: "view"
97
+ },
98
+ {
99
+ type: "function",
100
+ name: "isInactiveCreditAccount",
101
+ inputs: [
102
+ { name: "creditAccount", type: "address", internalType: "address" }
103
+ ],
104
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
105
+ stateMutability: "view"
106
+ },
107
+ {
108
+ type: "function",
109
+ name: "multicall",
110
+ inputs: [
111
+ { name: "creditAccount", type: "address", internalType: "address" },
112
+ {
113
+ name: "calls",
114
+ type: "tuple[]",
115
+ internalType: "struct MultiCall[]",
116
+ components: [
117
+ { name: "target", type: "address", internalType: "address" },
118
+ { name: "callData", type: "bytes", internalType: "bytes" }
119
+ ]
120
+ },
121
+ {
122
+ name: "tokensToRegister",
123
+ type: "address[]",
124
+ internalType: "address[]"
125
+ }
126
+ ],
127
+ outputs: [],
128
+ stateMutability: "nonpayable"
129
+ },
130
+ {
131
+ type: "function",
132
+ name: "openCreditAccount",
133
+ inputs: [
134
+ { name: "creditManager", 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
+ { name: "creditAccount", type: "address", internalType: "address" },
152
+ { name: "wallet", type: "address", internalType: "address" }
153
+ ],
154
+ stateMutability: "nonpayable"
155
+ },
156
+ {
157
+ type: "function",
158
+ name: "precomputeWalletAddress",
159
+ inputs: [
160
+ { name: "creditManager", type: "address", internalType: "address" },
161
+ { name: "investor", type: "address", internalType: "address" }
162
+ ],
163
+ outputs: [{ name: "", type: "address", internalType: "address" }],
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: "event",
259
+ name: "SetRegistrar",
260
+ inputs: [
261
+ {
262
+ name: "token",
263
+ type: "address",
264
+ indexed: true,
265
+ internalType: "address"
266
+ },
267
+ {
268
+ name: "registrar",
269
+ type: "address",
270
+ indexed: true,
271
+ internalType: "address"
272
+ }
273
+ ],
274
+ anonymous: false
275
+ },
276
+ {
277
+ type: "error",
278
+ name: "CallerIsNotInstanceOwnerException",
279
+ inputs: [{ name: "caller", type: "address", internalType: "address" }]
280
+ },
281
+ {
282
+ type: "error",
283
+ name: "CallerIsNotInvestorException",
284
+ inputs: [
285
+ { name: "caller", type: "address", internalType: "address" },
286
+ { name: "creditAccount", type: "address", internalType: "address" }
287
+ ]
288
+ },
289
+ {
290
+ type: "error",
291
+ name: "FrozenCreditAccountException",
292
+ inputs: [
293
+ { name: "creditAccount", type: "address", internalType: "address" }
294
+ ]
295
+ },
296
+ {
297
+ type: "error",
298
+ name: "InvalidCreditManagerException",
299
+ inputs: [
300
+ { name: "creditManager", type: "address", internalType: "address" }
301
+ ]
302
+ },
303
+ {
304
+ type: "error",
305
+ name: "InvalidUnderlyingTokenException",
306
+ inputs: [{ name: "underlying", type: "address", internalType: "address" }]
307
+ },
308
+ {
309
+ type: "error",
310
+ name: "RegistrarNotSetForTokenException",
311
+ inputs: [{ name: "token", type: "address", internalType: "address" }]
312
+ },
313
+ {
314
+ type: "error",
315
+ name: "UnknownCreditAccountException",
316
+ inputs: [
317
+ { name: "creditAccount", type: "address", internalType: "address" }
318
+ ]
319
+ },
320
+ {
321
+ type: "error",
322
+ name: "WalletCallExecutionFailedException",
323
+ inputs: [
324
+ { name: "index", type: "uint256", internalType: "uint256" },
325
+ { name: "reason", type: "bytes", internalType: "bytes" }
326
+ ]
327
+ },
328
+ { type: "error", name: "ZeroAddressException", inputs: [] }
329
+ ];
330
+ export {
331
+ iSecuritizeKYCFactoryAbi
332
+ };
@@ -7,7 +7,7 @@ import {
7
7
  } from "viem";
8
8
  import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
9
9
  import { ierc20Abi } from "../abi/iERC20.js";
10
- import { iCreditFacadeV300Abi, iPoolV300Abi } from "../abi/v300.js";
10
+ import { iCreditFacadeV300Abi } from "../abi/v300.js";
11
11
  import {
12
12
  ADDRESS_0X0,
13
13
  AddressMap,
@@ -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: iPoolV300Abi,
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 });