@gearbox-protocol/sdk 13.5.0-next.1 → 13.5.0-next.3

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 (53) hide show
  1. package/dist/cjs/dev/AccountOpener.js +5 -45
  2. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +6 -339
  3. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +1 -13
  4. package/dist/cjs/sdk/base/TokensMeta.js +7 -151
  5. package/dist/cjs/sdk/base/token-types.js +0 -6
  6. package/dist/cjs/sdk/chain/chains.js +1 -2
  7. package/dist/cjs/sdk/constants/addresses.js +3 -0
  8. package/dist/cjs/sdk/market/MarketRegister.js +0 -3
  9. package/dist/cjs/sdk/market/MarketSuite.js +0 -3
  10. package/dist/cjs/sdk/market/ZapperRegister.js +0 -123
  11. package/dist/cjs/sdk/market/pool/PoolSuite.js +0 -3
  12. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +2 -17
  13. package/dist/cjs/sdk/market/pool/index.js +0 -4
  14. package/dist/cjs/sdk/pools/PoolService.js +84 -132
  15. package/dist/esm/dev/AccountOpener.js +6 -47
  16. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +6 -339
  17. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +1 -13
  18. package/dist/esm/sdk/base/TokensMeta.js +7 -155
  19. package/dist/esm/sdk/base/token-types.js +0 -4
  20. package/dist/esm/sdk/chain/chains.js +1 -2
  21. package/dist/esm/sdk/constants/addresses.js +2 -0
  22. package/dist/esm/sdk/market/MarketRegister.js +0 -3
  23. package/dist/esm/sdk/market/MarketSuite.js +0 -3
  24. package/dist/esm/sdk/market/ZapperRegister.js +0 -123
  25. package/dist/esm/sdk/market/pool/PoolSuite.js +0 -3
  26. package/dist/esm/sdk/market/pool/PoolV310Contract.js +2 -17
  27. package/dist/esm/sdk/market/pool/index.js +0 -2
  28. package/dist/esm/sdk/pools/PoolService.js +75 -127
  29. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +5 -103
  30. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +2 -4
  31. package/dist/types/sdk/accounts/types.d.ts +6 -130
  32. package/dist/types/sdk/base/TokensMeta.d.ts +3 -20
  33. package/dist/types/sdk/base/token-types.d.ts +1 -21
  34. package/dist/types/sdk/base/types.d.ts +3 -0
  35. package/dist/types/sdk/chain/chains.d.ts +1 -1
  36. package/dist/types/sdk/constants/addresses.d.ts +4 -0
  37. package/dist/types/sdk/market/MarketSuite.d.ts +0 -2
  38. package/dist/types/sdk/market/pool/PoolSuite.d.ts +0 -2
  39. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +2 -6
  40. package/dist/types/sdk/market/pool/index.d.ts +0 -2
  41. package/dist/types/sdk/market/types.d.ts +1 -1
  42. package/dist/types/sdk/pools/PoolService.d.ts +24 -0
  43. package/dist/types/sdk/pools/types.d.ts +9 -8
  44. package/package.json +1 -1
  45. package/dist/cjs/abi/310/iSecuritizeDegenNFT.js +0 -263
  46. package/dist/cjs/abi/310/iSecuritizeKYCFactory.js +0 -278
  47. package/dist/cjs/sdk/market/pool/SecuritizeKYCFactory.js +0 -97
  48. package/dist/esm/abi/310/iSecuritizeDegenNFT.js +0 -239
  49. package/dist/esm/abi/310/iSecuritizeKYCFactory.js +0 -254
  50. package/dist/esm/sdk/market/pool/SecuritizeKYCFactory.js +0 -73
  51. package/dist/types/abi/310/iSecuritizeDegenNFT.d.ts +0 -324
  52. package/dist/types/abi/310/iSecuritizeKYCFactory.d.ts +0 -322
  53. package/dist/types/sdk/market/pool/SecuritizeKYCFactory.d.ts +0 -345
@@ -1,9 +1,6 @@
1
1
  import {
2
- decodeAbiParameters,
3
2
  erc20Abi
4
3
  } from "viem";
5
- import { iSecuritizeDegenNFTAbi } from "../../abi/310/iSecuritizeDegenNFT.js";
6
- import { iSecuritizeKYCFactoryAbi } from "../../abi/310/iSecuritizeKYCFactory.js";
7
4
  import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
8
5
  import { iVersionAbi } from "../../abi/iVersion.js";
9
6
  import {
@@ -12,10 +9,6 @@ import {
12
9
  bytes32ToString,
13
10
  formatBN
14
11
  } from "../utils/index.js";
15
- import {
16
- KYC_UNDERLYING_DEFAULT,
17
- KYC_UNDERLYING_ON_DEMAND
18
- } from "./token-types.js";
19
12
  class TokensMeta extends AddressMap {
20
13
  #client;
21
14
  #tokenDataLoaded = new AddressSet();
@@ -72,32 +65,6 @@ class TokensMeta extends AddressMap {
72
65
  }
73
66
  return !!t.contractType?.startsWith("PHANTOM_TOKEN::");
74
67
  }
75
- /**
76
- * Returns true if the token is a KYC underlying token, throws if the token data is not loaded
77
- * @param t
78
- * @returns
79
- */
80
- isKYCUnderlying(t) {
81
- if (!this.#tokenDataLoaded.has(t.addr)) {
82
- throw new Error(
83
- `extended token data not loaded for ${t.symbol} (${t.addr})`
84
- );
85
- }
86
- return !!t.contractType?.startsWith("KYC_UNDERLYING::");
87
- }
88
- /**
89
- * Returns true if the token is a DSToken, throws if the token data is not loaded
90
- * @param t
91
- * @returns
92
- */
93
- isDSToken(t) {
94
- if (!this.#tokenDataLoaded.has(t.addr)) {
95
- throw new Error(
96
- `extended token data not loaded for ${t.symbol} (${t.addr})`
97
- );
98
- }
99
- return !!t.isDSToken;
100
- }
101
68
  /**
102
69
  * Returns a map of all phantom tokens
103
70
  * Throws if token data is not loaded
@@ -111,28 +78,6 @@ class TokensMeta extends AddressMap {
111
78
  }
112
79
  return result;
113
80
  }
114
- /**
115
- * Returns a map of all KYC underlying tokens
116
- * Throws if token data is not loaded
117
- */
118
- get kycUnderlyings() {
119
- const result = new AddressMap();
120
- for (const [token, meta] of this.entries()) {
121
- if (this.isKYCUnderlying(meta)) {
122
- result.upsert(token, meta);
123
- }
124
- }
125
- return result;
126
- }
127
- get dsTokens() {
128
- const result = new AddressMap();
129
- for (const [token, meta] of this.entries()) {
130
- if (this.isDSToken(meta)) {
131
- result.upsert(token, meta);
132
- }
133
- }
134
- return result;
135
- }
136
81
  formatBN(arg0, arg1, arg2) {
137
82
  const token = typeof arg0 === "object" ? arg0.token : arg0;
138
83
  const amount = typeof arg0 === "object" ? arg0.balance : arg1;
@@ -162,7 +107,8 @@ class TokensMeta extends AddressMap {
162
107
  return meta;
163
108
  }
164
109
  /**
165
- * Loads token information about phantom tokens, KYC underlying tokens and DSTokens
110
+ * Loads token information about phantom tokens
111
+ * Other special tokens may be loaded here in the future
166
112
  *
167
113
  * @param tokens - tokens to load data for, defaults to all tokens
168
114
  */
@@ -191,116 +137,22 @@ class TokensMeta extends AddressMap {
191
137
  batchSize: 0
192
138
  });
193
139
  this.#logger?.debug(`loaded ${resp.length} contract types`);
194
- const kycFactories = new AddressSet();
195
140
  for (let i = 0; i < tokensToLoad.length; i++) {
196
- const meta = this.#overrideTokenMeta(
197
- tokensToLoad[i],
198
- resp[2 * i],
199
- resp[2 * i + 1]
200
- );
141
+ this.#overrideTokenMeta(tokensToLoad[i], resp[2 * i], resp[2 * i + 1]);
201
142
  this.#tokenDataLoaded.add(tokensToLoad[i]);
202
- if (this.isKYCUnderlying(meta)) {
203
- kycFactories.add(meta.kycFactory);
204
- }
205
143
  }
206
- this.#logger?.debug(`found ${kycFactories.size} KYC factories`);
207
- await this.#loadDSTokens(kycFactories);
208
144
  }
209
- #overrideTokenMeta(token, contractTypeResp, serializeResp) {
145
+ #overrideTokenMeta(token, contractTypeResp, _serializeResp) {
210
146
  const meta = this.mustGet(token);
211
147
  if (contractTypeResp.status === "success") {
212
148
  const contractType = bytes32ToString(contractTypeResp.result);
213
- if (contractType.startsWith("KYC_UNDERLYING::")) {
214
- if (serializeResp.status === "success") {
215
- this.#overrideKYCUnderlying(meta, contractType, serializeResp.result);
216
- } else {
217
- throw new Error(
218
- `token ${meta.symbol} (${token}) is ${contractType} but serialize failed: ${serializeResp.error}`
219
- );
220
- }
221
- } else {
222
- this.upsert(token, {
223
- ...meta,
224
- contractType
225
- });
226
- }
227
- this.#logger?.debug(`token ${meta.symbol} is ${contractType}`);
228
- }
229
- return this.mustGet(token);
230
- }
231
- #overrideKYCUnderlying(meta, contractType, serialized) {
232
- if (contractType === KYC_UNDERLYING_DEFAULT) {
233
- const decoded = decodeAbiParameters(
234
- [
235
- { type: "address", name: "kycFactory" },
236
- { type: "address", name: "asset" }
237
- ],
238
- serialized
239
- );
240
- this.upsert(meta.addr, {
241
- ...meta,
242
- contractType,
243
- kycFactory: decoded[0],
244
- asset: decoded[1]
245
- });
246
- } else if (contractType === KYC_UNDERLYING_ON_DEMAND) {
247
- const decoded = decodeAbiParameters(
248
- [
249
- { type: "address", name: "kycFactory" },
250
- { type: "address", name: "asset" },
251
- { type: "address", name: "pool" },
252
- { type: "address", name: "liquidityProvider" }
253
- ],
254
- serialized
255
- );
256
- this.upsert(meta.addr, {
257
- ...meta,
258
- contractType,
259
- kycFactory: decoded[0],
260
- asset: decoded[1],
261
- pool: decoded[2],
262
- liquidityProvider: decoded[3]
263
- });
264
- }
265
- }
266
- async #loadDSTokens(kycFactories) {
267
- const degenNFTs = await this.#client.multicall({
268
- contracts: kycFactories.map((address) => {
269
- return {
270
- address,
271
- abi: iSecuritizeKYCFactoryAbi,
272
- functionName: "getDegenNFT"
273
- };
274
- }),
275
- allowFailure: false,
276
- batchSize: 0
277
- });
278
- const resp = await this.#client.multicall({
279
- contracts: degenNFTs.map((address) => {
280
- return {
281
- address,
282
- abi: iSecuritizeDegenNFTAbi,
283
- functionName: "getDSTokens"
284
- };
285
- }),
286
- allowFailure: false,
287
- batchSize: 0
288
- });
289
- const dsToken = new AddressSet(resp.flat());
290
- const tokensToLoad = dsToken.difference(new Set(this.keys()));
291
- this.#logger?.debug(
292
- `found ${dsToken.size} DSTokens in KYC factories, need to load ${tokensToLoad.size} basic metadata`
293
- );
294
- await this.#loadWithoutCompressor(tokensToLoad);
295
- for (const token of dsToken) {
296
- const meta = this.mustGet(token);
297
149
  this.upsert(token, {
298
150
  ...meta,
299
- isDSToken: true
151
+ contractType
300
152
  });
301
- this.#tokenDataLoaded.add(token);
302
- this.#logger?.debug(`token ${meta.symbol} (${token}) is a DSToken`);
153
+ this.#logger?.debug(`token ${meta.symbol} is ${contractType}`);
303
154
  }
155
+ return this.mustGet(token);
304
156
  }
305
157
  async #loadWithoutCompressor(tokens_) {
306
158
  if (tokens_.size === 0) {
@@ -7,10 +7,6 @@ const PHANTOM_TOKEN_CONTRACT_TYPES = [
7
7
  "PHANTOM_TOKEN::STAKING_REWARDS",
8
8
  "PHANTOM_TOKEN::UPSHIFT_WITHDRAW"
9
9
  ];
10
- const KYC_UNDERLYING_DEFAULT = "KYC_UNDERLYING::DEFAULT";
11
- const KYC_UNDERLYING_ON_DEMAND = "KYC_UNDERLYING::ON_DEMAND";
12
10
  export {
13
- KYC_UNDERLYING_DEFAULT,
14
- KYC_UNDERLYING_ON_DEMAND,
15
11
  PHANTOM_TOKEN_CONTRACT_TYPES
16
12
  };
@@ -65,8 +65,7 @@ const chains = {
65
65
  "0x601067eba24bb5b558a184fc082525637e96a42d": "Gami Labs"
66
66
  },
67
67
  testMarketConfigurators: {
68
- "0x99df7330bf42d596af2e9d9836d4fc2077c574aa": "M11 Credit",
69
- "0xE0527dE5908B3fc2e054B7eEE0DeF6c9965AbF24": "Securitize"
68
+ "0x99df7330bf42d596af2e9d9836d4fc2077c574aa": "M11 Credit"
70
69
  },
71
70
  isPublic: true,
72
71
  wellKnownToken: {
@@ -1,8 +1,10 @@
1
1
  const MULTICALL_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
2
2
  const ADDRESS_0X0 = "0x0000000000000000000000000000000000000000";
3
3
  const NOT_DEPLOYED = "0xNOT DEPLOYED";
4
+ const NATIVE_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
4
5
  export {
5
6
  ADDRESS_0X0,
6
7
  MULTICALL_ADDRESS,
8
+ NATIVE_ADDRESS,
7
9
  NOT_DEPLOYED
8
10
  };
@@ -10,9 +10,6 @@ import { MarketConfiguratorContract } from "./MarketConfiguratorContract.js";
10
10
  import { MarketSuite } from "./MarketSuite.js";
11
11
  import { ZapperRegister } from "./ZapperRegister.js";
12
12
  class MarketRegister extends ZapperRegister {
13
- /**
14
- * Mapping pool.address -> MarketSuite
15
- */
16
13
  #markets = new AddressMap(void 0, "markets");
17
14
  #marketFilter;
18
15
  #marketConfigurators = new AddressMap(
@@ -44,9 +44,6 @@ class MarketSuite extends SDKConstruct {
44
44
  get underlying() {
45
45
  return this.pool.underlying;
46
46
  }
47
- async getKYCFactory() {
48
- return this.pool.getKYCFactory();
49
- }
50
47
  get dirty() {
51
48
  return this.configurator.dirty || this.pool.dirty || this.priceOracle.dirty || this.creditManagers.some((cm) => cm.dirty);
52
49
  }
@@ -53,17 +53,8 @@ class ZapperRegister extends SDKConstruct {
53
53
  );
54
54
  }
55
55
  }
56
- for (const z of KYC_ZAPPERS[this.networkType] ?? []) {
57
- this.#addZapper({ ...z, type: "kyc" });
58
- }
59
- for (const z of MIGRATION_ZAPPERS[this.networkType] ?? []) {
60
- this.#addZapper({ ...z, type: "migration" });
61
- }
62
56
  }
63
57
  #addZapper(z) {
64
- if (BROKEN_ZAPPERS.has(z.baseParams.addr)) {
65
- return;
66
- }
67
58
  const existing = this.zappers.get(z.pool);
68
59
  if (existing) {
69
60
  const hasZapper = existing.some(
@@ -100,120 +91,6 @@ class ZapperRegister extends SDKConstruct {
100
91
  return zappers;
101
92
  }
102
93
  }
103
- const BROKEN_ZAPPERS = new AddressMap(
104
- [["0x90D66b03EC4D462e42e3c7741049FB46a4a03B69", true]],
105
- "brokenZappers"
106
- );
107
- const MIGRATION_ZAPPERS = {
108
- Mainnet: [
109
- {
110
- baseParams: {
111
- addr: "0x85f540c9d5b3be85dbad54085aa18d49e23cd254",
112
- version: 310n,
113
- contractType: "0x5a41505045523a3a5354414b45445f4552433436323600000000000000000000",
114
- serializedParams: "0x0000000000000000000000000418feb7d0b25c411eb77cd654305d29fcbff685000000000000000000000000da0002859b2d05f66a753d8241fcde8623f26f4f"
115
- },
116
- tokenIn: {
117
- addr: "0x0418fEB7d0B25C411EB77cD654305d29FcbFf685",
118
- symbol: "farmdWETHV3",
119
- name: "Farming of Trade WETH v3",
120
- decimals: 18
121
- },
122
- tokenOut: {
123
- addr: "0x9396DCbf78fc526bb003665337C5E73b699571EF",
124
- symbol: "kpkWETH",
125
- name: "WETH Market",
126
- decimals: 18
127
- },
128
- pool: "0x9396DCbf78fc526bb003665337C5E73b699571EF"
129
- },
130
- {
131
- baseParams: {
132
- addr: "0x5A5F69e134765Cb0169f280c2f2A7d8AdF8eFd29",
133
- version: 310n,
134
- contractType: "0x5a41505045523a3a455243343632360000000000000000000000000000000000",
135
- serializedParams: "0x000000000000000000000000da0002859b2d05f66a753d8241fcde8623f26f4f"
136
- },
137
- tokenIn: {
138
- addr: "0xda0002859B2d05F66a753d8241fCDE8623f26F4f",
139
- symbol: "dWETHV3",
140
- name: "Trade WETH v3",
141
- decimals: 18
142
- },
143
- tokenOut: {
144
- addr: "0x9396DCbf78fc526bb003665337C5E73b699571EF",
145
- symbol: "kpkWETH",
146
- name: "WETH Market",
147
- decimals: 18
148
- },
149
- pool: "0x9396DCbf78fc526bb003665337C5E73b699571EF"
150
- },
151
- {
152
- baseParams: {
153
- addr: "0xbff5E156779aDCE4C61ecc6bCc32cba89eD7dfa6",
154
- version: 310n,
155
- contractType: "0x5a41505045523a3a455243343632360000000000000000000000000000000000",
156
- serializedParams: "0x000000000000000000000000ff94993fa7ea27efc943645f95adb36c1b81244b"
157
- },
158
- tokenIn: {
159
- addr: "0xFF94993fA7EA27Efc943645F95Adb36C1b81244b",
160
- symbol: "dWSTETHV3",
161
- name: "wstETH v3",
162
- decimals: 18
163
- },
164
- tokenOut: {
165
- addr: "0xA9d17f6D3285208280a1Fd9B94479c62e0AABa64",
166
- symbol: "kpkwstETH",
167
- name: "wstETH v3",
168
- decimals: 18
169
- },
170
- pool: "0xA9d17f6D3285208280a1Fd9B94479c62e0AABa64"
171
- },
172
- {
173
- baseParams: {
174
- addr: "0x62af1fc6e54e66aba5322a3491b5ce1808a6fe89",
175
- version: 310n,
176
- contractType: "0x5a41505045523a3a455243343632360000000000000000000000000000000000",
177
- serializedParams: "0x000000000000000000000000da00000035fef4082f78def6a8903bee419fbf8e"
178
- },
179
- tokenIn: {
180
- addr: "0xda00000035fef4082F78dEF6A8903bee419FbF8E",
181
- symbol: "dUSDCV3",
182
- name: "Trade USDC v3",
183
- decimals: 6
184
- },
185
- tokenOut: {
186
- addr: "0xF0795C47fA58d00f5F77F4D5c01F31eE891E21B4",
187
- symbol: "rUSDC",
188
- name: "Tulipa USDC",
189
- decimals: 6
190
- },
191
- pool: "0xF0795C47fA58d00f5F77F4D5c01F31eE891E21B4"
192
- },
193
- {
194
- baseParams: {
195
- addr: "0x70383bac778f0285ddb5f35afbd631e5a4675c58",
196
- version: 310n,
197
- contractType: "0x5a41505045523a3a5354414b45445f4552433436323600000000000000000000",
198
- serializedParams: "0x0000000000000000000000009ef444a6d7f4a5adcd68fd5329aa5240c90e14d2000000000000000000000000da00000035fef4082f78def6a8903bee419fbf8e"
199
- },
200
- tokenIn: {
201
- addr: "0x9ef444a6d7F4A5adcd68FD5329aA5240C90E14d2",
202
- symbol: "farmdUSDCV3",
203
- name: "Farming of Trade USDC v3",
204
- decimals: 6
205
- },
206
- tokenOut: {
207
- addr: "0xF0795C47fA58d00f5F77F4D5c01F31eE891E21B4",
208
- symbol: "rUSDC",
209
- name: "Tulipa USDC",
210
- decimals: 6
211
- },
212
- pool: "0xF0795C47fA58d00f5F77F4D5c01F31eE891E21B4"
213
- }
214
- ]
215
- };
216
- const KYC_ZAPPERS = {};
217
94
  export {
218
95
  ZapperRegister
219
96
  };
@@ -55,9 +55,6 @@ class PoolSuite extends SDKConstruct {
55
55
  get underlying() {
56
56
  return this.pool.underlying;
57
57
  }
58
- async getKYCFactory() {
59
- return this.pool.getKYCFactory();
60
- }
61
58
  get dirty() {
62
59
  return this.pool.dirty || this.rateKeeper.dirty || this.pqk.dirty || this.interestRateModel.dirty;
63
60
  }
@@ -7,20 +7,16 @@ import {
7
7
  formatBNvalue,
8
8
  percentFmt
9
9
  } from "../../utils/index.js";
10
- import { SecuritizeKYCFactory } from "./SecuritizeKYCFactory.js";
11
10
  const abi = [...iPoolV310Abi, ...iPausableAbi];
12
11
  class PoolV310Contract extends BaseContract {
13
12
  creditManagerDebtParams;
14
- #sdk;
15
- #kycFactory;
16
- constructor(sdk, data) {
13
+ constructor(options, data) {
17
14
  const { baseParams, creditManagerDebtParams, ...rest } = data;
18
- super(sdk, {
15
+ super(options, {
19
16
  ...data.baseParams,
20
17
  name: `PoolV3(${data.name})`,
21
18
  abi
22
19
  });
23
- this.#sdk = sdk;
24
20
  Object.assign(this, rest);
25
21
  this.creditManagerDebtParams = new AddressMap(
26
22
  creditManagerDebtParams.map((p) => [p.creditManager, p])
@@ -32,17 +28,6 @@ class PoolV310Contract extends BaseContract {
32
28
  symbol: data.symbol
33
29
  });
34
30
  }
35
- async getKYCFactory() {
36
- if (this.#kycFactory) {
37
- return this.#kycFactory;
38
- }
39
- await this.#sdk.tokensMeta.loadTokenData(this.underlying);
40
- const u = this.#sdk.tokensMeta.mustGet(this.underlying);
41
- if (this.#sdk.tokensMeta.isKYCUnderlying(u)) {
42
- this.#kycFactory = new SecuritizeKYCFactory(this.#sdk, u.kycFactory);
43
- }
44
- return this.#kycFactory;
45
- }
46
31
  stateHuman(raw = true) {
47
32
  return {
48
33
  ...super.stateHuman(raw),
@@ -1,6 +1,4 @@
1
1
  export * from "./GaugeContract.js";
2
2
  export * from "./LinearInterestRateModelContract.js";
3
3
  export * from "./PoolSuite.js";
4
- export * from "./PoolV310Contract.js";
5
- export * from "./SecuritizeKYCFactory.js";
6
4
  export * from "./types.js";