@gearbox-protocol/sdk 13.0.0-next.1 → 13.0.0-next.11

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.
@@ -28,14 +28,14 @@ var import__ = require("../index.js");
28
28
  var import_utils = require("../utils/index.js");
29
29
  class TokensMeta extends import_utils.AddressMap {
30
30
  #client;
31
- #tokenDataLoaded = false;
31
+ #tokenDataLoaded = new import_utils.AddressSet();
32
32
  constructor(client) {
33
33
  super(void 0, "tokensMeta");
34
34
  this.#client = client;
35
35
  }
36
36
  reset() {
37
37
  this.clear();
38
- this.#tokenDataLoaded = false;
38
+ this.#tokenDataLoaded.clear();
39
39
  }
40
40
  symbol(token) {
41
41
  return this.mustGet(token).symbol;
@@ -44,14 +44,18 @@ class TokensMeta extends import_utils.AddressMap {
44
44
  return this.mustGet(token).decimals;
45
45
  }
46
46
  isPhantomToken(t) {
47
- if (!this.#tokenDataLoaded) {
48
- throw new Error("extended token data not loaded");
47
+ if (!this.#tokenDataLoaded.has(t.addr)) {
48
+ throw new Error(
49
+ `extended token data not loaded for ${t.symbol} (${t.addr})`
50
+ );
49
51
  }
50
52
  return "contractType" in t && t.contractType.startsWith("PHANTOM_TOKEN::");
51
53
  }
52
54
  isKYCUnderlying(t) {
53
- if (!this.#tokenDataLoaded) {
54
- throw new Error("extended token data not loaded");
55
+ if (!this.#tokenDataLoaded.has(t.addr)) {
56
+ throw new Error(
57
+ `extended token data not loaded for ${t.symbol} (${t.addr})`
58
+ );
55
59
  }
56
60
  return "contractType" in t && t.contractType.startsWith("KYC_UNDERLYING::");
57
61
  }
@@ -97,11 +101,17 @@ class TokensMeta extends import_utils.AddressMap {
97
101
  }
98
102
  /**
99
103
  * Loads token information about phantom token and KYC underlying tokens
104
+ *
105
+ * @param tokens - tokens to load data for, defaults to all tokens
100
106
  */
101
- async loadTokenData() {
102
- const tokens = this.keys();
107
+ async loadTokenData(...tokens) {
108
+ const tokenz = new import_utils.AddressSet(tokens.length > 0 ? tokens : this.keys());
109
+ const tokensToLoad = Array.from(tokenz.difference(this.#tokenDataLoaded));
110
+ if (tokensToLoad.length === 0) {
111
+ return;
112
+ }
103
113
  const resp = await this.#client.multicall({
104
- contracts: tokens.flatMap(
114
+ contracts: tokensToLoad.flatMap(
105
115
  (t) => [
106
116
  {
107
117
  address: t,
@@ -118,10 +128,10 @@ class TokensMeta extends import_utils.AddressMap {
118
128
  allowFailure: true,
119
129
  batchSize: 0
120
130
  });
121
- for (let i = 0; i < tokens.length; i++) {
122
- this.#overrideTokenMeta(tokens[i], resp[i], resp[i + 1]);
131
+ for (let i = 0; i < tokensToLoad.length; i++) {
132
+ this.#overrideTokenMeta(tokensToLoad[i], resp[i], resp[i + 1]);
133
+ this.#tokenDataLoaded.add(tokensToLoad[i]);
123
134
  }
124
- this.#tokenDataLoaded = true;
125
135
  }
126
136
  #overrideTokenMeta(token, contractTypeResp, serializeResp) {
127
137
  const meta = this.mustGet(token);
@@ -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
  */
@@ -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
  });
@@ -0,0 +1,16 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
@@ -21,7 +21,6 @@ __export(PoolService_exports, {
21
21
  PoolService: () => PoolService
22
22
  });
23
23
  module.exports = __toCommonJS(PoolService_exports);
24
- var import_peripheryCompressor = require("../../abi/compressors/peripheryCompressor.js");
25
24
  var import_iERC20 = require("../../abi/iERC20.js");
26
25
  var import_iERC20ZapperDeposits = require("../../abi/iERC20ZapperDeposits.js");
27
26
  var import_iETHZapperDeposits = require("../../abi/iETHZapperDeposits.js");
@@ -29,99 +28,65 @@ var import_iZapper = require("../../abi/iZapper.js");
29
28
  var import_v300 = require("../../abi/v300.js");
30
29
  var import_base = require("../base/index.js");
31
30
  var import__ = require("../index.js");
32
- var import_extraZappers = require("./extraZappers.js");
31
+ var import_utils = require("../utils/index.js");
33
32
  const NATIVE_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
33
+ const POOL_TOKENS_TO_MIGRATE = new import_utils.AddressMap([
34
+ // v2 diesels
35
+ ["0x6CFaF95457d7688022FC53e7AbE052ef8DFBbdBA", "dDAI"],
36
+ ["0xc411dB5f5Eb3f7d552F9B8454B2D74097ccdE6E3", "dUSDC"],
37
+ ["0xe753260F1955e8678DCeA8887759e07aa57E8c54", "dWBTC"],
38
+ ["0xF21fc650C1B34eb0FDE786D52d23dA99Db3D6278", "dWETH"],
39
+ ["0x2158034dB06f06dcB9A786D2F1F8c38781bA779d", "dwstETH"],
40
+ ["0x8A1112AFef7F4FC7c066a77AABBc01b3Fff31D47", "dFRAX"]
41
+ ]);
34
42
  class PoolService extends import_base.SDKConstruct {
35
- #zappers;
36
- get zappers() {
37
- if (!this.#zappers) {
38
- throw new Error("zappers not loaded, call loadZappers first");
39
- }
40
- return this.#zappers;
41
- }
42
- async loadZappers(force) {
43
- if (!force && this.#zappers) {
44
- return;
45
- }
46
- const [pcAddr] = this.sdk.addressProvider.mustGetLatest(
47
- import__.AP_PERIPHERY_COMPRESSOR,
48
- import__.VERSION_RANGE_310
49
- );
50
- this.logger?.debug(`loading zappers with periphery compressor ${pcAddr}`);
51
- const markets = this.sdk.marketRegister.markets;
52
- const resp = await this.client.multicall({
53
- contracts: markets.map(
54
- (m) => ({
55
- abi: import_peripheryCompressor.peripheryCompressorAbi,
56
- address: pcAddr,
57
- functionName: "getZappers",
58
- args: [m.configurator.address, m.pool.pool.address]
59
- })
60
- ),
61
- allowFailure: true,
62
- batchSize: 0
63
- });
64
- this.#zappers = new import__.AddressMap(void 0, "zappers");
65
- for (let i = 0; i < resp.length; i++) {
66
- const { status, result, error } = resp[i];
67
- const marketConfigurator = markets[i].configurator.address;
68
- const pool = markets[i].pool.pool.address;
69
- if (status === "success") {
70
- for (const z of result) {
71
- this.#addZapper({ ...z, pool });
72
- }
73
- } else {
74
- this.sdk.logger?.error(
75
- `failed to load zapper for market configurator ${this.labelAddress(
76
- marketConfigurator
77
- )} and pool ${this.labelAddress(pool)}: ${error}`
78
- );
79
- }
80
- }
81
- for (const z of import_extraZappers.extraZappers[this.networkType] ?? []) {
82
- this.#addZapper(z);
83
- }
84
- }
85
43
  getDepositTokensIn(pool) {
86
44
  const underlying = this.#describeUnderlying(pool);
87
45
  if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
88
46
  switch (underlying.contractType) {
89
47
  case import_base.KYC_UNDERLYING_DEFAULT:
90
- return this.depositTokensIn(pool, false);
48
+ return this.#depositTokensIn(pool, false);
91
49
  case import_base.KYC_UNDERLYING_ON_DEMAND:
92
50
  return [underlying.asset];
93
51
  }
94
52
  }
95
- return this.depositTokensIn(pool, true);
53
+ return this.#depositTokensIn(pool, true);
96
54
  }
97
55
  getDepositTokensOut(pool, tokenIn) {
98
56
  const underlying = this.#describeUnderlying(pool);
99
57
  if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
100
58
  switch (underlying.contractType) {
101
59
  case import_base.KYC_UNDERLYING_DEFAULT:
102
- return this.depositTokensOut(pool, tokenIn, false);
60
+ return this.#depositTokensOut(pool, tokenIn, false);
103
61
  case import_base.KYC_UNDERLYING_ON_DEMAND:
104
62
  return [];
105
63
  }
106
64
  }
107
- return this.depositTokensOut(pool, tokenIn, true);
65
+ return this.#depositTokensOut(pool, tokenIn, true);
108
66
  }
109
67
  getDepositMetadata(pool, tokenIn, tokenOut) {
110
68
  const underlying = this.#describeUnderlying(pool);
111
69
  if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
112
70
  switch (underlying.contractType) {
113
71
  case import_base.KYC_UNDERLYING_DEFAULT: {
114
- return this.depositMetadata(pool, tokenIn, tokenOut, false);
72
+ return this.#depositMetadata(
73
+ "kyc-default",
74
+ pool,
75
+ tokenIn,
76
+ tokenOut,
77
+ false
78
+ );
115
79
  }
116
80
  case import_base.KYC_UNDERLYING_ON_DEMAND:
117
81
  return {
118
82
  zapper: void 0,
119
83
  approveTarget: underlying.liquidityProvider,
120
- permissible: false
84
+ permissible: false,
85
+ type: "kyc-on-demand"
121
86
  };
122
87
  }
123
88
  }
124
- return this.depositMetadata(pool, tokenIn, tokenOut, true);
89
+ return this.#depositMetadata("classic", pool, tokenIn, tokenOut, true);
125
90
  }
126
91
  addLiquidity(props) {
127
92
  const { collateral, meta, permit, referralCode, pool, wallet } = props;
@@ -132,7 +97,7 @@ class PoolService extends import_base.SDKConstruct {
132
97
  }
133
98
  }
134
99
  const { zapper } = meta;
135
- if (zapper?.tokenIn.addr === NATIVE_ADDRESS) {
100
+ if (zapper?.tokenIn.addr?.toLowerCase() === NATIVE_ADDRESS.toLowerCase()) {
136
101
  return {
137
102
  target: zapper.baseParams.addr,
138
103
  abi: import_iETHZapperDeposits.iethZapperDepositsAbi,
@@ -209,13 +174,17 @@ class PoolService extends import_base.SDKConstruct {
209
174
  args: [amount, account, account]
210
175
  };
211
176
  }
212
- depositTokensIn(poolAddr, allowDirectDeposit) {
177
+ #getDepositZappers(poolAddr) {
178
+ const zappers = this.sdk.marketRegister.poolZappers(poolAddr);
179
+ return zappers.filter((z) => z.type !== "migration");
180
+ }
181
+ #depositTokensIn(poolAddr, allowDirectDeposit) {
213
182
  const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
214
183
  const result = new import__.AddressSet();
215
184
  if (allowDirectDeposit) {
216
185
  result.add(pool.underlying);
217
186
  }
218
- const zappers = this.zappers.get(poolAddr) ?? [];
187
+ const zappers = this.#getDepositZappers(poolAddr);
219
188
  for (const z of zappers) {
220
189
  if ((0, import__.hexEq)(z.tokenOut.addr, poolAddr)) {
221
190
  result.add(z.tokenIn.addr);
@@ -226,14 +195,18 @@ class PoolService extends import_base.SDKConstruct {
226
195
  `No tokensIn found for pool ${this.labelAddress(poolAddr)}`
227
196
  );
228
197
  }
229
- return result.asArray();
198
+ const r = result.asArray().filter((t) => !POOL_TOKENS_TO_MIGRATE.has(t));
199
+ return r;
230
200
  }
231
- depositTokensOut(poolAddr, tokenIn, allowDirectDeposit) {
201
+ #depositTokensOut(poolAddr, tokenIn, allowDirectDeposit) {
232
202
  const result = new import__.AddressSet();
233
203
  const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
234
- const zappers = this.zappers.get(poolAddr) ?? [];
204
+ const zappers = this.#getDepositZappers(poolAddr);
235
205
  for (const z of zappers) {
236
206
  if ((0, import__.hexEq)(z.tokenIn.addr, tokenIn)) {
207
+ if (!(0, import__.hexEq)(z.tokenOut.addr, poolAddr)) {
208
+ console.log("found", "z.tokenOut.addr", z.tokenOut.addr);
209
+ }
237
210
  result.add(z.tokenOut.addr);
238
211
  }
239
212
  }
@@ -242,20 +215,40 @@ class PoolService extends import_base.SDKConstruct {
242
215
  }
243
216
  if (result.size === 0) {
244
217
  throw new Error(
245
- `No tokensOut found for tokenIn ${this.labelAddress(tokenIn)} on pool ${this.labelAddress(poolAddr)}`
218
+ `No tokensOut found for tokenIn ${this.labelAddress(
219
+ tokenIn
220
+ )} on pool ${this.labelAddress(poolAddr)}`
246
221
  );
247
222
  }
248
- return result.asArray();
223
+ const r = result.asArray();
224
+ return r;
249
225
  }
250
- depositMetadata(poolAddr, tokenIn, tokenOut, allowDirectDeposit) {
226
+ #getDepositZapper(poolAddr, tokenIn, tokenOut) {
227
+ const zappers = this.sdk.marketRegister.getZapper(poolAddr, tokenIn, tokenOut)?.filter((z) => z.type !== "migration");
228
+ if (zappers && zappers.length > 1) {
229
+ throw new Error(
230
+ `Multiple zappers found for tokenIn ${this.labelAddress(
231
+ tokenIn
232
+ )} and tokenOut ${this.labelAddress(
233
+ tokenOut
234
+ )} on pool ${this.labelAddress(poolAddr)}`
235
+ );
236
+ }
237
+ return zappers?.[0];
238
+ }
239
+ #depositMetadata(type, poolAddr, tokenIn, tokenOut, allowDirectDeposit) {
251
240
  if (!tokenOut) {
252
241
  throw new Error("tokenOut is required for classic pool deposit");
253
242
  }
254
243
  const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
255
- const zapper = this.getZapper(poolAddr, tokenIn, tokenOut);
244
+ const zapper = this.#getDepositZapper(poolAddr, tokenIn, tokenOut);
256
245
  if (!zapper && !allowDirectDeposit) {
257
246
  throw new Error(
258
- `No zapper found for tokenIn ${this.labelAddress(tokenIn)} and tokenOut ${this.labelAddress(tokenOut)} on pool ${this.labelAddress(poolAddr)}`
247
+ `No zapper found for tokenIn ${this.labelAddress(
248
+ tokenIn
249
+ )} and tokenOut ${this.labelAddress(
250
+ tokenOut
251
+ )} on pool ${this.labelAddress(poolAddr)}`
259
252
  );
260
253
  }
261
254
  return {
@@ -264,41 +257,10 @@ class PoolService extends import_base.SDKConstruct {
264
257
  approveTarget: zapper?.baseParams.addr ?? pool.pool.address,
265
258
  // TODO: instead of permissible, return permitType зависимости от tokenIn
266
259
  // "none" | "eip2612" | "dai_like";
267
- permissible: !!zapper && tokenIn !== NATIVE_ADDRESS
260
+ permissible: !!zapper && tokenIn !== NATIVE_ADDRESS,
261
+ type
268
262
  };
269
263
  }
270
- getZapper(pool, tokenIn, tokenOut) {
271
- return this.zappers.get(pool)?.find(
272
- (z) => (0, import__.hexEq)(z.tokenIn.addr, tokenIn) && (0, import__.hexEq)(z.tokenOut.addr, tokenOut)
273
- );
274
- }
275
- mustGetZapper(poolAddr, tokenIn, tokenOut) {
276
- const result = this.getZapper(poolAddr, tokenIn, tokenOut);
277
- if (!result) {
278
- throw new Error(
279
- `No zapper found for tokenIn ${this.labelAddress(tokenIn)} and tokenOut ${this.labelAddress(tokenOut)} on pool ${this.labelAddress(poolAddr)}`
280
- );
281
- }
282
- return result;
283
- }
284
- #addZapper(z) {
285
- const existing = this.zappers.get(z.pool);
286
- if (existing) {
287
- const hasZapper = existing.some(
288
- (zz) => (0, import__.hexEq)(zz.baseParams.addr, z.baseParams.addr)
289
- );
290
- if (!hasZapper) {
291
- existing.push(z);
292
- }
293
- } else {
294
- this.zappers.upsert(z.pool, [z]);
295
- }
296
- const zappersTokens = [z.tokenIn, z.tokenOut];
297
- for (const t of zappersTokens) {
298
- this.sdk.tokensMeta.upsert(t.addr, t);
299
- this.sdk.setAddressLabel(t.addr, t.symbol);
300
- }
301
- }
302
264
  #describeUnderlying(pool) {
303
265
  const market = this.sdk.marketRegister.findByPool(pool);
304
266
  return this.sdk.tokensMeta.mustGet(market.underlying);
@@ -8,17 +8,17 @@ import {
8
8
  KYC_UNDERLYING_DEFAULT,
9
9
  KYC_UNDERLYING_ON_DEMAND
10
10
  } from "../index.js";
11
- import { AddressMap, formatBN } from "../utils/index.js";
11
+ import { AddressMap, AddressSet, formatBN } from "../utils/index.js";
12
12
  class TokensMeta extends AddressMap {
13
13
  #client;
14
- #tokenDataLoaded = false;
14
+ #tokenDataLoaded = new AddressSet();
15
15
  constructor(client) {
16
16
  super(void 0, "tokensMeta");
17
17
  this.#client = client;
18
18
  }
19
19
  reset() {
20
20
  this.clear();
21
- this.#tokenDataLoaded = false;
21
+ this.#tokenDataLoaded.clear();
22
22
  }
23
23
  symbol(token) {
24
24
  return this.mustGet(token).symbol;
@@ -27,14 +27,18 @@ class TokensMeta extends AddressMap {
27
27
  return this.mustGet(token).decimals;
28
28
  }
29
29
  isPhantomToken(t) {
30
- if (!this.#tokenDataLoaded) {
31
- throw new Error("extended token data not loaded");
30
+ if (!this.#tokenDataLoaded.has(t.addr)) {
31
+ throw new Error(
32
+ `extended token data not loaded for ${t.symbol} (${t.addr})`
33
+ );
32
34
  }
33
35
  return "contractType" in t && t.contractType.startsWith("PHANTOM_TOKEN::");
34
36
  }
35
37
  isKYCUnderlying(t) {
36
- if (!this.#tokenDataLoaded) {
37
- throw new Error("extended token data not loaded");
38
+ if (!this.#tokenDataLoaded.has(t.addr)) {
39
+ throw new Error(
40
+ `extended token data not loaded for ${t.symbol} (${t.addr})`
41
+ );
38
42
  }
39
43
  return "contractType" in t && t.contractType.startsWith("KYC_UNDERLYING::");
40
44
  }
@@ -80,11 +84,17 @@ class TokensMeta extends AddressMap {
80
84
  }
81
85
  /**
82
86
  * Loads token information about phantom token and KYC underlying tokens
87
+ *
88
+ * @param tokens - tokens to load data for, defaults to all tokens
83
89
  */
84
- async loadTokenData() {
85
- const tokens = this.keys();
90
+ async loadTokenData(...tokens) {
91
+ const tokenz = new AddressSet(tokens.length > 0 ? tokens : this.keys());
92
+ const tokensToLoad = Array.from(tokenz.difference(this.#tokenDataLoaded));
93
+ if (tokensToLoad.length === 0) {
94
+ return;
95
+ }
86
96
  const resp = await this.#client.multicall({
87
- contracts: tokens.flatMap(
97
+ contracts: tokensToLoad.flatMap(
88
98
  (t) => [
89
99
  {
90
100
  address: t,
@@ -101,10 +111,10 @@ class TokensMeta extends AddressMap {
101
111
  allowFailure: true,
102
112
  batchSize: 0
103
113
  });
104
- for (let i = 0; i < tokens.length; i++) {
105
- this.#overrideTokenMeta(tokens[i], resp[i], resp[i + 1]);
114
+ for (let i = 0; i < tokensToLoad.length; i++) {
115
+ this.#overrideTokenMeta(tokensToLoad[i], resp[i], resp[i + 1]);
116
+ this.#tokenDataLoaded.add(tokensToLoad[i]);
106
117
  }
107
- this.#tokenDataLoaded = true;
108
118
  }
109
119
  #overrideTokenMeta(token, contractTypeResp, serializeResp) {
110
120
  const meta = this.mustGet(token);
@@ -1,5 +1,4 @@
1
1
  import { marketCompressorAbi } from "../../abi/compressors/marketCompressor.js";
2
- import { SDKConstruct } from "../base/index.js";
3
2
  import {
4
3
  ADDRESS_0X0,
5
4
  AP_MARKET_COMPRESSOR,
@@ -9,7 +8,8 @@ import { AddressMap } from "../utils/index.js";
9
8
  import { simulateWithPriceUpdates } from "../utils/viem/index.js";
10
9
  import { MarketConfiguratorContract } from "./MarketConfiguratorContract.js";
11
10
  import { MarketSuite } from "./MarketSuite.js";
12
- class MarketRegister extends SDKConstruct {
11
+ import { ZapperRegister } from "./ZapperRegister.js";
12
+ class MarketRegister extends ZapperRegister {
13
13
  /**
14
14
  * Mapping pool.address -> MarketSuite
15
15
  */
@@ -1,4 +1,110 @@
1
- const extraZappers = {
1
+ import { peripheryCompressorAbi } from "../../abi/compressors/peripheryCompressor.js";
2
+ import { SDKConstruct } from "../base/index.js";
3
+ import {
4
+ AP_PERIPHERY_COMPRESSOR,
5
+ VERSION_RANGE_310
6
+ } from "../constants/index.js";
7
+ import { AddressMap, hexEq } from "../utils/index.js";
8
+ class ZapperRegister extends SDKConstruct {
9
+ /**
10
+ * Mapping pool.address -> ZapperData[]
11
+ * Needs to be loaded explicitly using loadZappers method
12
+ */
13
+ #zappers;
14
+ /**
15
+ * Load zappers for all pools using periphery compressor, adds hardcoded zappers
16
+ */
17
+ async loadZappers(force) {
18
+ if (!force && this.#zappers) {
19
+ return;
20
+ }
21
+ const [pcAddr] = this.sdk.addressProvider.mustGetLatest(
22
+ AP_PERIPHERY_COMPRESSOR,
23
+ VERSION_RANGE_310
24
+ );
25
+ this.logger?.debug(`loading zappers with periphery compressor ${pcAddr}`);
26
+ const markets = this.sdk.marketRegister.markets;
27
+ const resp = await this.client.multicall({
28
+ contracts: markets.map(
29
+ (m) => ({
30
+ abi: peripheryCompressorAbi,
31
+ address: pcAddr,
32
+ functionName: "getZappers",
33
+ args: [m.configurator.address, m.pool.pool.address]
34
+ })
35
+ ),
36
+ allowFailure: true,
37
+ batchSize: 0
38
+ });
39
+ this.#zappers = new AddressMap(void 0, "zappers");
40
+ for (let i = 0; i < resp.length; i++) {
41
+ const { status, result, error } = resp[i];
42
+ const marketConfigurator = markets[i].configurator.address;
43
+ const pool = markets[i].pool.pool.address;
44
+ if (status === "success") {
45
+ for (const z of result) {
46
+ this.#addZapper({ ...z, pool, type: "base" });
47
+ }
48
+ } else {
49
+ this.logger?.error(
50
+ `failed to load zapper for market configurator ${this.labelAddress(
51
+ marketConfigurator
52
+ )} and pool ${this.labelAddress(pool)}: ${error}`
53
+ );
54
+ }
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
+ }
63
+ #addZapper(z) {
64
+ if (BROKEN_ZAPPERS.has(z.baseParams.addr)) {
65
+ return;
66
+ }
67
+ const existing = this.zappers.get(z.pool);
68
+ if (existing) {
69
+ const hasZapper = existing.some(
70
+ (zz) => hexEq(zz.baseParams.addr, z.baseParams.addr)
71
+ );
72
+ if (!hasZapper) {
73
+ existing.push(z);
74
+ }
75
+ } else {
76
+ this.zappers.upsert(z.pool, [z]);
77
+ }
78
+ const zappersTokens = [z.tokenIn, z.tokenOut];
79
+ for (const t of zappersTokens) {
80
+ this.sdk.tokensMeta.upsert(t.addr, t);
81
+ this.sdk.setAddressLabel(t.addr, t.symbol);
82
+ }
83
+ }
84
+ get zappers() {
85
+ if (!this.#zappers) {
86
+ throw new Error("zappers not loaded, call loadZappers first");
87
+ }
88
+ return this.#zappers;
89
+ }
90
+ poolZappers(pool) {
91
+ return this.zappers.get(pool) ?? [];
92
+ }
93
+ /**
94
+ * Can return multiple zappers if there are multiple zappers for the same tokenIn and tokenOut
95
+ */
96
+ getZapper(pool, tokenIn, tokenOut) {
97
+ const zappers = this.zappers.get(pool)?.filter(
98
+ (z) => hexEq(z.tokenIn.addr, tokenIn) && hexEq(z.tokenOut.addr, tokenOut)
99
+ );
100
+ return zappers;
101
+ }
102
+ }
103
+ const BROKEN_ZAPPERS = new AddressMap(
104
+ [["0x90D66b03EC4D462e42e3c7741049FB46a4a03B69", true]],
105
+ "brokenZappers"
106
+ );
107
+ const MIGRATION_ZAPPERS = {
2
108
  Mainnet: [
3
109
  {
4
110
  baseParams: {
@@ -107,6 +213,7 @@ const extraZappers = {
107
213
  }
108
214
  ]
109
215
  };
216
+ const KYC_ZAPPERS = {};
110
217
  export {
111
- extraZappers
218
+ ZapperRegister
112
219
  };
@@ -5,3 +5,4 @@ export * from "./MarketSuite.js";
5
5
  export * from "./oracle/index.js";
6
6
  export * from "./pool/index.js";
7
7
  export * from "./pricefeeds/index.js";
8
+ export * from "./types.js";
File without changes
@@ -1,4 +1,3 @@
1
- import { peripheryCompressorAbi } from "../../abi/compressors/peripheryCompressor.js";
2
1
  import { ierc20Abi } from "../../abi/iERC20.js";
3
2
  import { ierc20ZapperDepositsAbi } from "../../abi/iERC20ZapperDeposits.js";
4
3
  import { iethZapperDepositsAbi } from "../../abi/iETHZapperDeposits.js";
@@ -9,106 +8,66 @@ import {
9
8
  KYC_UNDERLYING_ON_DEMAND,
10
9
  SDKConstruct
11
10
  } from "../base/index.js";
12
- import {
13
- AddressMap,
14
- AddressSet,
15
- AP_PERIPHERY_COMPRESSOR,
16
- hexEq,
17
- VERSION_RANGE_310
18
- } from "../index.js";
19
- import { extraZappers } from "./extraZappers.js";
11
+ import { AddressSet, hexEq } from "../index.js";
12
+ import { AddressMap } from "../utils/index.js";
20
13
  const NATIVE_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
14
+ const POOL_TOKENS_TO_MIGRATE = new AddressMap([
15
+ // v2 diesels
16
+ ["0x6CFaF95457d7688022FC53e7AbE052ef8DFBbdBA", "dDAI"],
17
+ ["0xc411dB5f5Eb3f7d552F9B8454B2D74097ccdE6E3", "dUSDC"],
18
+ ["0xe753260F1955e8678DCeA8887759e07aa57E8c54", "dWBTC"],
19
+ ["0xF21fc650C1B34eb0FDE786D52d23dA99Db3D6278", "dWETH"],
20
+ ["0x2158034dB06f06dcB9A786D2F1F8c38781bA779d", "dwstETH"],
21
+ ["0x8A1112AFef7F4FC7c066a77AABBc01b3Fff31D47", "dFRAX"]
22
+ ]);
21
23
  class PoolService extends SDKConstruct {
22
- #zappers;
23
- get zappers() {
24
- if (!this.#zappers) {
25
- throw new Error("zappers not loaded, call loadZappers first");
26
- }
27
- return this.#zappers;
28
- }
29
- async loadZappers(force) {
30
- if (!force && this.#zappers) {
31
- return;
32
- }
33
- const [pcAddr] = this.sdk.addressProvider.mustGetLatest(
34
- AP_PERIPHERY_COMPRESSOR,
35
- VERSION_RANGE_310
36
- );
37
- this.logger?.debug(`loading zappers with periphery compressor ${pcAddr}`);
38
- const markets = this.sdk.marketRegister.markets;
39
- const resp = await this.client.multicall({
40
- contracts: markets.map(
41
- (m) => ({
42
- abi: peripheryCompressorAbi,
43
- address: pcAddr,
44
- functionName: "getZappers",
45
- args: [m.configurator.address, m.pool.pool.address]
46
- })
47
- ),
48
- allowFailure: true,
49
- batchSize: 0
50
- });
51
- this.#zappers = new AddressMap(void 0, "zappers");
52
- for (let i = 0; i < resp.length; i++) {
53
- const { status, result, error } = resp[i];
54
- const marketConfigurator = markets[i].configurator.address;
55
- const pool = markets[i].pool.pool.address;
56
- if (status === "success") {
57
- for (const z of result) {
58
- this.#addZapper({ ...z, pool });
59
- }
60
- } else {
61
- this.sdk.logger?.error(
62
- `failed to load zapper for market configurator ${this.labelAddress(
63
- marketConfigurator
64
- )} and pool ${this.labelAddress(pool)}: ${error}`
65
- );
66
- }
67
- }
68
- for (const z of extraZappers[this.networkType] ?? []) {
69
- this.#addZapper(z);
70
- }
71
- }
72
24
  getDepositTokensIn(pool) {
73
25
  const underlying = this.#describeUnderlying(pool);
74
26
  if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
75
27
  switch (underlying.contractType) {
76
28
  case KYC_UNDERLYING_DEFAULT:
77
- return this.depositTokensIn(pool, false);
29
+ return this.#depositTokensIn(pool, false);
78
30
  case KYC_UNDERLYING_ON_DEMAND:
79
31
  return [underlying.asset];
80
32
  }
81
33
  }
82
- return this.depositTokensIn(pool, true);
34
+ return this.#depositTokensIn(pool, true);
83
35
  }
84
36
  getDepositTokensOut(pool, tokenIn) {
85
37
  const underlying = this.#describeUnderlying(pool);
86
38
  if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
87
39
  switch (underlying.contractType) {
88
40
  case KYC_UNDERLYING_DEFAULT:
89
- return this.depositTokensOut(pool, tokenIn, false);
41
+ return this.#depositTokensOut(pool, tokenIn, false);
90
42
  case KYC_UNDERLYING_ON_DEMAND:
91
43
  return [];
92
44
  }
93
45
  }
94
- return this.depositTokensOut(pool, tokenIn, true);
46
+ return this.#depositTokensOut(pool, tokenIn, true);
95
47
  }
96
48
  getDepositMetadata(pool, tokenIn, tokenOut) {
97
49
  const underlying = this.#describeUnderlying(pool);
98
50
  if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
99
51
  switch (underlying.contractType) {
100
52
  case KYC_UNDERLYING_DEFAULT: {
101
- return this.depositMetadata(pool, tokenIn, tokenOut, false);
53
+ return this.#depositMetadata(
54
+ "kyc-default",
55
+ pool,
56
+ tokenIn,
57
+ tokenOut,
58
+ false
59
+ );
102
60
  }
103
61
  case KYC_UNDERLYING_ON_DEMAND:
104
62
  return {
105
63
  zapper: void 0,
106
64
  approveTarget: underlying.liquidityProvider,
107
- permissible: false
65
+ permissible: false,
66
+ type: "kyc-on-demand"
108
67
  };
109
68
  }
110
69
  }
111
- return this.depositMetadata(pool, tokenIn, tokenOut, true);
70
+ return this.#depositMetadata("classic", pool, tokenIn, tokenOut, true);
112
71
  }
113
72
  addLiquidity(props) {
114
73
  const { collateral, meta, permit, referralCode, pool, wallet } = props;
@@ -119,7 +78,7 @@ class PoolService extends SDKConstruct {
119
78
  }
120
79
  }
121
80
  const { zapper } = meta;
122
- if (zapper?.tokenIn.addr === NATIVE_ADDRESS) {
81
+ if (zapper?.tokenIn.addr?.toLowerCase() === NATIVE_ADDRESS.toLowerCase()) {
123
82
  return {
124
83
  target: zapper.baseParams.addr,
125
84
  abi: iethZapperDepositsAbi,
@@ -196,13 +155,17 @@ class PoolService extends SDKConstruct {
196
155
  args: [amount, account, account]
197
156
  };
198
157
  }
199
- depositTokensIn(poolAddr, allowDirectDeposit) {
158
+ #getDepositZappers(poolAddr) {
159
+ const zappers = this.sdk.marketRegister.poolZappers(poolAddr);
160
+ return zappers.filter((z) => z.type !== "migration");
161
+ }
162
+ #depositTokensIn(poolAddr, allowDirectDeposit) {
200
163
  const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
201
164
  const result = new AddressSet();
202
165
  if (allowDirectDeposit) {
203
166
  result.add(pool.underlying);
204
167
  }
205
- const zappers = this.zappers.get(poolAddr) ?? [];
168
+ const zappers = this.#getDepositZappers(poolAddr);
206
169
  for (const z of zappers) {
207
170
  if (hexEq(z.tokenOut.addr, poolAddr)) {
208
171
  result.add(z.tokenIn.addr);
@@ -213,14 +176,18 @@ class PoolService extends SDKConstruct {
213
176
  `No tokensIn found for pool ${this.labelAddress(poolAddr)}`
214
177
  );
215
178
  }
216
- return result.asArray();
179
+ const r = result.asArray().filter((t) => !POOL_TOKENS_TO_MIGRATE.has(t));
180
+ return r;
217
181
  }
218
- depositTokensOut(poolAddr, tokenIn, allowDirectDeposit) {
182
+ #depositTokensOut(poolAddr, tokenIn, allowDirectDeposit) {
219
183
  const result = new AddressSet();
220
184
  const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
221
- const zappers = this.zappers.get(poolAddr) ?? [];
185
+ const zappers = this.#getDepositZappers(poolAddr);
222
186
  for (const z of zappers) {
223
187
  if (hexEq(z.tokenIn.addr, tokenIn)) {
188
+ if (!hexEq(z.tokenOut.addr, poolAddr)) {
189
+ console.log("found", "z.tokenOut.addr", z.tokenOut.addr);
190
+ }
224
191
  result.add(z.tokenOut.addr);
225
192
  }
226
193
  }
@@ -229,20 +196,40 @@ class PoolService extends SDKConstruct {
229
196
  }
230
197
  if (result.size === 0) {
231
198
  throw new Error(
232
- `No tokensOut found for tokenIn ${this.labelAddress(tokenIn)} on pool ${this.labelAddress(poolAddr)}`
199
+ `No tokensOut found for tokenIn ${this.labelAddress(
200
+ tokenIn
201
+ )} on pool ${this.labelAddress(poolAddr)}`
202
+ );
203
+ }
204
+ const r = result.asArray();
205
+ return r;
206
+ }
207
+ #getDepositZapper(poolAddr, tokenIn, tokenOut) {
208
+ const zappers = this.sdk.marketRegister.getZapper(poolAddr, tokenIn, tokenOut)?.filter((z) => z.type !== "migration");
209
+ if (zappers && zappers.length > 1) {
210
+ throw new Error(
211
+ `Multiple zappers found for tokenIn ${this.labelAddress(
212
+ tokenIn
213
+ )} and tokenOut ${this.labelAddress(
214
+ tokenOut
215
+ )} on pool ${this.labelAddress(poolAddr)}`
233
216
  );
234
217
  }
235
- return result.asArray();
218
+ return zappers?.[0];
236
219
  }
237
- depositMetadata(poolAddr, tokenIn, tokenOut, allowDirectDeposit) {
220
+ #depositMetadata(type, poolAddr, tokenIn, tokenOut, allowDirectDeposit) {
238
221
  if (!tokenOut) {
239
222
  throw new Error("tokenOut is required for classic pool deposit");
240
223
  }
241
224
  const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
242
- const zapper = this.getZapper(poolAddr, tokenIn, tokenOut);
225
+ const zapper = this.#getDepositZapper(poolAddr, tokenIn, tokenOut);
243
226
  if (!zapper && !allowDirectDeposit) {
244
227
  throw new Error(
245
- `No zapper found for tokenIn ${this.labelAddress(tokenIn)} and tokenOut ${this.labelAddress(tokenOut)} on pool ${this.labelAddress(poolAddr)}`
228
+ `No zapper found for tokenIn ${this.labelAddress(
229
+ tokenIn
230
+ )} and tokenOut ${this.labelAddress(
231
+ tokenOut
232
+ )} on pool ${this.labelAddress(poolAddr)}`
246
233
  );
247
234
  }
248
235
  return {
@@ -251,41 +238,10 @@ class PoolService extends SDKConstruct {
251
238
  approveTarget: zapper?.baseParams.addr ?? pool.pool.address,
252
239
  // TODO: instead of permissible, return permitType зависимости от tokenIn
253
240
  // "none" | "eip2612" | "dai_like";
254
- permissible: !!zapper && tokenIn !== NATIVE_ADDRESS
241
+ permissible: !!zapper && tokenIn !== NATIVE_ADDRESS,
242
+ type
255
243
  };
256
244
  }
257
- getZapper(pool, tokenIn, tokenOut) {
258
- return this.zappers.get(pool)?.find(
259
- (z) => hexEq(z.tokenIn.addr, tokenIn) && hexEq(z.tokenOut.addr, tokenOut)
260
- );
261
- }
262
- mustGetZapper(poolAddr, tokenIn, tokenOut) {
263
- const result = this.getZapper(poolAddr, tokenIn, tokenOut);
264
- if (!result) {
265
- throw new Error(
266
- `No zapper found for tokenIn ${this.labelAddress(tokenIn)} and tokenOut ${this.labelAddress(tokenOut)} on pool ${this.labelAddress(poolAddr)}`
267
- );
268
- }
269
- return result;
270
- }
271
- #addZapper(z) {
272
- const existing = this.zappers.get(z.pool);
273
- if (existing) {
274
- const hasZapper = existing.some(
275
- (zz) => hexEq(zz.baseParams.addr, z.baseParams.addr)
276
- );
277
- if (!hasZapper) {
278
- existing.push(z);
279
- }
280
- } else {
281
- this.zappers.upsert(z.pool, [z]);
282
- }
283
- const zappersTokens = [z.tokenIn, z.tokenOut];
284
- for (const t of zappersTokens) {
285
- this.sdk.tokensMeta.upsert(t.addr, t);
286
- this.sdk.setAddressLabel(t.addr, t.symbol);
287
- }
288
- }
289
245
  #describeUnderlying(pool) {
290
246
  const market = this.sdk.marketRegister.findByPool(pool);
291
247
  return this.sdk.tokensMeta.mustGet(market.underlying);
@@ -26,6 +26,8 @@ export declare class TokensMeta extends AddressMap<TokenMetaData> {
26
26
  mustFindBySymbol(symbol: string): TokenMetaData;
27
27
  /**
28
28
  * Loads token information about phantom token and KYC underlying tokens
29
+ *
30
+ * @param tokens - tokens to load data for, defaults to all tokens
29
31
  */
30
- loadTokenData(): Promise<void>;
32
+ loadTokenData(...tokens: Address[]): Promise<void>;
31
33
  }
@@ -1,6 +1,5 @@
1
1
  import type { Address } from "viem";
2
2
  import type { MarketData, MarketFilter } from "../base/index.js";
3
- import { SDKConstruct } from "../base/index.js";
4
3
  import type { GearboxSDK } from "../GearboxSDK.js";
5
4
  import type { MarketStateHuman } from "../types/index.js";
6
5
  import { AddressMap } from "../utils/index.js";
@@ -9,7 +8,8 @@ import { MarketConfiguratorContract } from "./MarketConfiguratorContract.js";
9
8
  import { MarketSuite } from "./MarketSuite.js";
10
9
  import type { IPriceOracleContract } from "./oracle/index.js";
11
10
  import type { PoolSuite } from "./pool/index.js";
12
- export declare class MarketRegister extends SDKConstruct {
11
+ import { ZapperRegister } from "./ZapperRegister.js";
12
+ export declare class MarketRegister extends ZapperRegister {
13
13
  #private;
14
14
  constructor(sdk: GearboxSDK, ignoreMarkets?: Address[]);
15
15
  hydrate(state: MarketData[]): void;
@@ -0,0 +1,17 @@
1
+ import type { Address } from "viem";
2
+ import { SDKConstruct } from "../base/index.js";
3
+ import { AddressMap } from "../utils/index.js";
4
+ import type { ZapperData } from "./types.js";
5
+ export declare class ZapperRegister extends SDKConstruct {
6
+ #private;
7
+ /**
8
+ * Load zappers for all pools using periphery compressor, adds hardcoded zappers
9
+ */
10
+ loadZappers(force?: boolean): Promise<void>;
11
+ get zappers(): AddressMap<ZapperData[]>;
12
+ poolZappers(pool: Address): ZapperData[];
13
+ /**
14
+ * Can return multiple zappers if there are multiple zappers for the same tokenIn and tokenOut
15
+ */
16
+ getZapper(pool: Address, tokenIn: Address, tokenOut: Address): Array<ZapperData> | undefined;
17
+ }
@@ -5,3 +5,4 @@ export * from "./MarketSuite.js";
5
5
  export * from "./oracle/index.js";
6
6
  export * from "./pool/index.js";
7
7
  export * from "./pricefeeds/index.js";
8
+ export * from "./types.js";
@@ -0,0 +1,10 @@
1
+ import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype";
2
+ import type { Address } from "viem";
3
+ import type { peripheryCompressorAbi } from "../../abi/compressors/peripheryCompressor.js";
4
+ import type { Unarray } from "../base/index.js";
5
+ type CompressorZapperData = Unarray<AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof peripheryCompressorAbi, "getZappers">["outputs"]>>;
6
+ export interface ZapperData extends CompressorZapperData {
7
+ pool: Address;
8
+ type: "migration" | "kyc" | "base";
9
+ }
10
+ export {};
@@ -1,19 +1,11 @@
1
1
  import type { Address } from "viem";
2
2
  import { SDKConstruct } from "../base/index.js";
3
- import { AddressMap } from "../index.js";
4
- import type { AddLiquidityProps, DepositMetadata, IPoolsService, PoolServiceCall, RemoveLiquidityProps, ZapperData } from "./types.js";
3
+ import type { AddLiquidityProps, DepositMetadata, IPoolsService, PoolServiceCall, RemoveLiquidityProps } from "./types.js";
5
4
  export declare class PoolService extends SDKConstruct implements IPoolsService {
6
5
  #private;
7
- get zappers(): AddressMap<ZapperData[]>;
8
- loadZappers(force?: boolean): Promise<void>;
9
6
  getDepositTokensIn(pool: Address): Address[];
10
7
  getDepositTokensOut(pool: Address, tokenIn: Address): Address[];
11
8
  getDepositMetadata(pool: Address, tokenIn: Address, tokenOut?: Address): DepositMetadata;
12
9
  addLiquidity(props: AddLiquidityProps): PoolServiceCall | undefined;
13
10
  removeLiquidity(props: RemoveLiquidityProps): PoolServiceCall;
14
- protected depositTokensIn(poolAddr: Address, allowDirectDeposit: boolean): Address[];
15
- protected depositTokensOut(poolAddr: Address, tokenIn: Address, allowDirectDeposit: boolean): Address[];
16
- protected depositMetadata(poolAddr: Address, tokenIn: Address, tokenOut?: Address, allowDirectDeposit?: boolean): DepositMetadata;
17
- protected getZapper(pool: Address, tokenIn: Address, tokenOut: Address): ZapperData | undefined;
18
- protected mustGetZapper(poolAddr: Address, tokenIn: Address, tokenOut: Address): ZapperData;
19
11
  }
@@ -1,14 +1,8 @@
1
- import type { Abi, AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype";
1
+ import type { Abi } from "abitype";
2
2
  import type { Address, ContractFunctionArgs, ContractFunctionName } from "viem";
3
- import type { peripheryCompressorAbi } from "../../abi/compressors/peripheryCompressor.js";
4
- import type { Unarray } from "../base/index.js";
3
+ import type { ZapperData } from "../market/index.js";
5
4
  import type { Asset } from "../router/index.js";
6
5
  import type { PoolData_Legacy } from "../sdk-legacy/index.js";
7
- import type { AddressMap } from "../utils/index.js";
8
- type CompressorZapperData = Unarray<AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof peripheryCompressorAbi, "getZappers">["outputs"]>>;
9
- export interface ZapperData extends CompressorZapperData {
10
- pool: Address;
11
- }
12
6
  interface PermitResult {
13
7
  r: Address;
14
8
  s: Address;
@@ -57,16 +51,12 @@ export interface DepositMetadata {
57
51
  * If true, user can avoid approval step and deposit with permit
58
52
  */
59
53
  permissible: boolean;
60
- }
61
- export interface IPoolsService {
62
54
  /**
63
- * Mapping of pool address -> zappers for that pool
55
+ * Type of deposit
64
56
  */
65
- zappers: AddressMap<ZapperData[]>;
66
- /**
67
- * Load zappers for all pools using periphery compressor, adds hardcoded zappers
68
- */
69
- loadZappers(force?: boolean): Promise<void>;
57
+ type: "kyc-on-demand" | "kyc-default" | "classic";
58
+ }
59
+ export interface IPoolsService {
70
60
  /**
71
61
  * Returns list of tokens that can be deposited to a pool
72
62
  * @param pool
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "13.0.0-next.1",
3
+ "version": "13.0.0-next.11",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",
@@ -1,9 +0,0 @@
1
- import type { NetworkType } from "../../sdk/index.js";
2
- import type { ZapperData } from "./types.js";
3
- /**
4
- * Temporary zappers
5
- *
6
- * On paper we have periphery compressor, but we don't use it because we don't add zappers to market configurator as periphery contract and this is unnecessary action for risk curator
7
- * Zappers for KYC markets are always in compressor, though
8
- */
9
- export declare const extraZappers: Partial<Record<NetworkType, ZapperData[]>>;