@gearbox-protocol/sdk 13.1.0 → 13.2.0-next.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 (96) hide show
  1. package/dist/cjs/abi/310/iSecuritizeDegenNFT.js +263 -0
  2. package/dist/cjs/abi/310/iSecuritizeKYCFactory.js +278 -0
  3. package/dist/cjs/{sdk/pools/PoolServiceV310.js → abi/iStateSerializer.js} +14 -8
  4. package/dist/cjs/dev/AccountOpener.js +45 -5
  5. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +462 -104
  6. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +16 -5
  7. package/dist/cjs/sdk/base/ChainContractsRegister.js +1 -1
  8. package/dist/cjs/sdk/base/TokensMeta.js +255 -32
  9. package/dist/cjs/sdk/base/index.js +2 -0
  10. package/dist/cjs/sdk/{constants/phantom-tokens.js → base/token-types.js} +9 -3
  11. package/dist/cjs/sdk/chain/chains.js +2 -1
  12. package/dist/cjs/sdk/constants/index.js +0 -2
  13. package/dist/cjs/sdk/market/MarketRegister.js +2 -2
  14. package/dist/cjs/sdk/market/MarketSuite.js +6 -0
  15. package/dist/cjs/{plugins/zappers/extraZappers.js → sdk/market/ZapperRegister.js} +110 -6
  16. package/dist/cjs/sdk/market/index.js +3 -1
  17. package/dist/cjs/sdk/market/pool/PoolSuite.js +3 -0
  18. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +17 -2
  19. package/dist/cjs/sdk/market/pool/SecuritizeKYCFactory.js +97 -0
  20. package/dist/cjs/sdk/market/pool/index.js +4 -0
  21. package/dist/cjs/sdk/pools/PoolService.js +391 -0
  22. package/dist/cjs/sdk/pools/index.js +2 -4
  23. package/dist/cjs/sdk/utils/AddressMap.js +1 -1
  24. package/dist/cjs/sdk/utils/viem/sendRawTx.js +16 -0
  25. package/dist/esm/abi/310/iSecuritizeDegenNFT.js +239 -0
  26. package/dist/esm/abi/310/iSecuritizeKYCFactory.js +254 -0
  27. package/dist/esm/abi/iStateSerializer.js +12 -0
  28. package/dist/esm/dev/AccountOpener.js +47 -6
  29. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +462 -104
  30. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +16 -5
  31. package/dist/esm/sdk/base/ChainContractsRegister.js +1 -1
  32. package/dist/esm/sdk/base/TokensMeta.js +261 -32
  33. package/dist/esm/sdk/base/index.js +1 -0
  34. package/dist/esm/sdk/{constants/phantom-tokens.js → base/token-types.js} +4 -0
  35. package/dist/esm/sdk/chain/chains.js +2 -1
  36. package/dist/esm/sdk/constants/index.js +0 -1
  37. package/dist/esm/sdk/market/MarketRegister.js +2 -2
  38. package/dist/esm/sdk/market/MarketSuite.js +6 -0
  39. package/dist/esm/{plugins/zappers/extraZappers.js → sdk/market/ZapperRegister.js} +109 -2
  40. package/dist/esm/sdk/market/index.js +1 -0
  41. package/dist/esm/sdk/market/pool/PoolSuite.js +3 -0
  42. package/dist/esm/sdk/market/pool/PoolV310Contract.js +17 -2
  43. package/dist/esm/sdk/market/pool/SecuritizeKYCFactory.js +73 -0
  44. package/dist/esm/sdk/market/pool/index.js +2 -0
  45. package/dist/esm/sdk/pools/PoolService.js +371 -0
  46. package/dist/esm/sdk/pools/index.js +1 -2
  47. package/dist/esm/sdk/utils/AddressMap.js +1 -1
  48. package/dist/esm/sdk/utils/viem/sendRawTx.js +19 -1
  49. package/dist/types/abi/310/iSecuritizeDegenNFT.d.ts +324 -0
  50. package/dist/types/abi/310/iSecuritizeKYCFactory.d.ts +322 -0
  51. package/dist/types/abi/iStateSerializer.d.ts +11 -0
  52. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +123 -27
  53. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
  54. package/dist/types/sdk/accounts/types.d.ts +108 -8
  55. package/dist/types/sdk/base/TokensMeta.d.ts +34 -18
  56. package/dist/types/sdk/base/index.d.ts +1 -0
  57. package/dist/types/sdk/base/token-types.d.ts +33 -0
  58. package/dist/types/sdk/base/types.d.ts +0 -1
  59. package/dist/types/sdk/chain/chains.d.ts +1 -1
  60. package/dist/types/sdk/constants/index.d.ts +0 -1
  61. package/dist/types/sdk/market/MarketRegister.d.ts +2 -2
  62. package/dist/types/sdk/market/MarketSuite.d.ts +3 -0
  63. package/dist/types/sdk/market/ZapperRegister.d.ts +17 -0
  64. package/dist/types/sdk/market/index.d.ts +1 -0
  65. package/dist/types/sdk/market/pool/PoolSuite.d.ts +2 -0
  66. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +6 -2
  67. package/dist/types/sdk/market/pool/SecuritizeKYCFactory.d.ts +345 -0
  68. package/dist/types/sdk/market/pool/index.d.ts +2 -0
  69. package/dist/types/sdk/market/types.d.ts +10 -0
  70. package/dist/types/sdk/pools/PoolService.d.ts +14 -0
  71. package/dist/types/sdk/pools/index.d.ts +1 -2
  72. package/dist/types/sdk/pools/types.d.ts +84 -63
  73. package/dist/types/sdk/utils/AddressMap.d.ts +1 -1
  74. package/dist/types/sdk/utils/viem/sendRawTx.d.ts +5 -1
  75. package/package.json +1 -1
  76. package/dist/cjs/plugins/zappers/ZappersPlugin.js +0 -144
  77. package/dist/cjs/plugins/zappers/index.js +0 -26
  78. package/dist/cjs/plugins/zappers/package.json +0 -1
  79. package/dist/cjs/sdk/pools/AbstractPoolService.js +0 -137
  80. package/dist/cjs/sdk/pools/createPoolService.js +0 -35
  81. package/dist/esm/plugins/zappers/ZappersPlugin.js +0 -126
  82. package/dist/esm/plugins/zappers/index.js +0 -3
  83. package/dist/esm/plugins/zappers/package.json +0 -1
  84. package/dist/esm/sdk/pools/AbstractPoolService.js +0 -113
  85. package/dist/esm/sdk/pools/PoolServiceV310.js +0 -6
  86. package/dist/esm/sdk/pools/createPoolService.js +0 -11
  87. package/dist/types/plugins/zappers/ZappersPlugin.d.ts +0 -18
  88. package/dist/types/plugins/zappers/extraZappers.d.ts +0 -6
  89. package/dist/types/plugins/zappers/index.d.ts +0 -3
  90. package/dist/types/plugins/zappers/types.d.ts +0 -12
  91. package/dist/types/sdk/constants/phantom-tokens.d.ts +0 -2
  92. package/dist/types/sdk/pools/AbstractPoolService.d.ts +0 -9
  93. package/dist/types/sdk/pools/PoolServiceV310.d.ts +0 -4
  94. package/dist/types/sdk/pools/createPoolService.d.ts +0 -3
  95. /package/dist/cjs/{plugins/zappers → sdk/market}/types.js +0 -0
  96. /package/dist/esm/{plugins/zappers → sdk/market}/types.js +0 -0
@@ -65,7 +65,7 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
65
65
  })
66
66
  };
67
67
  const calls = [...priceUpdatesCalls, addBotCall];
68
- const tx = targetContract.type === "creditAccount" ? cm.creditFacade.multicall(targetContract.creditAccount, calls) : void 0;
68
+ const tx = targetContract.type === "creditAccount" ? await this.multicallTx(cm, targetContract.creditAccount, calls) : void 0;
69
69
  return { tx, calls, creditFacade: cm.creditFacade };
70
70
  }
71
71
  /**
@@ -100,7 +100,7 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
100
100
  averageQuota
101
101
  })
102
102
  ];
103
- const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
103
+ const tx = await this.multicallTx(cm, creditAccount.creditAccount, calls);
104
104
  return { tx, calls, creditFacade: cm.creditFacade };
105
105
  }
106
106
  /**
@@ -113,11 +113,13 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
113
113
  creditAccount: ca,
114
114
  permits,
115
115
  to,
116
- tokensToClaim
116
+ tokensToClaim,
117
+ calls: wrapCalls = []
117
118
  }) {
118
119
  const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
119
120
  const addCollateral = collateralAssets.filter((a) => a.balance > 0);
120
121
  const router = this.sdk.routerFor(ca);
122
+ const unwrapCalls = await this.getRedeemDiffCalls(1n, ca.creditManager) ?? [];
121
123
  const claimPath = await router.findClaimAllRewards({
122
124
  tokensToClaim,
123
125
  creditAccount: ca
@@ -129,14 +131,21 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
129
131
  const calls = [
130
132
  ...operation === "close" ? [] : priceUpdates,
131
133
  ...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
134
+ ...wrapCalls,
132
135
  ...this.prepareDisableQuotas(ca),
133
136
  ...this.prepareDecreaseDebt(ca),
137
+ ...unwrapCalls,
134
138
  ...claimPath.calls,
135
139
  ...assetsToWithdraw.map(
136
140
  (t) => this.prepareWithdrawToken(ca.creditFacade, t.token, import_math.MAX_UINT256, to)
137
141
  )
138
142
  ];
139
- const tx = operation === "close" ? cm.creditFacade.closeCreditAccount(ca.creditAccount, calls) : cm.creditFacade.multicall(ca.creditAccount, calls);
143
+ const tx = await this.closeCreditAccountTx(
144
+ cm,
145
+ ca.creditAccount,
146
+ calls,
147
+ operation
148
+ );
140
149
  return { tx, calls, creditFacade: cm.creditFacade };
141
150
  }
142
151
  /**
@@ -160,11 +169,13 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
160
169
  creditManager: ca.creditManager,
161
170
  creditAccount: ca
162
171
  });
172
+ const wrapCalls = await this.getDepositDiffCalls(1n, ca.creditManager) ?? [];
163
173
  const addCollateral = collateralAssets.filter((a) => a.balance > 0);
164
174
  const calls = [
165
175
  ...priceUpdates,
166
176
  ...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
167
177
  ...claimPath.calls,
178
+ ...wrapCalls,
168
179
  ...assetsToWithdraw.map(
169
180
  (t) => this.prepareWithdrawToken(ca.creditFacade, t.token, import_math.MAX_UINT256, to)
170
181
  )
@@ -208,7 +219,7 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
208
219
  ...claimPath.calls,
209
220
  ...this.prepareUpdateQuotas(ca.creditFacade, { minQuota, averageQuota })
210
221
  ];
211
- const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
222
+ const tx = await this.multicallTx(cm, ca.creditAccount, calls);
212
223
  return { tx, calls, creditFacade: cm.creditFacade };
213
224
  }
214
225
  async previewWithdrawLlamathenaProportionally(_) {
@@ -38,7 +38,7 @@ class ChainContractsRegister {
38
38
  logger;
39
39
  constructor(client, logger) {
40
40
  this.client = client;
41
- this.tokensMeta = new import_TokensMeta.TokensMeta(client);
41
+ this.tokensMeta = new import_TokensMeta.TokensMeta(client, logger);
42
42
  this.logger = logger;
43
43
  }
44
44
  resetContracts() {
@@ -21,18 +21,36 @@ __export(TokensMeta_exports, {
21
21
  TokensMeta: () => TokensMeta
22
22
  });
23
23
  module.exports = __toCommonJS(TokensMeta_exports);
24
+ var import_viem = require("viem");
25
+ var import_iSecuritizeDegenNFT = require("../../abi/310/iSecuritizeDegenNFT.js");
26
+ var import_iSecuritizeKYCFactory = require("../../abi/310/iSecuritizeKYCFactory.js");
27
+ var import_iStateSerializer = require("../../abi/iStateSerializer.js");
24
28
  var import_iVersion = require("../../abi/iVersion.js");
25
29
  var import_utils = require("../utils/index.js");
30
+ var import_token_types = require("./token-types.js");
26
31
  class TokensMeta extends import_utils.AddressMap {
27
32
  #client;
28
- #phantomTokensLoaded;
29
- constructor(client) {
33
+ #tokenDataLoaded = new import_utils.AddressSet();
34
+ #logger;
35
+ constructor(client, logger) {
30
36
  super(void 0, "tokensMeta");
31
37
  this.#client = client;
38
+ this.#logger = logger?.child?.({ name: "TokensMeta" }) ?? logger;
32
39
  }
33
40
  reset() {
34
41
  this.clear();
35
- this.#phantomTokensLoaded = void 0;
42
+ this.#tokenDataLoaded.clear();
43
+ }
44
+ upsert(address, value) {
45
+ let v = value;
46
+ const existing = this.get(address);
47
+ if (existing && v) {
48
+ v = {
49
+ ...existing,
50
+ ...v
51
+ };
52
+ }
53
+ super.upsert(address, v);
36
54
  }
37
55
  symbol(token) {
38
56
  return this.mustGet(token).symbol;
@@ -41,27 +59,78 @@ class TokensMeta extends import_utils.AddressMap {
41
59
  return this.mustGet(token).decimals;
42
60
  }
43
61
  /**
44
- * Returns the phantom token type for a given token, or undefined for normal tokens
45
- * Throws if the phantom token data is not loaded
62
+ * Returns true if the token is a phantom token, throws if the token data is not loaded
63
+ * @param t
64
+ * @returns
65
+ */
66
+ isPhantomToken(t) {
67
+ if (!this.#tokenDataLoaded.has(t.addr)) {
68
+ throw new Error(
69
+ `extended token data not loaded for ${t.symbol} (${t.addr})`
70
+ );
71
+ }
72
+ return !!t.contractType?.startsWith("PHANTOM_TOKEN::");
73
+ }
74
+ /**
75
+ * Returns true if the token is a KYC underlying token, throws if the token data is not loaded
76
+ * @param t
77
+ * @returns
46
78
  */
47
- phantomTokenType(token) {
48
- if (!this.#phantomTokensLoaded?.has(token)) {
49
- throw new Error("phantom token data not loaded");
79
+ isKYCUnderlying(t) {
80
+ if (!this.#tokenDataLoaded.has(t.addr)) {
81
+ throw new Error(
82
+ `extended token data not loaded for ${t.symbol} (${t.addr})`
83
+ );
50
84
  }
51
- return this.mustGet(token).phantomTokenType;
85
+ return !!t.contractType?.startsWith("KYC_UNDERLYING::");
86
+ }
87
+ /**
88
+ * Returns true if the token is a DSToken, throws if the token data is not loaded
89
+ * @param t
90
+ * @returns
91
+ */
92
+ isDSToken(t) {
93
+ if (!this.#tokenDataLoaded.has(t.addr)) {
94
+ throw new Error(
95
+ `extended token data not loaded for ${t.symbol} (${t.addr})`
96
+ );
97
+ }
98
+ return !!t.isDSToken;
52
99
  }
53
100
  /**
54
101
  * Returns a map of all phantom tokens
55
- * Throws if the phantom token data is not loaded
102
+ * Throws if token data is not loaded
56
103
  */
57
104
  get phantomTokens() {
58
- if (!this.#phantomTokensLoaded) {
59
- throw new Error("phantom tokens not loaded");
105
+ const result = new import_utils.AddressMap();
106
+ for (const [token, meta] of this.entries()) {
107
+ if (this.isPhantomToken(meta)) {
108
+ result.upsert(token, meta);
109
+ }
60
110
  }
61
- return new import_utils.AddressMap(
62
- this.entries().filter(([_, v]) => !!v.phantomTokenType),
63
- "phantomTokens"
64
- );
111
+ return result;
112
+ }
113
+ /**
114
+ * Returns a map of all KYC underlying tokens
115
+ * Throws if token data is not loaded
116
+ */
117
+ get kycUnderlyings() {
118
+ const result = new import_utils.AddressMap();
119
+ for (const [token, meta] of this.entries()) {
120
+ if (this.isKYCUnderlying(meta)) {
121
+ result.upsert(token, meta);
122
+ }
123
+ }
124
+ return result;
125
+ }
126
+ get dsTokens() {
127
+ const result = new import_utils.AddressMap();
128
+ for (const [token, meta] of this.entries()) {
129
+ if (this.isDSToken(meta)) {
130
+ result.upsert(token, meta);
131
+ }
132
+ }
133
+ return result;
65
134
  }
66
135
  formatBN(arg0, arg1, arg2) {
67
136
  const token = typeof arg0 === "object" ? arg0.token : arg0;
@@ -82,30 +151,184 @@ class TokensMeta extends import_utils.AddressMap {
82
151
  return meta;
83
152
  }
84
153
  /**
85
- * Loads phantom token data for all known tokens from chain
154
+ * Loads token information about phantom tokens, KYC underlying tokens and DSTokens
155
+ *
156
+ * @param tokens - tokens to load data for, defaults to all tokens
86
157
  */
87
- async loadPhantomTokens() {
88
- this.#phantomTokensLoaded = new import_utils.AddressSet();
89
- const tokens = this.keys();
158
+ async loadTokenData(...tokens) {
159
+ const tokenz = new import_utils.AddressSet(tokens.length > 0 ? tokens : this.keys());
160
+ const tokensToLoad = Array.from(tokenz.difference(this.#tokenDataLoaded));
161
+ if (tokensToLoad.length === 0) {
162
+ return;
163
+ }
90
164
  const resp = await this.#client.multicall({
91
- contracts: tokens.map(
92
- (t) => ({
93
- address: t,
94
- abi: import_iVersion.iVersionAbi,
95
- functionName: "contractType"
96
- })
165
+ contracts: tokensToLoad.flatMap(
166
+ (t) => [
167
+ {
168
+ address: t,
169
+ abi: import_iVersion.iVersionAbi,
170
+ functionName: "contractType"
171
+ },
172
+ {
173
+ address: t,
174
+ abi: import_iStateSerializer.iStateSerializerAbi,
175
+ functionName: "serialize"
176
+ }
177
+ ]
97
178
  ),
98
179
  allowFailure: true,
99
180
  batchSize: 0
100
181
  });
101
- for (let i = 0; i < resp.length; i++) {
102
- if (resp[i].status === "success") {
103
- const contractType = (0, import_utils.bytes32ToString)(resp[i].result);
104
- if (contractType.startsWith("PHANTOM_TOKEN::")) {
105
- this.mustGet(tokens[i]).phantomTokenType = contractType;
182
+ this.#logger?.debug(`loaded ${resp.length} contract types`);
183
+ const kycFactories = new import_utils.AddressSet();
184
+ for (let i = 0; i < tokensToLoad.length; i++) {
185
+ const meta = this.#overrideTokenMeta(
186
+ tokensToLoad[i],
187
+ resp[2 * i],
188
+ resp[2 * i + 1]
189
+ );
190
+ this.#tokenDataLoaded.add(tokensToLoad[i]);
191
+ if (this.isKYCUnderlying(meta)) {
192
+ kycFactories.add(meta.kycFactory);
193
+ }
194
+ }
195
+ this.#logger?.debug(`found ${kycFactories.size} KYC factories`);
196
+ await this.#loadDSTokens(kycFactories);
197
+ }
198
+ #overrideTokenMeta(token, contractTypeResp, serializeResp) {
199
+ const meta = this.mustGet(token);
200
+ if (contractTypeResp.status === "success") {
201
+ const contractType = (0, import_utils.bytes32ToString)(contractTypeResp.result);
202
+ if (contractType.startsWith("KYC_UNDERLYING::")) {
203
+ if (serializeResp.status === "success") {
204
+ this.#overrideKYCUnderlying(meta, contractType, serializeResp.result);
205
+ } else {
206
+ throw new Error(
207
+ `token ${meta.symbol} (${token}) is ${contractType} but serialize failed: ${serializeResp.error}`
208
+ );
106
209
  }
210
+ } else {
211
+ this.upsert(token, {
212
+ ...meta,
213
+ contractType
214
+ });
107
215
  }
108
- this.#phantomTokensLoaded.add(tokens[i]);
216
+ this.#logger?.debug(`token ${meta.symbol} is ${contractType}`);
217
+ }
218
+ return this.mustGet(token);
219
+ }
220
+ #overrideKYCUnderlying(meta, contractType, serialized) {
221
+ if (contractType === import_token_types.KYC_UNDERLYING_DEFAULT) {
222
+ const decoded = (0, import_viem.decodeAbiParameters)(
223
+ [
224
+ { type: "address", name: "kycFactory" },
225
+ { type: "address", name: "asset" }
226
+ ],
227
+ serialized
228
+ );
229
+ this.upsert(meta.addr, {
230
+ ...meta,
231
+ contractType,
232
+ kycFactory: decoded[0],
233
+ asset: decoded[1]
234
+ });
235
+ } else if (contractType === import_token_types.KYC_UNDERLYING_ON_DEMAND) {
236
+ const decoded = (0, import_viem.decodeAbiParameters)(
237
+ [
238
+ { type: "address", name: "kycFactory" },
239
+ { type: "address", name: "asset" },
240
+ { type: "address", name: "pool" },
241
+ { type: "address", name: "liquidityProvider" }
242
+ ],
243
+ serialized
244
+ );
245
+ this.upsert(meta.addr, {
246
+ ...meta,
247
+ contractType,
248
+ kycFactory: decoded[0],
249
+ asset: decoded[1],
250
+ pool: decoded[2],
251
+ liquidityProvider: decoded[3]
252
+ });
253
+ }
254
+ }
255
+ async #loadDSTokens(kycFactories) {
256
+ const degenNFTs = await this.#client.multicall({
257
+ contracts: kycFactories.map((address) => {
258
+ return {
259
+ address,
260
+ abi: import_iSecuritizeKYCFactory.iSecuritizeKYCFactoryAbi,
261
+ functionName: "getDegenNFT"
262
+ };
263
+ }),
264
+ allowFailure: false,
265
+ batchSize: 0
266
+ });
267
+ const resp = await this.#client.multicall({
268
+ contracts: degenNFTs.map((address) => {
269
+ return {
270
+ address,
271
+ abi: import_iSecuritizeDegenNFT.iSecuritizeDegenNFTAbi,
272
+ functionName: "getDSTokens"
273
+ };
274
+ }),
275
+ allowFailure: false,
276
+ batchSize: 0
277
+ });
278
+ const dsToken = new import_utils.AddressSet(resp.flat());
279
+ const tokensToLoad = dsToken.difference(new Set(this.keys()));
280
+ this.#logger?.debug(
281
+ `found ${dsToken.size} DSTokens in KYC factories, need to load ${tokensToLoad.size} basic metadata`
282
+ );
283
+ await this.#loadWithoutCompressor(tokensToLoad);
284
+ for (const token of dsToken) {
285
+ const meta = this.mustGet(token);
286
+ this.upsert(token, {
287
+ ...meta,
288
+ isDSToken: true
289
+ });
290
+ this.#tokenDataLoaded.add(token);
291
+ this.#logger?.debug(`token ${meta.symbol} (${token}) is a DSToken`);
292
+ }
293
+ }
294
+ async #loadWithoutCompressor(tokens_) {
295
+ if (tokens_.size === 0) {
296
+ return;
297
+ }
298
+ const tokens = Array.from(tokens_);
299
+ const resp = await this.#client.multicall({
300
+ contracts: tokens.flatMap(
301
+ (t) => [
302
+ {
303
+ address: t,
304
+ abi: import_viem.erc20Abi,
305
+ functionName: "symbol"
306
+ },
307
+ {
308
+ address: t,
309
+ abi: import_viem.erc20Abi,
310
+ functionName: "name"
311
+ },
312
+ {
313
+ address: t,
314
+ abi: import_viem.erc20Abi,
315
+ functionName: "decimals"
316
+ }
317
+ ]
318
+ ),
319
+ allowFailure: false,
320
+ batchSize: 0
321
+ });
322
+ this.#logger?.debug(
323
+ `loaded ${resp.length} basic metadata without compressor`
324
+ );
325
+ for (let i = 0; i < tokens.length; i++) {
326
+ this.upsert(tokens[i], {
327
+ addr: tokens[i],
328
+ symbol: resp[3 * i],
329
+ name: resp[3 * i + 1],
330
+ decimals: resp[3 * i + 2]
331
+ });
109
332
  }
110
333
  }
111
334
  }
@@ -22,6 +22,7 @@ __reExport(base_exports, require("./errors.js"), module.exports);
22
22
  __reExport(base_exports, require("./PlaceholderContract.js"), module.exports);
23
23
  __reExport(base_exports, require("./SDKConstruct.js"), module.exports);
24
24
  __reExport(base_exports, require("./TokensMeta.js"), module.exports);
25
+ __reExport(base_exports, require("./token-types.js"), module.exports);
25
26
  __reExport(base_exports, require("./types.js"), module.exports);
26
27
  // Annotate the CommonJS export names for ESM import in node:
27
28
  0 && (module.exports = {
@@ -32,5 +33,6 @@ __reExport(base_exports, require("./types.js"), module.exports);
32
33
  ...require("./PlaceholderContract.js"),
33
34
  ...require("./SDKConstruct.js"),
34
35
  ...require("./TokensMeta.js"),
36
+ ...require("./token-types.js"),
35
37
  ...require("./types.js")
36
38
  });
@@ -16,11 +16,13 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var phantom_tokens_exports = {};
20
- __export(phantom_tokens_exports, {
19
+ var token_types_exports = {};
20
+ __export(token_types_exports, {
21
+ KYC_UNDERLYING_DEFAULT: () => KYC_UNDERLYING_DEFAULT,
22
+ KYC_UNDERLYING_ON_DEMAND: () => KYC_UNDERLYING_ON_DEMAND,
21
23
  PHANTOM_TOKEN_CONTRACT_TYPES: () => PHANTOM_TOKEN_CONTRACT_TYPES
22
24
  });
23
- module.exports = __toCommonJS(phantom_tokens_exports);
25
+ module.exports = __toCommonJS(token_types_exports);
24
26
  const PHANTOM_TOKEN_CONTRACT_TYPES = [
25
27
  "PHANTOM_TOKEN::CONVEX",
26
28
  "PHANTOM_TOKEN::INFINIFI_UNWIND",
@@ -30,7 +32,11 @@ const PHANTOM_TOKEN_CONTRACT_TYPES = [
30
32
  "PHANTOM_TOKEN::STAKING_REWARDS",
31
33
  "PHANTOM_TOKEN::UPSHIFT_WITHDRAW"
32
34
  ];
35
+ const KYC_UNDERLYING_DEFAULT = "KYC_UNDERLYING::DEFAULT";
36
+ const KYC_UNDERLYING_ON_DEMAND = "KYC_UNDERLYING::ON_DEMAND";
33
37
  // Annotate the CommonJS export names for ESM import in node:
34
38
  0 && (module.exports = {
39
+ KYC_UNDERLYING_DEFAULT,
40
+ KYC_UNDERLYING_ON_DEMAND,
35
41
  PHANTOM_TOKEN_CONTRACT_TYPES
36
42
  });
@@ -79,7 +79,8 @@ const chains = {
79
79
  "0x601067eba24bb5b558a184fc082525637e96a42d": "Gami Labs"
80
80
  },
81
81
  testMarketConfigurators: {
82
- "0x99df7330bf42d596af2e9d9836d4fc2077c574aa": "M11 Credit"
82
+ "0x99df7330bf42d596af2e9d9836d4fc2077c574aa": "M11 Credit",
83
+ "0xE0527dE5908B3fc2e054B7eEE0DeF6c9965AbF24": "Securitize"
83
84
  },
84
85
  isPublic: true,
85
86
  wellKnownToken: {
@@ -21,7 +21,6 @@ __reExport(constants_exports, require("./bot-permissions.js"), module.exports);
21
21
  __reExport(constants_exports, require("./math.js"), module.exports);
22
22
  __reExport(constants_exports, require("./networks.js"), module.exports);
23
23
  __reExport(constants_exports, require("./periphery.js"), module.exports);
24
- __reExport(constants_exports, require("./phantom-tokens.js"), module.exports);
25
24
  __reExport(constants_exports, require("./versions.js"), module.exports);
26
25
  // Annotate the CommonJS export names for ESM import in node:
27
26
  0 && (module.exports = {
@@ -31,6 +30,5 @@ __reExport(constants_exports, require("./versions.js"), module.exports);
31
30
  ...require("./math.js"),
32
31
  ...require("./networks.js"),
33
32
  ...require("./periphery.js"),
34
- ...require("./phantom-tokens.js"),
35
33
  ...require("./versions.js")
36
34
  });
@@ -22,13 +22,13 @@ __export(MarketRegister_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(MarketRegister_exports);
24
24
  var import_marketCompressor = require("../../abi/compressors/marketCompressor.js");
25
- var import_base = require("../base/index.js");
26
25
  var import_constants = require("../constants/index.js");
27
26
  var import_utils = require("../utils/index.js");
28
27
  var import_viem = require("../utils/viem/index.js");
29
28
  var import_MarketConfiguratorContract = require("./MarketConfiguratorContract.js");
30
29
  var import_MarketSuite = require("./MarketSuite.js");
31
- class MarketRegister extends import_base.SDKConstruct {
30
+ var import_ZapperRegister = require("./ZapperRegister.js");
31
+ class MarketRegister extends import_ZapperRegister.ZapperRegister {
32
32
  /**
33
33
  * Mapping pool.address -> MarketSuite
34
34
  */
@@ -62,6 +62,12 @@ class MarketSuite extends import_base.SDKConstruct {
62
62
  this.priceOracle = (0, import_oracle.createPriceOracle)(sdk, marketData.priceOracle);
63
63
  this.lossPolicy = (0, import_loss_policy.createLossPolicy)(sdk, marketData.lossPolicy);
64
64
  }
65
+ get underlying() {
66
+ return this.pool.underlying;
67
+ }
68
+ async getKYCFactory() {
69
+ return this.pool.getKYCFactory();
70
+ }
65
71
  get dirty() {
66
72
  return this.configurator.dirty || this.pool.dirty || this.priceOracle.dirty || this.creditManagers.some((cm) => cm.dirty);
67
73
  }
@@ -16,12 +16,115 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var extraZappers_exports = {};
20
- __export(extraZappers_exports, {
21
- extraZappers: () => extraZappers
19
+ var ZapperRegister_exports = {};
20
+ __export(ZapperRegister_exports, {
21
+ ZapperRegister: () => ZapperRegister
22
22
  });
23
- module.exports = __toCommonJS(extraZappers_exports);
24
- const extraZappers = {
23
+ module.exports = __toCommonJS(ZapperRegister_exports);
24
+ var import_peripheryCompressor = require("../../abi/compressors/peripheryCompressor.js");
25
+ var import_base = require("../base/index.js");
26
+ var import_constants = require("../constants/index.js");
27
+ var import_utils = require("../utils/index.js");
28
+ class ZapperRegister extends import_base.SDKConstruct {
29
+ /**
30
+ * Mapping pool.address -> ZapperData[]
31
+ * Needs to be loaded explicitly using loadZappers method
32
+ */
33
+ #zappers;
34
+ /**
35
+ * Load zappers for all pools using periphery compressor, adds hardcoded zappers
36
+ */
37
+ async loadZappers(force) {
38
+ if (!force && this.#zappers) {
39
+ return;
40
+ }
41
+ const [pcAddr] = this.sdk.addressProvider.mustGetLatest(
42
+ import_constants.AP_PERIPHERY_COMPRESSOR,
43
+ import_constants.VERSION_RANGE_310
44
+ );
45
+ this.logger?.debug(`loading zappers with periphery compressor ${pcAddr}`);
46
+ const markets = this.sdk.marketRegister.markets;
47
+ const resp = await this.client.multicall({
48
+ contracts: markets.map(
49
+ (m) => ({
50
+ abi: import_peripheryCompressor.peripheryCompressorAbi,
51
+ address: pcAddr,
52
+ functionName: "getZappers",
53
+ args: [m.configurator.address, m.pool.pool.address]
54
+ })
55
+ ),
56
+ allowFailure: true,
57
+ batchSize: 0
58
+ });
59
+ this.#zappers = new import_utils.AddressMap(void 0, "zappers");
60
+ for (let i = 0; i < resp.length; i++) {
61
+ const { status, result, error } = resp[i];
62
+ const marketConfigurator = markets[i].configurator.address;
63
+ const pool = markets[i].pool.pool.address;
64
+ if (status === "success") {
65
+ for (const z of result) {
66
+ this.#addZapper({ ...z, pool, type: "base" });
67
+ }
68
+ } else {
69
+ this.logger?.error(
70
+ `failed to load zapper for market configurator ${this.labelAddress(
71
+ marketConfigurator
72
+ )} and pool ${this.labelAddress(pool)}: ${error}`
73
+ );
74
+ }
75
+ }
76
+ for (const z of KYC_ZAPPERS[this.networkType] ?? []) {
77
+ this.#addZapper({ ...z, type: "kyc" });
78
+ }
79
+ for (const z of MIGRATION_ZAPPERS[this.networkType] ?? []) {
80
+ this.#addZapper({ ...z, type: "migration" });
81
+ }
82
+ }
83
+ #addZapper(z) {
84
+ if (BROKEN_ZAPPERS.has(z.baseParams.addr)) {
85
+ return;
86
+ }
87
+ const existing = this.zappers.get(z.pool);
88
+ if (existing) {
89
+ const hasZapper = existing.some(
90
+ (zz) => (0, import_utils.hexEq)(zz.baseParams.addr, z.baseParams.addr)
91
+ );
92
+ if (!hasZapper) {
93
+ existing.push(z);
94
+ }
95
+ } else {
96
+ this.zappers.upsert(z.pool, [z]);
97
+ }
98
+ const zappersTokens = [z.tokenIn, z.tokenOut];
99
+ for (const t of zappersTokens) {
100
+ this.sdk.tokensMeta.upsert(t.addr, t);
101
+ this.sdk.setAddressLabel(t.addr, t.symbol);
102
+ }
103
+ }
104
+ get zappers() {
105
+ if (!this.#zappers) {
106
+ throw new Error("zappers not loaded, call loadZappers first");
107
+ }
108
+ return this.#zappers;
109
+ }
110
+ poolZappers(pool) {
111
+ return this.zappers.get(pool) ?? [];
112
+ }
113
+ /**
114
+ * Can return multiple zappers if there are multiple zappers for the same tokenIn and tokenOut
115
+ */
116
+ getZapper(pool, tokenIn, tokenOut) {
117
+ const zappers = this.zappers.get(pool)?.filter(
118
+ (z) => (0, import_utils.hexEq)(z.tokenIn.addr, tokenIn) && (0, import_utils.hexEq)(z.tokenOut.addr, tokenOut)
119
+ );
120
+ return zappers;
121
+ }
122
+ }
123
+ const BROKEN_ZAPPERS = new import_utils.AddressMap(
124
+ [["0x90D66b03EC4D462e42e3c7741049FB46a4a03B69", true]],
125
+ "brokenZappers"
126
+ );
127
+ const MIGRATION_ZAPPERS = {
25
128
  Mainnet: [
26
129
  {
27
130
  baseParams: {
@@ -130,7 +233,8 @@ const extraZappers = {
130
233
  }
131
234
  ]
132
235
  };
236
+ const KYC_ZAPPERS = {};
133
237
  // Annotate the CommonJS export names for ESM import in node:
134
238
  0 && (module.exports = {
135
- extraZappers
239
+ ZapperRegister
136
240
  });
@@ -22,6 +22,7 @@ __reExport(market_exports, require("./MarketSuite.js"), module.exports);
22
22
  __reExport(market_exports, require("./oracle/index.js"), module.exports);
23
23
  __reExport(market_exports, require("./pool/index.js"), module.exports);
24
24
  __reExport(market_exports, require("./pricefeeds/index.js"), module.exports);
25
+ __reExport(market_exports, require("./types.js"), module.exports);
25
26
  // Annotate the CommonJS export names for ESM import in node:
26
27
  0 && (module.exports = {
27
28
  ...require("./adapters/index.js"),
@@ -30,5 +31,6 @@ __reExport(market_exports, require("./pricefeeds/index.js"), module.exports);
30
31
  ...require("./MarketSuite.js"),
31
32
  ...require("./oracle/index.js"),
32
33
  ...require("./pool/index.js"),
33
- ...require("./pricefeeds/index.js")
34
+ ...require("./pricefeeds/index.js"),
35
+ ...require("./types.js")
34
36
  });
@@ -88,6 +88,9 @@ class PoolSuite extends import_base.SDKConstruct {
88
88
  get underlying() {
89
89
  return this.pool.underlying;
90
90
  }
91
+ async getKYCFactory() {
92
+ return this.pool.getKYCFactory();
93
+ }
91
94
  get dirty() {
92
95
  return this.pool.dirty || this.rateKeeper.dirty || this.pqk.dirty || this.interestRateModel.dirty;
93
96
  }