@gearbox-protocol/sdk 14.10.3-next.2 → 14.10.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 (48) hide show
  1. package/dist/cjs/dev/AccountOpener.js +5 -4
  2. package/dist/cjs/plugins/apy/strategy-data-source.js +1 -1
  3. package/dist/cjs/sdk/market/MarketSuite.js +63 -3
  4. package/dist/cjs/sdk/market/ZapperRegister.js +3 -5
  5. package/dist/cjs/sdk/market/credit/CreditSuite.js +81 -9
  6. package/dist/cjs/sdk/market/index.js +1 -3
  7. package/dist/cjs/sdk/market/pool/PoolSuite.js +64 -0
  8. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +0 -20
  9. package/dist/cjs/sdk/pools/PoolService.js +60 -58
  10. package/dist/esm/dev/AccountOpener.js +5 -4
  11. package/dist/esm/plugins/apy/strategy-data-source.js +1 -1
  12. package/dist/esm/sdk/market/MarketSuite.js +63 -3
  13. package/dist/esm/sdk/market/ZapperRegister.js +3 -5
  14. package/dist/esm/sdk/market/credit/CreditSuite.js +81 -9
  15. package/dist/esm/sdk/market/index.js +0 -1
  16. package/dist/esm/sdk/market/pool/PoolSuite.js +64 -0
  17. package/dist/esm/sdk/market/pool/PoolV310Contract.js +0 -20
  18. package/dist/esm/sdk/pools/PoolService.js +60 -62
  19. package/dist/types/sdk/market/MarketSuite.d.ts +70 -1
  20. package/dist/types/sdk/market/ZapperRegister.d.ts +4 -4
  21. package/dist/types/sdk/market/credit/CreditSuite.d.ts +84 -4
  22. package/dist/types/sdk/market/index.d.ts +0 -1
  23. package/dist/types/sdk/market/pool/PoolSuite.d.ts +75 -0
  24. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +2 -12
  25. package/dist/types/sdk/pools/PoolService.d.ts +3 -3
  26. package/dist/types/sdk/pools/types.d.ts +5 -10
  27. package/package.json +1 -1
  28. package/dist/cjs/abi/iERC20Zapper.js +0 -33
  29. package/dist/cjs/abi/iETHZapper.js +0 -30
  30. package/dist/cjs/sdk/market/zapper/IERC20ZapperContract.js +0 -98
  31. package/dist/cjs/sdk/market/zapper/IETHZapperContract.js +0 -89
  32. package/dist/cjs/sdk/market/zapper/Zapper.js +0 -41
  33. package/dist/cjs/sdk/market/zapper/createZapper.js +0 -38
  34. package/dist/cjs/sdk/market/zapper/index.js +0 -28
  35. package/dist/esm/abi/iERC20Zapper.js +0 -9
  36. package/dist/esm/abi/iETHZapper.js +0 -6
  37. package/dist/esm/sdk/market/zapper/IERC20ZapperContract.js +0 -74
  38. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +0 -65
  39. package/dist/esm/sdk/market/zapper/Zapper.js +0 -17
  40. package/dist/esm/sdk/market/zapper/createZapper.js +0 -14
  41. package/dist/esm/sdk/market/zapper/index.js +0 -4
  42. package/dist/types/abi/iERC20Zapper.d.ts +0 -313
  43. package/dist/types/abi/iETHZapper.d.ts +0 -153
  44. package/dist/types/sdk/market/zapper/IERC20ZapperContract.d.ts +0 -350
  45. package/dist/types/sdk/market/zapper/IETHZapperContract.d.ts +0 -186
  46. package/dist/types/sdk/market/zapper/Zapper.d.ts +0 -10
  47. package/dist/types/sdk/market/zapper/createZapper.d.ts +0 -6
  48. package/dist/types/sdk/market/zapper/index.d.ts +0 -4
@@ -7,17 +7,55 @@ import { MarketConfiguratorContract } from "./MarketConfiguratorContract.js";
7
7
  import { createPriceOracle } from "./oracle/index.js";
8
8
  import { PoolSuite } from "./pool/index.js";
9
9
  class MarketSuite extends SDKConstruct {
10
+ /**
11
+ * Access-control list contract that owns market roles such as pausable and
12
+ * unpausable admins.
13
+ */
10
14
  acl;
15
+ /**
16
+ * Treasury splitter or fee recipient associated with this market.
17
+ */
11
18
  treasury;
19
+ /**
20
+ * Market-level configurator that controls pool and credit-suite risk
21
+ * parameters.
22
+ */
12
23
  configurator;
24
+ /**
25
+ * Pool-side contract bundle: ERC-4626 pool, quota keeper, rate keeper, and
26
+ * interest-rate model.
27
+ */
13
28
  pool;
29
+ /**
30
+ * Market price oracle used by credit managers and pool for normalized
31
+ * price conversion and safe-price checks.
32
+ */
14
33
  priceOracle;
34
+ /**
35
+ * Bad-debt liquidation policy shared by the market's credit facades.
36
+ */
15
37
  lossPolicy;
38
+ /**
39
+ * Credit-suite wrappers connected to the pool.
40
+ *
41
+ * @remarks
42
+ * Each suite corresponds to one credit manager branch with its own facade,
43
+ * configurator, collateral set, adapters, debt limits, and expiration policy.
44
+ */
16
45
  creditManagers = [];
17
46
  /**
18
- * Original data received from compressor
47
+ * Original market snapshot received from the market compressor contract.
19
48
  */
20
49
  state;
50
+ /**
51
+ * Creates a market aggregate from compressor state.
52
+ *
53
+ * @param sdk - Attached on-chain SDK instance used for contract lookup,
54
+ * labels, token metadata, and plugin access.
55
+ * @param marketData - Full market state returned by the market compressor.
56
+ * @throws If the configurator address from `marketData` is not already
57
+ * registered as a {@link MarketConfiguratorContract}.
58
+ */
21
59
  constructor(sdk, marketData) {
22
60
  super(sdk);
23
61
  this.state = marketData;
@@ -35,21 +73,37 @@ class MarketSuite extends SDKConstruct {
35
73
  sdk.setAddressLabel(t.addr, t.symbol);
36
74
  }
37
75
  this.pool = new PoolSuite(sdk, marketData);
38
- for (let i = 0; i < marketData.creditManagers.length; i++) {
39
- this.creditManagers.push(new CreditSuite(sdk, marketData, i));
76
+ for (const suiteData of marketData.creditManagers) {
77
+ this.creditManagers.push(new CreditSuite(sdk, suiteData));
40
78
  }
41
79
  this.priceOracle = createPriceOracle(sdk, marketData.priceOracle);
42
80
  this.lossPolicy = createLossPolicy(sdk, marketData.lossPolicy);
43
81
  }
82
+ /**
83
+ * Underlying token of the market pool.
84
+ */
44
85
  get underlying() {
45
86
  return this.pool.underlying;
46
87
  }
88
+ /**
89
+ * Factory contract that opens and manages RWA-compliant credit accounts for
90
+ * this market. Defined only for RWA markets.
91
+ */
47
92
  get rwaFactory() {
48
93
  return this.pool.rwaFactory;
49
94
  }
95
+ /**
96
+ * Whether any child contract wrapper has observed events that require a
97
+ * market resync.
98
+ */
50
99
  get dirty() {
51
100
  return this.configurator.dirty || this.pool.dirty || this.priceOracle.dirty || this.creditManagers.some((cm) => cm.dirty);
52
101
  }
102
+ /**
103
+ * Contract addresses whose logs are enough to detect stale market state.
104
+ *
105
+ * @internal
106
+ */
53
107
  get watchAddresses() {
54
108
  return /* @__PURE__ */ new Set([
55
109
  this.configurator.address,
@@ -59,6 +113,12 @@ class MarketSuite extends SDKConstruct {
59
113
  ...Array.from(this.pool.watchAddresses)
60
114
  ]);
61
115
  }
116
+ /**
117
+ * Returns a label-enriched, JSON-friendly view of the market state.
118
+ *
119
+ * @param raw - Whether child wrappers should keep raw numeric values when
120
+ * applying human formatting.
121
+ */
62
122
  stateHuman(raw = true) {
63
123
  return {
64
124
  configurator: this.labelAddress(this.configurator.address),
@@ -5,10 +5,9 @@ import {
5
5
  VERSION_RANGE_310
6
6
  } from "../constants/index.js";
7
7
  import { AddressMap, hexEq } from "../utils/index.js";
8
- import { createZapper } from "./zapper/index.js";
9
8
  class ZapperRegister extends SDKConstruct {
10
9
  /**
11
- * Mapping pool.address -> Zapper[]
10
+ * Mapping pool.address -> ZapperData[]
12
11
  * Needs to be loaded explicitly using loadZappers method
13
12
  */
14
13
  #zappers;
@@ -56,17 +55,16 @@ class ZapperRegister extends SDKConstruct {
56
55
  }
57
56
  }
58
57
  #addZapper(z) {
59
- const zapper = createZapper(this.sdk, z);
60
58
  const existing = this.zappers.get(z.pool);
61
59
  if (existing) {
62
60
  const hasZapper = existing.some(
63
61
  (zz) => hexEq(zz.baseParams.addr, z.baseParams.addr)
64
62
  );
65
63
  if (!hasZapper) {
66
- existing.push(zapper);
64
+ existing.push(z);
67
65
  }
68
66
  } else {
69
- this.zappers.upsert(z.pool, [zapper]);
67
+ this.zappers.upsert(z.pool, [z]);
70
68
  }
71
69
  const zappersTokens = [z.tokenIn, z.tokenOut];
72
70
  for (const t of zappersTokens) {
@@ -3,35 +3,101 @@ import createCreditConfigurator from "./createCreditConfigurator.js";
3
3
  import createCreditFacade from "./createCreditFacade.js";
4
4
  import createCreditManager from "./createCreditManager.js";
5
5
  class CreditSuite extends SDKConstruct {
6
+ /**
7
+ * Pool that supplies underlying liquidity to this credit manager.
8
+ */
6
9
  pool;
7
- underlying;
10
+ /**
11
+ * Wrapper around the core credit manager contract.
12
+ *
13
+ * @remarks
14
+ * The credit manager owns account accounting, collateral checks, enabled
15
+ * collateral token masks, adapter mappings, debt updates, and liquidation
16
+ * calculations for this branch.
17
+ */
8
18
  creditManager;
19
+ /**
20
+ * Wrapper around the credit facade contract used to build account
21
+ * transactions such as open, close, liquidate, and multicall.
22
+ */
9
23
  creditFacade;
24
+ /**
25
+ * Wrapper around the credit configurator that mutates risk
26
+ * parameters, collateral tokens, adapter permissions, and facade settings.
27
+ */
10
28
  creditConfigurator;
11
- marketConfigurator;
29
+ /**
30
+ * Original compressor contract snapshot for this credit suite.
31
+ */
12
32
  state;
33
+ /**
34
+ * Human-readable credit manager name from the core contract state.
35
+ */
13
36
  name;
14
- constructor(sdk, marketData, index) {
37
+ /**
38
+ * Creates a credit suite from one entry in a market compressor snapshot.
39
+ *
40
+ * @param sdk - Attached SDK instance.
41
+ * @param data - Parent market snapshot part that contains the credit suite data.
42
+ */
43
+ constructor(sdk, data) {
15
44
  super(sdk);
16
- const { creditManagers, pool } = marketData;
17
- this.name = creditManagers[index].creditManager.name;
18
- this.state = creditManagers[index];
19
- this.pool = pool.baseParams.addr;
20
- this.underlying = pool.underlying;
45
+ this.name = data.creditManager.name;
46
+ this.state = data;
47
+ this.pool = data.creditManager.pool;
21
48
  this.creditManager = createCreditManager(sdk, this.state);
22
49
  this.creditFacade = createCreditFacade(sdk, this.state);
23
50
  this.creditConfigurator = createCreditConfigurator(sdk, this.state);
24
- this.marketConfigurator = marketData.configurator;
25
51
  }
52
+ /**
53
+ * Token borrowed from the pool and used as the account debt asset.
54
+ */
55
+ get underlying() {
56
+ return this.creditManager.underlying;
57
+ }
58
+ /**
59
+ * Parent market that contains this credit manager
60
+ */
61
+ get market() {
62
+ return this.sdk.marketRegister.findByCreditManager(
63
+ this.creditManager.address
64
+ );
65
+ }
66
+ /**
67
+ * Market configurator that governs this credit suite and its parent pool.
68
+ */
69
+ get marketConfigurator() {
70
+ return this.market.configurator;
71
+ }
72
+ /**
73
+ * Router configured for this credit suite.
74
+ */
26
75
  get router() {
27
76
  return this.sdk.routerFor(this);
28
77
  }
78
+ /**
79
+ * Whether this suite's facade is past its configured expiration timestamp.
80
+ *
81
+ * @remarks
82
+ * Expired credit suites can have different liquidation parameters on-chain.
83
+ * Non-expirable facades and facades with zero expiration are treated as not
84
+ * expired.
85
+ */
29
86
  get isExpired() {
30
87
  return this.creditFacade.expirable && this.creditFacade.expirationDate > 0 && this.creditFacade.expirationDate < this.sdk.timestamp;
31
88
  }
89
+ /**
90
+ * Whether the facade, manager, or configurator has observed logs that require
91
+ * a credit-suite resync.
92
+ */
32
93
  get dirty() {
33
94
  return this.creditFacade.dirty || this.creditManager.dirty || this.creditConfigurator.dirty;
34
95
  }
96
+ /**
97
+ * Credit contracts whose events are enough to detect stale suite state.
98
+ *
99
+ * @internal
100
+ */
35
101
  get watchAddresses() {
36
102
  return /* @__PURE__ */ new Set([
37
103
  this.creditConfigurator.address,
@@ -39,6 +105,12 @@ class CreditSuite extends SDKConstruct {
39
105
  this.creditFacade.address
40
106
  ]);
41
107
  }
108
+ /**
109
+ * Returns a label-enriched, JSON-friendly view of this credit suite.
110
+ *
111
+ * @param raw - Whether child wrappers should keep raw numeric values instead
112
+ * of applying human formatting where they support both modes.
113
+ */
42
114
  stateHuman(raw = true) {
43
115
  return {
44
116
  isExpired: this.isExpired,
@@ -7,4 +7,3 @@ export * from "./pool/index.js";
7
7
  export * from "./pricefeeds/index.js";
8
8
  export * from "./rwa/index.js";
9
9
  export * from "./types.js";
10
- export * from "./zapper/index.js";
@@ -7,11 +7,34 @@ import { GaugeContract } from "./GaugeContract.js";
7
7
  import { LinearInterestRateModelContract } from "./LinearInterestRateModelContract.js";
8
8
  import { TumblerContract } from "./TumblerContract.js";
9
9
  class PoolSuite extends SDKConstruct {
10
+ /**
11
+ * ERC-4626 liquidity pool wrapper for deposits, withdrawals, borrowing
12
+ * limits, and base interest accounting.
13
+ */
10
14
  pool;
15
+ /**
16
+ * Quota keeper wrapper that tracks per-token quota limits, quoted exposure,
17
+ * quota rates, and credit-manager access.
18
+ */
11
19
  pqk;
20
+ /**
21
+ * Rate keeper used by the quota keeper to obtain collateral-specific quota
22
+ * rates. Can be a {@link GaugeContract} or a {@link TumblerContract}.
23
+ */
12
24
  rateKeeper;
25
+ /**
26
+ * Interest-rate model used by the pool to calculate the base borrow rate from
27
+ * expected and available liquidity.
28
+ */
13
29
  interestRateModel;
14
30
  #marketConfigurator;
31
+ /**
32
+ * Creates the pool aggregate from a market compressor snapshot.
33
+ *
34
+ * @param sdk - Attached SDK instance
35
+ * @param data - Full market snapshot containing pool, quota, rate, and
36
+ * interest-rate model state.
37
+ */
15
38
  constructor(sdk, data) {
16
39
  super(sdk);
17
40
  this.pool = createPool(sdk, data.pool);
@@ -23,6 +46,11 @@ class PoolSuite extends SDKConstruct {
23
46
  );
24
47
  this.#marketConfigurator = data.configurator;
25
48
  }
49
+ /**
50
+ * Narrows `rateKeeper` to a gauge rate keeper.
51
+ *
52
+ * @throws If the market uses a different rate keeper type.
53
+ */
26
54
  get gauge() {
27
55
  if (this.rateKeeper instanceof GaugeContract) {
28
56
  return this.rateKeeper;
@@ -31,6 +59,11 @@ class PoolSuite extends SDKConstruct {
31
59
  `Rate keeper is not a gauge, but a ${this.rateKeeper.contractType}`
32
60
  );
33
61
  }
62
+ /**
63
+ * Narrows `rateKeeper` to a tumbler rate keeper.
64
+ *
65
+ * @throws If the market uses a different rate keeper type.
66
+ */
34
67
  get tumbler() {
35
68
  if (this.rateKeeper instanceof TumblerContract) {
36
69
  return this.rateKeeper;
@@ -39,6 +72,11 @@ class PoolSuite extends SDKConstruct {
39
72
  `Rate keeper is not a tumbler, but a ${this.rateKeeper.contractType}`
40
73
  );
41
74
  }
75
+ /**
76
+ * Narrows `interestRateModel` to the linear interest-rate model.
77
+ *
78
+ * @throws If the market uses a different interest-rate model type.
79
+ */
42
80
  get linearModel() {
43
81
  if (this.interestRateModel instanceof LinearInterestRateModelContract) {
44
82
  return this.interestRateModel;
@@ -47,20 +85,40 @@ class PoolSuite extends SDKConstruct {
47
85
  `Interest rate model is not a linear model, but a ${this.interestRateModel.contractType}`
48
86
  );
49
87
  }
88
+ /**
89
+ * Market configurator that governs the pool and its connected credit suites.
90
+ *
91
+ * @throws If the configurator is missing from the SDK contract register.
92
+ */
50
93
  get marketConfigurator() {
51
94
  return this.register.mustGetContract(
52
95
  this.#marketConfigurator
53
96
  );
54
97
  }
98
+ /**
99
+ * Underlying asset deposited into the pool and borrowed by connected credit
100
+ * suites.
101
+ */
55
102
  get underlying() {
56
103
  return this.pool.underlying;
57
104
  }
105
+ /**
106
+ * RWA factory associated with the pool's underlying, undefined for non-RWA markets.
107
+ */
58
108
  get rwaFactory() {
59
109
  return this.pool.rwaFactory;
60
110
  }
111
+ /**
112
+ * Whether any pool-side wrapper has observed logs that require a resync.
113
+ */
61
114
  get dirty() {
62
115
  return this.pool.dirty || this.rateKeeper.dirty || this.pqk.dirty || this.interestRateModel.dirty;
63
116
  }
117
+ /**
118
+ * Pool-side contract addresses whose logs are enough to detect stale state.
119
+ *
120
+ * @internal
121
+ */
64
122
  get watchAddresses() {
65
123
  return /* @__PURE__ */ new Set([
66
124
  this.pool.address,
@@ -69,6 +127,12 @@ class PoolSuite extends SDKConstruct {
69
127
  this.interestRateModel.address
70
128
  ]);
71
129
  }
130
+ /**
131
+ * Returns a label-enriched, JSON-friendly view of the pool-side state.
132
+ *
133
+ * @param raw - Whether child wrappers should keep raw numeric values instead
134
+ * of applying human formatting where they support both modes.
135
+ */
72
136
  stateHuman(raw = true) {
73
137
  return {
74
138
  pool: this.pool.stateHuman(raw),
@@ -109,26 +109,6 @@ class PoolV310Contract extends BaseContract {
109
109
  break;
110
110
  }
111
111
  }
112
- /**
113
- * Deposits underlying assets into the pool on behalf of a user with a
114
- * referral code.
115
- */
116
- depositWithReferral(amount, onBehalfOf, referralCode) {
117
- return this.createRawTx({
118
- functionName: "depositWithReferral",
119
- args: [amount, onBehalfOf, referralCode]
120
- });
121
- }
122
- /**
123
- * Redeems pool shares from the owner and sends the underlying assets to
124
- * the receiver.
125
- */
126
- redeem(amount, owner, receiver) {
127
- return this.createRawTx({
128
- functionName: "redeem",
129
- args: [amount, owner, receiver]
130
- });
131
- }
132
112
  stringifyFunctionParams(params) {
133
113
  switch (params.functionName) {
134
114
  case "deposit": {
@@ -1,15 +1,14 @@
1
+ import { iPoolV310Abi } from "../../abi/310/generated.js";
1
2
  import { ierc20Abi } from "../../abi/iERC20.js";
3
+ import { ierc20ZapperDepositsAbi } from "../../abi/iERC20ZapperDeposits.js";
4
+ import { iethZapperDepositsAbi } from "../../abi/iETHZapperDeposits.js";
5
+ import { iZapperAbi } from "../../abi/iZapper.js";
2
6
  import {
3
- BaseContract,
4
7
  RWA_UNDERLYING_DEFAULT,
5
8
  RWA_UNDERLYING_ON_DEMAND,
6
9
  SDKConstruct
7
10
  } from "../base/index.js";
8
11
  import { NATIVE_ADDRESS } from "../constants/index.js";
9
- import {
10
- IERC20ZapperContract,
11
- IETHZapperContract
12
- } from "../market/index.js";
13
12
  import { AddressSet, hexEq } from "../utils/index.js";
14
13
  class PoolService extends SDKConstruct {
15
14
  /**
@@ -81,42 +80,42 @@ class PoolService extends SDKConstruct {
81
80
  }
82
81
  }
83
82
  const { zapper } = meta;
84
- if (zapper instanceof IETHZapperContract) {
85
- const tx2 = zapper.depositWithReferral(wallet, referralCode ?? 0n);
86
- tx2.value = collateral.balance.toString();
83
+ if (zapper && hexEq(zapper.tokenIn.addr, NATIVE_ADDRESS)) {
87
84
  return {
88
- tx: tx2,
89
- calls: [{ target: zapper.baseParams.addr, callData: tx2.callData }]
85
+ target: zapper.baseParams.addr,
86
+ abi: iethZapperDepositsAbi,
87
+ functionName: "depositWithReferral",
88
+ args: [wallet, referralCode],
89
+ value: collateral.balance
90
90
  };
91
- } else if (zapper instanceof IERC20ZapperContract) {
92
- const tx2 = permit ? zapper.depositWithReferralAndPermit(
93
- collateral.balance,
94
- wallet,
95
- referralCode ?? 0n,
96
- permit.deadline,
97
- permit.v,
98
- permit.r,
99
- permit.s
100
- ) : zapper.depositWithReferral(
101
- collateral.balance,
102
- wallet,
103
- referralCode ?? 0n
104
- );
91
+ } else if (zapper) {
92
+ return permit ? {
93
+ target: zapper.baseParams.addr,
94
+ abi: ierc20ZapperDepositsAbi,
95
+ functionName: "depositWithReferralAndPermit",
96
+ args: [
97
+ collateral.balance,
98
+ wallet,
99
+ referralCode,
100
+ permit.deadline,
101
+ permit.v,
102
+ permit.r,
103
+ permit.s
104
+ ]
105
+ } : {
106
+ target: zapper.baseParams.addr,
107
+ abi: ierc20ZapperDepositsAbi,
108
+ functionName: "depositWithReferral",
109
+ args: [collateral.balance, wallet, referralCode]
110
+ };
111
+ } else {
105
112
  return {
106
- tx: tx2,
107
- calls: [{ target: zapper.baseParams.addr, callData: tx2.callData }]
113
+ target: pool,
114
+ abi: iPoolV310Abi,
115
+ functionName: "depositWithReferral",
116
+ args: [collateral.balance, wallet, referralCode]
108
117
  };
109
118
  }
110
- const poolContract = this.sdk.marketRegister.findByPool(pool).pool.pool;
111
- const tx = poolContract.depositWithReferral(
112
- collateral.balance,
113
- wallet,
114
- referralCode ?? 0n
115
- );
116
- return {
117
- tx,
118
- calls: [{ target: pool, callData: tx.callData }]
119
- };
120
119
  }
121
120
  /**
122
121
  * {@inheritDoc IPoolsService.getWithdrawalTokensIn}
@@ -156,40 +155,39 @@ class PoolService extends SDKConstruct {
156
155
  const underlying = this.#describeUnderlying(pool);
157
156
  if (this.sdk.tokensMeta.isRWAUnderlying(underlying)) {
158
157
  if (underlying.contractType === RWA_UNDERLYING_ON_DEMAND) {
159
- const tokenContract = new BaseContract(this.sdk, {
160
- addr: underlying.asset,
158
+ return {
161
159
  abi: ierc20Abi,
162
- name: "ERC20"
163
- });
164
- const tx2 = tokenContract.createRawTx({
165
160
  functionName: "approve",
166
- args: [underlying.liquidityProvider.addr, 0n]
167
- });
168
- return {
169
- tx: tx2,
170
- calls: [{ target: underlying.asset, callData: tx2.callData }]
161
+ args: [underlying.liquidityProvider, 0n],
162
+ target: underlying.asset
171
163
  };
172
164
  }
173
165
  }
174
- if (meta.zapper instanceof IETHZapperContract || meta.zapper instanceof IERC20ZapperContract) {
175
- const tx2 = permit ? meta.zapper.redeemWithPermit(
176
- amount,
177
- wallet,
178
- permit.deadline,
179
- permit.v,
180
- permit.r,
181
- permit.s
182
- ) : meta.zapper.redeem(amount, wallet);
183
- return {
184
- tx: tx2,
185
- calls: [{ target: meta.zapper.baseParams.addr, callData: tx2.callData }]
166
+ if (meta.zapper) {
167
+ return permit ? {
168
+ target: meta.zapper.baseParams.addr,
169
+ abi: iZapperAbi,
170
+ functionName: "redeemWithPermit",
171
+ args: [
172
+ amount,
173
+ wallet,
174
+ permit.deadline,
175
+ permit.v,
176
+ permit.r,
177
+ permit.s
178
+ ]
179
+ } : {
180
+ target: meta.zapper.baseParams.addr,
181
+ abi: iZapperAbi,
182
+ functionName: "redeem",
183
+ args: [amount, wallet]
186
184
  };
187
185
  }
188
- const poolContract = this.sdk.marketRegister.findByPool(pool).pool.pool;
189
- const tx = poolContract.redeem(amount, wallet, wallet);
190
186
  return {
191
- tx,
192
- calls: [{ target: pool, callData: tx.callData }]
187
+ target: pool,
188
+ abi: iPoolV310Abi,
189
+ functionName: "redeem",
190
+ args: [amount, wallet, wallet]
193
191
  };
194
192
  }
195
193
  /**
@@ -9,22 +9,91 @@ import { MarketConfiguratorContract } from "./MarketConfiguratorContract.js";
9
9
  import type { IPriceOracleContract } from "./oracle/index.js";
10
10
  import { PoolSuite } from "./pool/index.js";
11
11
  import type { IRWAFactory } from "./rwa/types.js";
12
+ /**
13
+ * Aggregates all SDK wrappers that make up one Gearbox market.
14
+ *
15
+ * @remarks
16
+ * A market is the SDK representation of the core "one pool, many markets"
17
+ * architecture: one liquidity pool can fund several isolated credit suites,
18
+ * while the market-level configurator, price oracle, and loss policy define
19
+ * the shared risk boundary.
20
+ */
12
21
  export declare class MarketSuite extends SDKConstruct {
22
+ /**
23
+ * Access-control list contract that owns market roles such as pausable and
24
+ * unpausable admins.
25
+ */
13
26
  readonly acl: Address;
27
+ /**
28
+ * Treasury splitter or fee recipient associated with this market.
29
+ */
14
30
  readonly treasury: Address;
31
+ /**
32
+ * Market-level configurator that controls pool and credit-suite risk
33
+ * parameters.
34
+ */
15
35
  readonly configurator: MarketConfiguratorContract;
36
+ /**
37
+ * Pool-side contract bundle: ERC-4626 pool, quota keeper, rate keeper, and
38
+ * interest-rate model.
39
+ */
16
40
  readonly pool: PoolSuite;
41
+ /**
42
+ * Market price oracle used by credit managers and pool for normalized
43
+ * price conversion and safe-price checks.
44
+ */
17
45
  readonly priceOracle: IPriceOracleContract;
46
+ /**
47
+ * Bad-debt liquidation policy shared by the market's credit facades.
48
+ */
18
49
  readonly lossPolicy: ILossPolicyContract;
50
+ /**
51
+ * Credit-suite wrappers connected to the pool.
52
+ *
53
+ * @remarks
54
+ * Each suite corresponds to one credit manager branch with its own facade,
55
+ * configurator, collateral set, adapters, debt limits, and expiration policy.
56
+ */
19
57
  readonly creditManagers: CreditSuite[];
20
58
  /**
21
- * Original data received from compressor
59
+ * Original market snapshot received from the market compressor contract.
22
60
  */
23
61
  readonly state: MarketData;
62
+ /**
63
+ * Creates a market aggregate from compressor state.
64
+ *
65
+ * @param sdk - Attached on-chain SDK instance used for contract lookup,
66
+ * labels, token metadata, and plugin access.
67
+ * @param marketData - Full market state returned by the market compressor.
68
+ * @throws If the configurator address from `marketData` is not already
69
+ * registered as a {@link MarketConfiguratorContract}.
70
+ */
24
71
  constructor(sdk: OnchainSDK, marketData: MarketData);
72
+ /**
73
+ * Underlying token of the market pool.
74
+ */
25
75
  get underlying(): Address;
76
+ /**
77
+ * Factory contract that opens and manages RWA-compliant credit accounts for
78
+ * this market. Defined only for RWA markets.
79
+ */
26
80
  get rwaFactory(): IRWAFactory | undefined;
81
+ /**
82
+ * Whether any child contract wrapper has observed events that require a
83
+ * market resync.
84
+ */
27
85
  get dirty(): boolean;
86
+ /**
87
+ * Contract addresses whose logs are enough to detect stale market state.
88
+ *
89
+ * @internal
90
+ */
28
91
  get watchAddresses(): Set<Address>;
92
+ /**
93
+ * Returns a label-enriched, JSON-friendly view of the market state.
94
+ *
95
+ * @param raw - Whether child wrappers should keep raw numeric values when
96
+ * applying human formatting.
97
+ */
29
98
  stateHuman(raw?: boolean): MarketStateHuman;
30
99
  }