@gearbox-protocol/sdk 13.6.0-kyc.7 → 13.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/dist/cjs/dev/AccountOpener.js +5 -45
  2. package/dist/cjs/dev/logSplitterTransport.js +10 -1
  3. package/dist/cjs/plugins/adapters/abi/actionAbi.js +1 -1
  4. package/dist/cjs/plugins/adapters/abi/conctructorAbi.js +1 -1
  5. package/dist/cjs/plugins/adapters/createAdapter.js +1 -1
  6. package/dist/cjs/plugins/adapters/types.js +1 -1
  7. package/dist/cjs/plugins/apy/ApyPlugin.js +266 -0
  8. package/dist/cjs/plugins/apy/apy-cache.js +120 -0
  9. package/dist/cjs/plugins/apy/apy-parser.js +169 -0
  10. package/dist/cjs/{sdk/market/kyc/securitize → plugins/apy}/constants.js +6 -3
  11. package/dist/cjs/{sdk/market/kyc/securitize → plugins/apy}/index.js +14 -6
  12. package/dist/cjs/{sdk/market/kyc/securitize/types.js → plugins/apy/pool-apy-types.js} +2 -2
  13. package/dist/cjs/plugins/apy/pool-apy-utils.js +141 -0
  14. package/dist/cjs/rewards/rewards/extra-apy.js +10 -8
  15. package/dist/cjs/sdk/GearboxSDK.js +5 -52
  16. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +16 -324
  17. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +1 -7
  18. package/dist/cjs/sdk/base/TokensMeta.js +43 -32
  19. package/dist/cjs/sdk/base/token-types.js +0 -9
  20. package/dist/cjs/sdk/chain/chains.js +32 -17
  21. package/dist/cjs/sdk/constants/address-provider.js +0 -3
  22. package/dist/cjs/sdk/market/MarketRegister.js +116 -70
  23. package/dist/cjs/sdk/market/MarketSuite.js +0 -3
  24. package/dist/cjs/sdk/market/index.js +0 -2
  25. package/dist/cjs/sdk/market/pool/PoolSuite.js +0 -3
  26. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +2 -11
  27. package/dist/cjs/sdk/market/pool/index.js +0 -2
  28. package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -3
  29. package/dist/cjs/sdk/options.js +1 -7
  30. package/dist/cjs/sdk/pools/PoolService.js +12 -104
  31. package/dist/cjs/sdk/utils/viem/index.js +0 -2
  32. package/dist/cjs/sdk/utils/viem/simulateWithPriceUpdates.js +39 -2
  33. package/dist/esm/dev/AccountOpener.js +6 -47
  34. package/dist/esm/dev/logSplitterTransport.js +10 -1
  35. package/dist/esm/plugins/adapters/abi/actionAbi.js +1 -1
  36. package/dist/esm/plugins/adapters/abi/conctructorAbi.js +1 -1
  37. package/dist/esm/plugins/adapters/createAdapter.js +1 -1
  38. package/dist/esm/plugins/adapters/types.js +1 -1
  39. package/dist/esm/plugins/apy/ApyPlugin.js +255 -0
  40. package/dist/esm/plugins/apy/apy-cache.js +86 -0
  41. package/dist/esm/plugins/apy/apy-parser.js +143 -0
  42. package/dist/esm/plugins/apy/constants.js +6 -0
  43. package/dist/esm/plugins/apy/index.js +7 -0
  44. package/dist/esm/plugins/apy/pool-apy-utils.js +113 -0
  45. package/dist/esm/rewards/rewards/extra-apy.js +10 -8
  46. package/dist/esm/sdk/GearboxSDK.js +6 -56
  47. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +17 -328
  48. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +1 -7
  49. package/dist/esm/sdk/base/TokensMeta.js +45 -32
  50. package/dist/esm/sdk/base/token-types.js +0 -6
  51. package/dist/esm/sdk/chain/chains.js +32 -17
  52. package/dist/esm/sdk/constants/address-provider.js +0 -2
  53. package/dist/esm/sdk/market/MarketRegister.js +118 -74
  54. package/dist/esm/sdk/market/MarketSuite.js +0 -3
  55. package/dist/esm/sdk/market/index.js +0 -1
  56. package/dist/esm/sdk/market/pool/PoolSuite.js +0 -3
  57. package/dist/esm/sdk/market/pool/PoolV310Contract.js +2 -11
  58. package/dist/esm/sdk/market/pool/index.js +0 -1
  59. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -3
  60. package/dist/esm/sdk/options.js +1 -7
  61. package/dist/esm/sdk/pools/PoolService.js +13 -109
  62. package/dist/esm/sdk/utils/viem/index.js +0 -1
  63. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +41 -2
  64. package/dist/types/dev/logSplitterTransport.d.ts +3 -1
  65. package/dist/types/plugins/adapters/types.d.ts +2 -2
  66. package/dist/types/plugins/apy/ApyPlugin.d.ts +46 -0
  67. package/dist/types/plugins/apy/apy-cache.d.ts +28 -0
  68. package/dist/types/plugins/apy/apy-parser.d.ts +5 -0
  69. package/dist/types/plugins/apy/constants.d.ts +2 -0
  70. package/dist/types/plugins/apy/index.d.ts +7 -0
  71. package/dist/types/plugins/apy/pool-apy-types.d.ts +41 -0
  72. package/dist/types/plugins/apy/pool-apy-utils.d.ts +73 -0
  73. package/dist/types/plugins/apy/types.d.ts +37 -0
  74. package/dist/types/rewards/rewards/api.d.ts +10 -1
  75. package/dist/types/rewards/rewards/common.d.ts +0 -10
  76. package/dist/types/rewards/rewards/extra-apy.d.ts +4 -6
  77. package/dist/types/sdk/GearboxSDK.d.ts +0 -7
  78. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +2 -52
  79. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
  80. package/dist/types/sdk/accounts/types.d.ts +13 -93
  81. package/dist/types/sdk/base/TokensMeta.d.ts +3 -14
  82. package/dist/types/sdk/base/token-types.d.ts +4 -44
  83. package/dist/types/sdk/base/types.d.ts +11 -116
  84. package/dist/types/sdk/chain/chains.d.ts +5 -5
  85. package/dist/types/sdk/constants/address-provider.d.ts +0 -1
  86. package/dist/types/sdk/market/MarketRegister.d.ts +9 -6
  87. package/dist/types/sdk/market/MarketSuite.d.ts +0 -2
  88. package/dist/types/sdk/market/index.d.ts +0 -1
  89. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +2 -3
  90. package/dist/types/sdk/market/oracle/types.d.ts +10 -3
  91. package/dist/types/sdk/market/pool/PoolSuite.d.ts +0 -2
  92. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +2 -6
  93. package/dist/types/sdk/market/pool/index.d.ts +0 -1
  94. package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +1 -1
  95. package/dist/types/sdk/market/types.d.ts +1 -1
  96. package/dist/types/sdk/options.d.ts +0 -1
  97. package/dist/types/sdk/pools/PoolService.d.ts +8 -8
  98. package/dist/types/sdk/pools/types.d.ts +1 -1
  99. package/dist/types/sdk/types/state-human.d.ts +0 -2
  100. package/dist/types/sdk/types/state.d.ts +0 -5
  101. package/dist/types/sdk/utils/viem/index.d.ts +0 -1
  102. package/package.json +2 -3
  103. package/dist/cjs/abi/kyc/iDSRegistryService.js +0 -70
  104. package/dist/cjs/abi/kyc/iDSToken.js +0 -71
  105. package/dist/cjs/abi/kyc/iKYCCompressor.js +0 -196
  106. package/dist/cjs/abi/kyc/iKYCFactory.js +0 -122
  107. package/dist/cjs/abi/kyc/iKYCUnderlying.js +0 -401
  108. package/dist/cjs/abi/kyc/iSecuritizeDegenNFT.js +0 -326
  109. package/dist/cjs/abi/kyc/iSecuritizeKYCFactory.js +0 -319
  110. package/dist/cjs/plugins/pools-history/Pools7DAgoPlugin.js +0 -108
  111. package/dist/cjs/plugins/pools-history/index.js +0 -24
  112. package/dist/cjs/sdk/market/kyc/KYCRegistry.js +0 -269
  113. package/dist/cjs/sdk/market/kyc/index.js +0 -26
  114. package/dist/cjs/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +0 -244
  115. package/dist/cjs/sdk/market/kyc/types.js +0 -34
  116. package/dist/cjs/sdk/utils/viem/executeDelegatedMulticalls.js +0 -38
  117. package/dist/esm/abi/kyc/iDSRegistryService.js +0 -46
  118. package/dist/esm/abi/kyc/iDSToken.js +0 -47
  119. package/dist/esm/abi/kyc/iKYCCompressor.js +0 -172
  120. package/dist/esm/abi/kyc/iKYCFactory.js +0 -98
  121. package/dist/esm/abi/kyc/iKYCUnderlying.js +0 -377
  122. package/dist/esm/abi/kyc/iSecuritizeDegenNFT.js +0 -302
  123. package/dist/esm/abi/kyc/iSecuritizeKYCFactory.js +0 -295
  124. package/dist/esm/plugins/pools-history/Pools7DAgoPlugin.js +0 -90
  125. package/dist/esm/plugins/pools-history/index.js +0 -2
  126. package/dist/esm/sdk/market/kyc/KYCRegistry.js +0 -253
  127. package/dist/esm/sdk/market/kyc/index.js +0 -3
  128. package/dist/esm/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +0 -220
  129. package/dist/esm/sdk/market/kyc/securitize/constants.js +0 -4
  130. package/dist/esm/sdk/market/kyc/securitize/index.js +0 -3
  131. package/dist/esm/sdk/market/kyc/types.js +0 -9
  132. package/dist/esm/sdk/utils/viem/executeDelegatedMulticalls.js +0 -14
  133. package/dist/types/abi/kyc/iDSRegistryService.d.ts +0 -71
  134. package/dist/types/abi/kyc/iDSToken.d.ts +0 -67
  135. package/dist/types/abi/kyc/iKYCCompressor.d.ts +0 -228
  136. package/dist/types/abi/kyc/iKYCFactory.d.ts +0 -139
  137. package/dist/types/abi/kyc/iKYCUnderlying.d.ts +0 -548
  138. package/dist/types/abi/kyc/iSecuritizeDegenNFT.d.ts +0 -404
  139. package/dist/types/abi/kyc/iSecuritizeKYCFactory.d.ts +0 -376
  140. package/dist/types/plugins/pools-history/Pools7DAgoPlugin.d.ts +0 -20
  141. package/dist/types/plugins/pools-history/index.d.ts +0 -2
  142. package/dist/types/plugins/pools-history/types.d.ts +0 -9
  143. package/dist/types/sdk/market/kyc/KYCRegistry.d.ts +0 -52
  144. package/dist/types/sdk/market/kyc/index.d.ts +0 -3
  145. package/dist/types/sdk/market/kyc/securitize/SecuritizeKYCFactory.d.ts +0 -428
  146. package/dist/types/sdk/market/kyc/securitize/constants.d.ts +0 -1
  147. package/dist/types/sdk/market/kyc/securitize/index.d.ts +0 -3
  148. package/dist/types/sdk/market/kyc/securitize/types.d.ts +0 -127
  149. package/dist/types/sdk/market/kyc/types.d.ts +0 -170
  150. package/dist/types/sdk/utils/viem/executeDelegatedMulticalls.d.ts +0 -28
  151. /package/dist/cjs/plugins/{pools-history → apy}/package.json +0 -0
  152. /package/dist/cjs/plugins/{pools-history → apy}/types.js +0 -0
  153. /package/dist/esm/plugins/{pools-history → apy}/package.json +0 -0
  154. /package/dist/esm/plugins/{pools-history/types.js → apy/pool-apy-types.js} +0 -0
  155. /package/dist/esm/{sdk/market/kyc/securitize → plugins/apy}/types.js +0 -0
@@ -22,7 +22,6 @@ __export(PoolService_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(PoolService_exports);
24
24
  var import_generated = require("../../abi/310/generated.js");
25
- 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");
28
27
  var import_iZapper = require("../../abi/iZapper.js");
@@ -31,73 +30,28 @@ var import_constants = require("../constants/index.js");
31
30
  var import_utils = require("../utils/index.js");
32
31
  class PoolService extends import_base.SDKConstruct {
33
32
  /**
34
- * {@inheritDoc IPoolsService.getDepositTokensIn}
33
+ * @inheritdoc IPoolsService.getDepositTokensIn
35
34
  */
36
35
  getDepositTokensIn(pool) {
37
- const underlying = this.#describeUnderlying(pool);
38
- if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
39
- switch (underlying.contractType) {
40
- case import_base.KYC_UNDERLYING_DEFAULT:
41
- return this.#depositTokensIn(pool, false);
42
- case import_base.KYC_UNDERLYING_ON_DEMAND:
43
- return [underlying.asset];
44
- }
45
- }
46
36
  return this.#depositTokensIn(pool, true);
47
37
  }
48
38
  /**
49
- * {@inheritDoc IPoolsService.getDepositTokensOut}
39
+ * @inheritdoc IPoolsService.getDepositTokensOut
50
40
  */
51
41
  getDepositTokensOut(pool, tokenIn) {
52
- const underlying = this.#describeUnderlying(pool);
53
- if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
54
- switch (underlying.contractType) {
55
- case import_base.KYC_UNDERLYING_DEFAULT:
56
- return this.#depositTokensOut(pool, tokenIn, false);
57
- case import_base.KYC_UNDERLYING_ON_DEMAND:
58
- return [];
59
- }
60
- }
61
42
  return this.#depositTokensOut(pool, tokenIn, true);
62
43
  }
63
44
  /**
64
- * {@inheritDoc IPoolsService.getDepositMetadata}
45
+ * @inheritdoc IPoolsService.getDepositMetadata
65
46
  */
66
47
  getDepositMetadata(pool, tokenIn, tokenOut) {
67
- const underlying = this.#describeUnderlying(pool);
68
- if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
69
- switch (underlying.contractType) {
70
- case import_base.KYC_UNDERLYING_DEFAULT: {
71
- return this.#depositMetadata(
72
- "kyc-default",
73
- pool,
74
- tokenIn,
75
- tokenOut,
76
- false
77
- );
78
- }
79
- case import_base.KYC_UNDERLYING_ON_DEMAND:
80
- return {
81
- zapper: void 0,
82
- approveTarget: underlying.liquidityProvider.addr,
83
- permissible: false,
84
- type: "kyc-on-demand"
85
- };
86
- }
87
- }
88
48
  return this.#depositMetadata("classic", pool, tokenIn, tokenOut, true);
89
49
  }
90
50
  /**
91
- * {@inheritDoc IPoolsService.addLiquidity}
51
+ * @inheritdoc IPoolsService.addLiquidity
92
52
  */
93
53
  addLiquidity(props) {
94
54
  const { collateral, meta, permit, referralCode, pool, wallet } = props;
95
- const underlying = this.#describeUnderlying(pool);
96
- if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
97
- if (underlying.contractType === import_base.KYC_UNDERLYING_ON_DEMAND) {
98
- return void 0;
99
- }
100
- }
101
55
  const { zapper } = meta;
102
56
  if (zapper && (0, import_utils.hexEq)(zapper.tokenIn.addr, import_constants.NATIVE_ADDRESS)) {
103
57
  return {
@@ -137,51 +91,22 @@ class PoolService extends import_base.SDKConstruct {
137
91
  }
138
92
  }
139
93
  /**
140
- * {@inheritDoc IPoolsService.getWithdrawalTokensIn}
94
+ * @inheritdoc IPoolsService.getWithdrawalTokensIn
141
95
  */
142
96
  getWithdrawalTokensIn(pool) {
143
- const underlying = this.#describeUnderlying(pool);
144
- if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
145
- switch (underlying.contractType) {
146
- case import_base.KYC_UNDERLYING_DEFAULT:
147
- return this.#withdrawalTokensIn(pool, false);
148
- case import_base.KYC_UNDERLYING_ON_DEMAND:
149
- return [];
150
- }
151
- }
152
97
  return this.#withdrawalTokensIn(pool, true);
153
98
  }
154
99
  /**
155
- * {@inheritDoc IPoolsService.getWithdrawalTokensOut}
100
+ * @inheritdoc IPoolsService.getWithdrawalTokensOut
156
101
  */
157
102
  getWithdrawalTokensOut(pool, tokenIn) {
158
- const underlying = this.#describeUnderlying(pool);
159
- if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
160
- switch (underlying.contractType) {
161
- case import_base.KYC_UNDERLYING_DEFAULT:
162
- return this.#withdrawalTokensOut(pool, tokenIn, false);
163
- case import_base.KYC_UNDERLYING_ON_DEMAND:
164
- return [underlying.asset];
165
- }
166
- }
167
103
  return this.#withdrawalTokensOut(pool, tokenIn, true);
168
104
  }
169
105
  /**
170
- * {@inheritDoc IPoolsService.removeLiquidity}
106
+ * @inheritdoc IPoolsService.removeLiquidity
171
107
  */
172
108
  removeLiquidity(props) {
173
109
  const { pool, amount, meta, wallet, permit } = props;
174
- const underlying = this.#describeUnderlying(pool);
175
- if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
176
- if (underlying.contractType === import_base.KYC_UNDERLYING_ON_DEMAND) {
177
- return {
178
- abi: import_iERC20.ierc20Abi,
179
- functionName: "approve",
180
- args: [underlying.liquidityProvider, 0n],
181
- target: underlying.asset
182
- };
183
- }
184
- }
185
110
  if (meta.zapper) {
186
111
  return permit ? {
187
112
  target: meta.zapper.baseParams.addr,
@@ -210,30 +135,9 @@ class PoolService extends import_base.SDKConstruct {
210
135
  };
211
136
  }
212
137
  /**
213
- * {@inheritDoc IPoolsService.getWithdrawalMetadata}
138
+ * @inheritdoc IPoolsService.getWithdrawalMetadata
214
139
  */
215
140
  getWithdrawalMetadata(pool, tokenIn, tokenOut) {
216
- const underlying = this.#describeUnderlying(pool);
217
- if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
218
- switch (underlying.contractType) {
219
- case import_base.KYC_UNDERLYING_DEFAULT: {
220
- return this.#withdrawalMetadata(
221
- "kyc-default",
222
- pool,
223
- tokenIn,
224
- tokenOut,
225
- false
226
- );
227
- }
228
- case import_base.KYC_UNDERLYING_ON_DEMAND:
229
- return {
230
- zapper: void 0,
231
- approveTarget: void 0,
232
- permissible: false,
233
- type: "kyc-on-demand"
234
- };
235
- }
236
- }
237
141
  return this.#withdrawalMetadata("classic", pool, tokenIn, tokenOut, true);
238
142
  }
239
143
  /**
@@ -393,6 +297,8 @@ class PoolService extends import_base.SDKConstruct {
393
297
  zapper,
394
298
  // Approval target is zapper when routed, otherwise the pool contract.
395
299
  approveTarget: zapper?.baseParams.addr ?? pool.pool.address,
300
+ // TODO: instead of permissible, return permitType depending on tokenIn
301
+ // "none" | "eip2612" | "dai_like";
396
302
  permissible: !!zapper && !(0, import_utils.hexEq)(tokenIn, import_constants.NATIVE_ADDRESS),
397
303
  type
398
304
  };
@@ -420,6 +326,8 @@ class PoolService extends import_base.SDKConstruct {
420
326
  zapper,
421
327
  // Approval target exists only for zapper-based withdrawals.
422
328
  approveTarget: zapper?.baseParams.addr,
329
+ // TODO: instead of permissible, return permitType depending on tokenIn
330
+ // "none" | "eip2612" | "dai_like";
423
331
  permissible: !!zapper,
424
332
  type
425
333
  };
@@ -16,7 +16,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
16
16
  var viem_exports = {};
17
17
  module.exports = __toCommonJS(viem_exports);
18
18
  __reExport(viem_exports, require("./cast.js"), module.exports);
19
- __reExport(viem_exports, require("./executeDelegatedMulticalls.js"), module.exports);
20
19
  __reExport(viem_exports, require("./getLogsPaginated.js"), module.exports);
21
20
  __reExport(viem_exports, require("./getLogsSafe.js"), module.exports);
22
21
  __reExport(viem_exports, require("./sendRawTx.js"), module.exports);
@@ -25,7 +24,6 @@ __reExport(viem_exports, require("./simulateWithPriceUpdates.js"), module.export
25
24
  // Annotate the CommonJS export names for ESM import in node:
26
25
  0 && (module.exports = {
27
26
  ...require("./cast.js"),
28
- ...require("./executeDelegatedMulticalls.js"),
29
27
  ...require("./getLogsPaginated.js"),
30
28
  ...require("./getLogsSafe.js"),
31
29
  ...require("./sendRawTx.js"),
@@ -24,6 +24,8 @@ __export(simulateWithPriceUpdates_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(simulateWithPriceUpdates_exports);
26
26
  var import_viem = require("viem");
27
+ var import_actions = require("viem/actions");
28
+ var import_utils = require("viem/utils");
27
29
  var import_errors = require("../../../abi/errors.js");
28
30
  var import_iUpdatablePriceFeed = require("../../../abi/iUpdatablePriceFeed.js");
29
31
  var import_cast = require("./cast.js");
@@ -53,6 +55,41 @@ async function simulateWithPriceUpdates(client, parameters) {
53
55
  "client chain not configured. multicallAddress is required."
54
56
  );
55
57
  }
58
+ if (priceUpdates.length === 0 && restContracts.length === 1) {
59
+ const contract = restContracts[0];
60
+ const { abi, address, args, functionName } = contract;
61
+ const callData = (0, import_viem.encodeFunctionData)({ abi, args, functionName });
62
+ const request2 = {
63
+ batch: false,
64
+ data: callData,
65
+ to: address,
66
+ blockNumber: rest.blockNumber,
67
+ blockTag: rest.blockTag,
68
+ gas: rest.gas,
69
+ account: rest.account ? (0, import_utils.parseAccount)(rest.account) : client.account,
70
+ value: rest.value
71
+ };
72
+ try {
73
+ const { data } = await (0, import_utils.getAction)(client, import_actions.call, "call")(request2);
74
+ const result = (0, import_viem.decodeFunctionResult)({
75
+ abi,
76
+ args,
77
+ data: data || "0x",
78
+ functionName
79
+ });
80
+ return [
81
+ result
82
+ ];
83
+ } catch (e) {
84
+ throw getSimulateWithPriceUpdatesError(
85
+ e,
86
+ priceUpdates,
87
+ restContracts,
88
+ void 0,
89
+ request2
90
+ );
91
+ }
92
+ }
56
93
  let request;
57
94
  try {
58
95
  const contracts = [
@@ -173,8 +210,8 @@ function getSimulateWithPriceUpdatesError(cause, priceUpdates, calls, results, r
173
210
  return [extractCallError(result), p.pretty, tsValid].filter(Boolean).join(" ");
174
211
  });
175
212
  const prettyCalls = callsResults.map((c, i) => {
176
- const call = calls[i];
177
- return [extractCallError(c), `${call.address}.${call.functionName}`].filter(Boolean).join(" ");
213
+ const call2 = calls[i];
214
+ return [extractCallError(c), `${call2.address}.${call2.functionName}`].filter(Boolean).join(" ");
178
215
  });
179
216
  if (results[0]?.status === "failure") {
180
217
  prettyCalls.unshift(
@@ -6,7 +6,7 @@ import {
6
6
  parseEventLogs
7
7
  } from "viem";
8
8
  import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
9
- import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
9
+ import { iCreditFacadeV310Abi, iPoolV310Abi } from "../abi/310/generated.js";
10
10
  import { ierc20Abi } from "../abi/iERC20.js";
11
11
  import {
12
12
  ADDRESS_0X0,
@@ -15,7 +15,6 @@ import {
15
15
  childLogger,
16
16
  MAX_UINT256,
17
17
  PERCENTAGE_FACTOR,
18
- PoolService,
19
18
  SDKConstruct,
20
19
  sendRawTx
21
20
  } from "../sdk/index.js";
@@ -44,7 +43,6 @@ class AccountOpener extends SDKConstruct {
44
43
  #minDebtMultiplier;
45
44
  #allowMint;
46
45
  #leverageDelta;
47
- #poolService;
48
46
  constructor(service, options_ = {}) {
49
47
  super(service.sdk);
50
48
  const {
@@ -70,7 +68,6 @@ class AccountOpener extends SDKConstruct {
70
68
  this.#poolDepositMultiplier = BigInt(poolDepositMultiplier);
71
69
  this.#minDebtMultiplier = BigInt(minDebtMultiplier);
72
70
  this.#leverageDelta = BigInt(leverageDelta);
73
- this.#poolService = new PoolService(service.sdk);
74
71
  this.#logger?.info(
75
72
  {
76
73
  borrower: privateKeyToAccount(this.borrowerKey).address,
@@ -108,10 +105,6 @@ class AccountOpener extends SDKConstruct {
108
105
  },
109
106
  "opening credit accounts"
110
107
  );
111
- await Promise.all([
112
- this.sdk.tokensMeta.loadTokenData(),
113
- this.sdk.marketRegister.loadZappers()
114
- ]);
115
108
  let deposits = [];
116
109
  if (depositIntoPools) {
117
110
  try {
@@ -463,34 +456,9 @@ class AccountOpener extends SDKConstruct {
463
456
  this.#logger?.debug(
464
457
  `depositor balance in underlying: ${this.sdk.tokensMeta.formatBN(pool.underlying, allowance, { symbol: true })}`
465
458
  );
466
- const tokensOut = this.#poolService.getDepositTokensOut(
467
- address,
468
- underlying
469
- );
470
- this.#logger?.debug(
471
- { tokensOut: tokensOut.map((t) => this.labelAddress(t)) },
472
- "deposit tokens out"
473
- );
474
- if (tokensOut.length === 0) {
475
- throw new Error(`no tokens out found for pool ${poolName}`);
476
- }
477
- const tokenOut = tokensOut[0];
478
- const metadata = this.#poolService.getDepositMetadata(
479
- address,
480
- underlying,
481
- tokenOut
482
- );
483
- this.logger?.debug(
484
- {
485
- underlying: this.labelAddress(underlying),
486
- tokenOut: this.labelAddress(tokenOut),
487
- ...metadata
488
- },
489
- "pool deposit metadata"
490
- );
491
459
  txHash = await this.#anvil.writeContract({
492
460
  account: depositor,
493
- address: metadata.approveTarget,
461
+ address: underlying,
494
462
  abi: ierc20Abi,
495
463
  functionName: "approve",
496
464
  args: [address, allowance],
@@ -507,21 +475,12 @@ class AccountOpener extends SDKConstruct {
507
475
  this.#logger?.debug(
508
476
  `depositor approved underlying for pool ${poolName}: ${txHash}`
509
477
  );
510
- const depositCall = this.#poolService.addLiquidity({
511
- collateral: { token: underlying, balance: amount },
512
- pool: address,
513
- wallet: depositor.address,
514
- meta: metadata
515
- });
516
- if (!depositCall) {
517
- throw new Error(`no deposit call could be created for ${poolName}`);
518
- }
519
478
  txHash = await this.#anvil.writeContract({
520
479
  account: depositor,
521
- address: depositCall.target,
522
- abi: depositCall.abi,
523
- functionName: depositCall.functionName,
524
- args: depositCall.args,
480
+ address,
481
+ abi: iPoolV310Abi,
482
+ functionName: "deposit",
483
+ args: [amount, depositor.address],
525
484
  chain: this.#anvil.chain
526
485
  });
527
486
  receipt = await this.#anvil.waitForTransactionReceipt({ hash: txHash });
@@ -21,7 +21,9 @@ const RANGE_ERROR_PATTERNS = [
21
21
  /eth_getLogs is limited to/i,
22
22
  /eth_getLogs requests with up to/i,
23
23
  /range is too large/i,
24
- /exceeded max allowed range/i
24
+ /exceeded max allowed range/i,
25
+ // Encountered on DRPC: "query exceeds max results 20000, retry with the range …"
26
+ /exceeds max results/i
25
27
  ];
26
28
  function isRangeError(error) {
27
29
  const msg = errorMessage(error);
@@ -29,10 +31,17 @@ function isRangeError(error) {
29
31
  }
30
32
  const GENERIC_BLOCKS_RE = /(\d+)\s*block/i;
31
33
  const ALCHEMY_RANGE_RE = /this block range should work: \[(0x[0-9a-fA-F]+),\s*(0x[0-9a-fA-F]+)\]/;
34
+ const DRPC_RANGE_RE = /retry with the range (\d+)-(\d+)/;
32
35
  function parsePageSizeHint(error) {
33
36
  const alchemy = tryAlchemyHint(error);
34
37
  if (alchemy != null) return alchemy;
35
38
  const msg = errorMessage(error);
39
+ const drpc = msg.match(DRPC_RANGE_RE);
40
+ if (drpc) {
41
+ const from = Number(drpc[1]);
42
+ const to = Number(drpc[2]);
43
+ return to - from + 1;
44
+ }
36
45
  const m = msg.match(GENERIC_BLOCKS_RE);
37
46
  return m ? Number(m[1]) : null;
38
47
  }
@@ -48,7 +48,7 @@ const adapterActionSignatures = {
48
48
  310: "function setPairStatusBatch((address,address,address,uint8)[])",
49
49
  311: "function setPairStatusBatch((address,address,address,uint8,uint8)[])"
50
50
  },
51
- [AdapterType.TRADERJOE_ROUTER]: {
51
+ [AdapterType.TRADER_JOE_ROUTER]: {
52
52
  310: "function setPoolStatusBatch((address,address,uint256,uint8,bool)[])"
53
53
  },
54
54
  [AdapterType.UNISWAP_V2_ROUTER]: {
@@ -63,7 +63,7 @@ const adapterConstructorAbi = {
63
63
  [AdapterType.DAI_USDS_EXCHANGE]: {
64
64
  310: BASIC_ADAPTER_ABI
65
65
  },
66
- [AdapterType.TRADERJOE_ROUTER]: {
66
+ [AdapterType.TRADER_JOE_ROUTER]: {
67
67
  310: BASIC_ADAPTER_ABI
68
68
  },
69
69
  [AdapterType.UNISWAP_V2_ROUTER]: {
@@ -109,7 +109,7 @@ function createAdapter(options, data, strict) {
109
109
  return new PendleRouterAdapterContract(options, data);
110
110
  case "ADAPTER::STAKING_REWARDS":
111
111
  return new StakingRewardsAdapterContract(options, data);
112
- case "ADAPTER::TRADERJOE_ROUTER":
112
+ case "ADAPTER::TRADER_JOE_ROUTER":
113
113
  return new TraderJoeRouterAdapterContract(options, data);
114
114
  case "ADAPTER::UNISWAP_V2_ROUTER":
115
115
  return new UniswapV2AdapterContract(options, data);
@@ -36,7 +36,7 @@ var AdapterType = /* @__PURE__ */ ((AdapterType2) => {
36
36
  AdapterType2["MIDAS_REDEMPTION_VAULT"] = "MIDAS_REDEMPTION_VAULT";
37
37
  AdapterType2["PENDLE_ROUTER"] = "PENDLE_ROUTER";
38
38
  AdapterType2["STAKING_REWARDS"] = "STAKING_REWARDS";
39
- AdapterType2["TRADERJOE_ROUTER"] = "TRADERJOE_ROUTER";
39
+ AdapterType2["TRADER_JOE_ROUTER"] = "TRADER_JOE_ROUTER";
40
40
  AdapterType2["UNISWAP_V2_ROUTER"] = "UNISWAP_V2_ROUTER";
41
41
  AdapterType2["UNISWAP_V3_ROUTER"] = "UNISWAP_V3_ROUTER";
42
42
  AdapterType2["UNISWAP_V4_GATEWAY"] = "UNISWAP_V4_GATEWAY";