@gearbox-protocol/sdk 13.0.0-next.2 → 13.0.0-next.4
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.
- package/dist/cjs/sdk/market/MarketRegister.js +2 -2
- package/dist/cjs/sdk/{pools/extraZappers.js → market/ZapperRegister.js} +95 -6
- package/dist/cjs/sdk/market/index.js +3 -1
- package/dist/cjs/sdk/market/types.js +16 -0
- package/dist/cjs/sdk/pools/PoolService.js +7 -87
- package/dist/esm/sdk/market/MarketRegister.js +2 -2
- package/dist/esm/sdk/{pools/extraZappers.js → market/ZapperRegister.js} +94 -2
- package/dist/esm/sdk/market/index.js +1 -0
- package/dist/esm/sdk/market/types.js +0 -0
- package/dist/esm/sdk/pools/PoolService.js +8 -94
- package/dist/types/sdk/market/MarketRegister.d.ts +2 -2
- package/dist/types/sdk/market/ZapperRegister.d.ts +14 -0
- package/dist/types/sdk/market/index.d.ts +1 -0
- package/dist/types/sdk/market/types.d.ts +9 -0
- package/dist/types/sdk/pools/PoolService.d.ts +1 -4
- package/dist/types/sdk/pools/types.d.ts +2 -16
- package/package.json +1 -1
- package/dist/types/sdk/pools/extraZappers.d.ts +0 -9
|
@@ -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
|
-
|
|
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,101 @@ 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
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var ZapperRegister_exports = {};
|
|
20
|
+
__export(ZapperRegister_exports, {
|
|
21
|
+
ZapperRegister: () => ZapperRegister
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
24
|
-
|
|
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 });
|
|
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 EXTRA_ZAPPERS[this.networkType] ?? []) {
|
|
77
|
+
this.#addZapper(z);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
#addZapper(z) {
|
|
81
|
+
const existing = this.zappers.get(z.pool);
|
|
82
|
+
if (existing) {
|
|
83
|
+
const hasZapper = existing.some(
|
|
84
|
+
(zz) => (0, import_utils.hexEq)(zz.baseParams.addr, z.baseParams.addr)
|
|
85
|
+
);
|
|
86
|
+
if (!hasZapper) {
|
|
87
|
+
existing.push(z);
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
this.zappers.upsert(z.pool, [z]);
|
|
91
|
+
}
|
|
92
|
+
const zappersTokens = [z.tokenIn, z.tokenOut];
|
|
93
|
+
for (const t of zappersTokens) {
|
|
94
|
+
this.sdk.tokensMeta.upsert(t.addr, t);
|
|
95
|
+
this.sdk.setAddressLabel(t.addr, t.symbol);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
get zappers() {
|
|
99
|
+
if (!this.#zappers) {
|
|
100
|
+
throw new Error("zappers not loaded, call loadZappers first");
|
|
101
|
+
}
|
|
102
|
+
return this.#zappers;
|
|
103
|
+
}
|
|
104
|
+
poolZappers(pool) {
|
|
105
|
+
return this.zappers.get(pool) ?? [];
|
|
106
|
+
}
|
|
107
|
+
getZapper(pool, tokenIn, tokenOut) {
|
|
108
|
+
return this.zappers.get(pool)?.find(
|
|
109
|
+
(z) => (0, import_utils.hexEq)(z.tokenIn.addr, tokenIn) && (0, import_utils.hexEq)(z.tokenOut.addr, tokenOut)
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const EXTRA_ZAPPERS = {
|
|
25
114
|
Mainnet: [
|
|
26
115
|
{
|
|
27
116
|
baseParams: {
|
|
@@ -132,5 +221,5 @@ const extraZappers = {
|
|
|
132
221
|
};
|
|
133
222
|
// Annotate the CommonJS export names for ESM import in node:
|
|
134
223
|
0 && (module.exports = {
|
|
135
|
-
|
|
224
|
+
ZapperRegister
|
|
136
225
|
});
|
|
@@ -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,59 +28,8 @@ 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");
|
|
33
31
|
const NATIVE_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
34
32
|
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
33
|
getDepositTokensIn(pool) {
|
|
86
34
|
const underlying = this.#describeUnderlying(pool);
|
|
87
35
|
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
@@ -215,7 +163,7 @@ class PoolService extends import_base.SDKConstruct {
|
|
|
215
163
|
if (allowDirectDeposit) {
|
|
216
164
|
result.add(pool.underlying);
|
|
217
165
|
}
|
|
218
|
-
const zappers = this.
|
|
166
|
+
const zappers = this.sdk.marketRegister.poolZappers(poolAddr);
|
|
219
167
|
for (const z of zappers) {
|
|
220
168
|
if ((0, import__.hexEq)(z.tokenOut.addr, poolAddr)) {
|
|
221
169
|
result.add(z.tokenIn.addr);
|
|
@@ -231,7 +179,7 @@ class PoolService extends import_base.SDKConstruct {
|
|
|
231
179
|
#depositTokensOut(poolAddr, tokenIn, allowDirectDeposit) {
|
|
232
180
|
const result = new import__.AddressSet();
|
|
233
181
|
const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
|
|
234
|
-
const zappers = this.
|
|
182
|
+
const zappers = this.sdk.marketRegister.poolZappers(poolAddr);
|
|
235
183
|
for (const z of zappers) {
|
|
236
184
|
if ((0, import__.hexEq)(z.tokenIn.addr, tokenIn)) {
|
|
237
185
|
result.add(z.tokenOut.addr);
|
|
@@ -252,7 +200,11 @@ class PoolService extends import_base.SDKConstruct {
|
|
|
252
200
|
throw new Error("tokenOut is required for classic pool deposit");
|
|
253
201
|
}
|
|
254
202
|
const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
|
|
255
|
-
const zapper = this
|
|
203
|
+
const zapper = this.sdk.marketRegister.getZapper(
|
|
204
|
+
poolAddr,
|
|
205
|
+
tokenIn,
|
|
206
|
+
tokenOut
|
|
207
|
+
);
|
|
256
208
|
if (!zapper && !allowDirectDeposit) {
|
|
257
209
|
throw new Error(
|
|
258
210
|
`No zapper found for tokenIn ${this.labelAddress(tokenIn)} and tokenOut ${this.labelAddress(tokenOut)} on pool ${this.labelAddress(poolAddr)}`
|
|
@@ -267,38 +219,6 @@ class PoolService extends import_base.SDKConstruct {
|
|
|
267
219
|
permissible: !!zapper && tokenIn !== NATIVE_ADDRESS
|
|
268
220
|
};
|
|
269
221
|
}
|
|
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
222
|
#describeUnderlying(pool) {
|
|
303
223
|
const market = this.sdk.marketRegister.findByPool(pool);
|
|
304
224
|
return this.sdk.tokensMeta.mustGet(market.underlying);
|
|
@@ -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
|
-
|
|
11
|
+
import { ZapperRegister } from "./ZapperRegister.js";
|
|
12
|
+
class MarketRegister extends ZapperRegister {
|
|
13
13
|
/**
|
|
14
14
|
* Mapping pool.address -> MarketSuite
|
|
15
15
|
*/
|
|
@@ -1,4 +1,96 @@
|
|
|
1
|
-
|
|
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 });
|
|
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 EXTRA_ZAPPERS[this.networkType] ?? []) {
|
|
57
|
+
this.#addZapper(z);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
#addZapper(z) {
|
|
61
|
+
const existing = this.zappers.get(z.pool);
|
|
62
|
+
if (existing) {
|
|
63
|
+
const hasZapper = existing.some(
|
|
64
|
+
(zz) => hexEq(zz.baseParams.addr, z.baseParams.addr)
|
|
65
|
+
);
|
|
66
|
+
if (!hasZapper) {
|
|
67
|
+
existing.push(z);
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
this.zappers.upsert(z.pool, [z]);
|
|
71
|
+
}
|
|
72
|
+
const zappersTokens = [z.tokenIn, z.tokenOut];
|
|
73
|
+
for (const t of zappersTokens) {
|
|
74
|
+
this.sdk.tokensMeta.upsert(t.addr, t);
|
|
75
|
+
this.sdk.setAddressLabel(t.addr, t.symbol);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
get zappers() {
|
|
79
|
+
if (!this.#zappers) {
|
|
80
|
+
throw new Error("zappers not loaded, call loadZappers first");
|
|
81
|
+
}
|
|
82
|
+
return this.#zappers;
|
|
83
|
+
}
|
|
84
|
+
poolZappers(pool) {
|
|
85
|
+
return this.zappers.get(pool) ?? [];
|
|
86
|
+
}
|
|
87
|
+
getZapper(pool, tokenIn, tokenOut) {
|
|
88
|
+
return this.zappers.get(pool)?.find(
|
|
89
|
+
(z) => hexEq(z.tokenIn.addr, tokenIn) && hexEq(z.tokenOut.addr, tokenOut)
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const EXTRA_ZAPPERS = {
|
|
2
94
|
Mainnet: [
|
|
3
95
|
{
|
|
4
96
|
baseParams: {
|
|
@@ -108,5 +200,5 @@ const extraZappers = {
|
|
|
108
200
|
]
|
|
109
201
|
};
|
|
110
202
|
export {
|
|
111
|
-
|
|
203
|
+
ZapperRegister
|
|
112
204
|
};
|
|
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,66 +8,9 @@ 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";
|
|
20
12
|
const NATIVE_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
21
13
|
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
14
|
getDepositTokensIn(pool) {
|
|
73
15
|
const underlying = this.#describeUnderlying(pool);
|
|
74
16
|
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
@@ -202,7 +144,7 @@ class PoolService extends SDKConstruct {
|
|
|
202
144
|
if (allowDirectDeposit) {
|
|
203
145
|
result.add(pool.underlying);
|
|
204
146
|
}
|
|
205
|
-
const zappers = this.
|
|
147
|
+
const zappers = this.sdk.marketRegister.poolZappers(poolAddr);
|
|
206
148
|
for (const z of zappers) {
|
|
207
149
|
if (hexEq(z.tokenOut.addr, poolAddr)) {
|
|
208
150
|
result.add(z.tokenIn.addr);
|
|
@@ -218,7 +160,7 @@ class PoolService extends SDKConstruct {
|
|
|
218
160
|
#depositTokensOut(poolAddr, tokenIn, allowDirectDeposit) {
|
|
219
161
|
const result = new AddressSet();
|
|
220
162
|
const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
|
|
221
|
-
const zappers = this.
|
|
163
|
+
const zappers = this.sdk.marketRegister.poolZappers(poolAddr);
|
|
222
164
|
for (const z of zappers) {
|
|
223
165
|
if (hexEq(z.tokenIn.addr, tokenIn)) {
|
|
224
166
|
result.add(z.tokenOut.addr);
|
|
@@ -239,7 +181,11 @@ class PoolService extends SDKConstruct {
|
|
|
239
181
|
throw new Error("tokenOut is required for classic pool deposit");
|
|
240
182
|
}
|
|
241
183
|
const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
|
|
242
|
-
const zapper = this
|
|
184
|
+
const zapper = this.sdk.marketRegister.getZapper(
|
|
185
|
+
poolAddr,
|
|
186
|
+
tokenIn,
|
|
187
|
+
tokenOut
|
|
188
|
+
);
|
|
243
189
|
if (!zapper && !allowDirectDeposit) {
|
|
244
190
|
throw new Error(
|
|
245
191
|
`No zapper found for tokenIn ${this.labelAddress(tokenIn)} and tokenOut ${this.labelAddress(tokenOut)} on pool ${this.labelAddress(poolAddr)}`
|
|
@@ -254,38 +200,6 @@ class PoolService extends SDKConstruct {
|
|
|
254
200
|
permissible: !!zapper && tokenIn !== NATIVE_ADDRESS
|
|
255
201
|
};
|
|
256
202
|
}
|
|
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
203
|
#describeUnderlying(pool) {
|
|
290
204
|
const market = this.sdk.marketRegister.findByPool(pool);
|
|
291
205
|
return this.sdk.tokensMeta.mustGet(market.underlying);
|
|
@@ -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
|
-
|
|
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,14 @@
|
|
|
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
|
+
getZapper(pool: Address, tokenIn: Address, tokenOut: Address): ZapperData | undefined;
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
}
|
|
9
|
+
export {};
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
2
|
import { SDKConstruct } from "../base/index.js";
|
|
3
|
-
import {
|
|
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;
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import type { Abi
|
|
1
|
+
import type { Abi } from "abitype";
|
|
2
2
|
import type { Address, ContractFunctionArgs, ContractFunctionName } from "viem";
|
|
3
|
-
import type {
|
|
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;
|
|
@@ -59,14 +53,6 @@ export interface DepositMetadata {
|
|
|
59
53
|
permissible: boolean;
|
|
60
54
|
}
|
|
61
55
|
export interface IPoolsService {
|
|
62
|
-
/**
|
|
63
|
-
* Mapping of pool address -> zappers for that pool
|
|
64
|
-
*/
|
|
65
|
-
zappers: AddressMap<ZapperData[]>;
|
|
66
|
-
/**
|
|
67
|
-
* Load zappers for all pools using periphery compressor, adds hardcoded zappers
|
|
68
|
-
*/
|
|
69
|
-
loadZappers(force?: boolean): Promise<void>;
|
|
70
56
|
/**
|
|
71
57
|
* Returns list of tokens that can be deposited to a pool
|
|
72
58
|
* @param pool
|
package/package.json
CHANGED
|
@@ -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[]>>;
|