@gearbox-protocol/sdk 12.4.0-next.1 → 12.4.0

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 (94) hide show
  1. package/dist/cjs/abi/errors.js +10 -1
  2. package/dist/cjs/dev/AccountOpener.js +2 -1
  3. package/dist/cjs/dev/RevolverTransport.js +4 -6
  4. package/dist/cjs/dev/ltUtils.js +2 -1
  5. package/dist/cjs/dev/migrateFaucet.js +2 -1
  6. package/dist/cjs/dev/providers.js +6 -2
  7. package/dist/cjs/dev/transports.js +3 -3
  8. package/dist/cjs/permissionless/bindings/compressors/token-compressor.js +7 -4
  9. package/dist/cjs/permissionless/bindings/governance/governor.js +3 -4
  10. package/dist/cjs/permissionless/bindings/market-configurator.js +4 -2
  11. package/dist/cjs/permissionless/bindings/price-feed-store.js +2 -1
  12. package/dist/cjs/permissionless/bindings/treasury-splitter.js +12 -1
  13. package/dist/cjs/permissionless/utils/format.js +0 -8
  14. package/dist/cjs/plugins/accounts-counter/AccountsCounterPlugin.js +2 -1
  15. package/dist/cjs/plugins/bots/BotsPlugin.js +4 -2
  16. package/dist/cjs/plugins/degen-distributors/DegenDistributorsPlugin.js +13 -7
  17. package/dist/cjs/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +2 -1
  18. package/dist/cjs/plugins/pools-history/Pools7DAgoPlugin.js +2 -1
  19. package/dist/cjs/plugins/zappers/ZappersPlugin.js +2 -1
  20. package/dist/cjs/sdk/GearboxSDK.js +9 -5
  21. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +71 -38
  22. package/dist/cjs/sdk/base/TokensMeta.js +2 -1
  23. package/dist/cjs/sdk/core/address-provider/createAddressProvider.js +11 -5
  24. package/dist/cjs/sdk/gauges/GaugeStakingService.js +2 -1
  25. package/dist/cjs/sdk/index.js +2 -0
  26. package/dist/cjs/sdk/market/MarketConfiguratorContract.js +15 -0
  27. package/dist/cjs/sdk/market/credit/CreditFacadeV300Contract.js +1 -1
  28. package/dist/cjs/sdk/market/credit/CreditFacadeV310Contract.js +1 -1
  29. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +6 -0
  30. package/dist/cjs/sdk/pools/AbstractPoolService.js +137 -0
  31. package/dist/cjs/sdk/pools/PoolServiceV300.js +30 -0
  32. package/dist/cjs/sdk/pools/PoolServiceV310.js +30 -0
  33. package/dist/cjs/sdk/pools/createPoolService.js +39 -0
  34. package/dist/cjs/sdk/pools/index.js +26 -0
  35. package/dist/cjs/sdk/pools/types.js +16 -0
  36. package/dist/cjs/sdk/sdk-legacy/core/endpoint.js +3 -9
  37. package/dist/cjs/sdk/sdk-legacy/gearboxRewards/api.js +2 -1
  38. package/dist/cjs/sdk/utils/formatter.js +8 -0
  39. package/dist/esm/abi/errors.js +9 -1
  40. package/dist/esm/dev/AccountOpener.js +2 -1
  41. package/dist/esm/dev/RevolverTransport.js +5 -7
  42. package/dist/esm/dev/ltUtils.js +2 -1
  43. package/dist/esm/dev/migrateFaucet.js +2 -1
  44. package/dist/esm/dev/providers.js +4 -1
  45. package/dist/esm/dev/transports.js +2 -2
  46. package/dist/esm/permissionless/bindings/compressors/token-compressor.js +7 -4
  47. package/dist/esm/permissionless/bindings/governance/governor.js +5 -2
  48. package/dist/esm/permissionless/bindings/market-configurator.js +4 -2
  49. package/dist/esm/permissionless/bindings/price-feed-store.js +2 -1
  50. package/dist/esm/permissionless/bindings/treasury-splitter.js +13 -2
  51. package/dist/esm/permissionless/utils/format.js +0 -7
  52. package/dist/esm/plugins/accounts-counter/AccountsCounterPlugin.js +2 -1
  53. package/dist/esm/plugins/bots/BotsPlugin.js +4 -2
  54. package/dist/esm/plugins/degen-distributors/DegenDistributorsPlugin.js +13 -7
  55. package/dist/esm/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +2 -1
  56. package/dist/esm/plugins/pools-history/Pools7DAgoPlugin.js +2 -1
  57. package/dist/esm/plugins/zappers/ZappersPlugin.js +2 -1
  58. package/dist/esm/sdk/GearboxSDK.js +9 -5
  59. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +71 -38
  60. package/dist/esm/sdk/base/TokensMeta.js +2 -1
  61. package/dist/esm/sdk/core/address-provider/createAddressProvider.js +16 -6
  62. package/dist/esm/sdk/gauges/GaugeStakingService.js +2 -1
  63. package/dist/esm/sdk/index.js +1 -0
  64. package/dist/esm/sdk/market/MarketConfiguratorContract.js +15 -0
  65. package/dist/esm/sdk/market/credit/CreditFacadeV300Contract.js +6 -2
  66. package/dist/esm/sdk/market/credit/CreditFacadeV310Contract.js +6 -2
  67. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +6 -0
  68. package/dist/esm/sdk/pools/AbstractPoolService.js +113 -0
  69. package/dist/esm/sdk/pools/PoolServiceV300.js +6 -0
  70. package/dist/esm/sdk/pools/PoolServiceV310.js +6 -0
  71. package/dist/esm/sdk/pools/createPoolService.js +15 -0
  72. package/dist/esm/sdk/pools/index.js +3 -0
  73. package/dist/esm/sdk/pools/types.js +0 -0
  74. package/dist/esm/sdk/sdk-legacy/core/endpoint.js +3 -9
  75. package/dist/esm/sdk/sdk-legacy/gearboxRewards/api.js +2 -1
  76. package/dist/esm/sdk/utils/formatter.js +7 -0
  77. package/dist/types/abi/errors.d.ts +33 -0
  78. package/dist/types/dev/RevolverTransport.d.ts +2 -20
  79. package/dist/types/dev/providers.d.ts +8 -1
  80. package/dist/types/dev/transports.d.ts +1 -1
  81. package/dist/types/permissionless/utils/format.d.ts +0 -1
  82. package/dist/types/sdk/GearboxSDK.d.ts +1 -1
  83. package/dist/types/sdk/index.d.ts +1 -0
  84. package/dist/types/sdk/market/MarketConfiguratorContract.d.ts +9 -0
  85. package/dist/types/sdk/pools/AbstractPoolService.d.ts +9 -0
  86. package/dist/types/sdk/pools/PoolServiceV300.d.ts +4 -0
  87. package/dist/types/sdk/pools/PoolServiceV310.d.ts +4 -0
  88. package/dist/types/sdk/pools/createPoolService.d.ts +8 -0
  89. package/dist/types/sdk/pools/index.d.ts +3 -0
  90. package/dist/types/sdk/pools/types.d.ts +92 -0
  91. package/dist/types/sdk/sdk-legacy/core/endpoint.d.ts +1 -3
  92. package/dist/types/sdk/types/state-human.d.ts +1 -1
  93. package/dist/types/sdk/utils/formatter.d.ts +1 -0
  94. package/package.json +6 -6
@@ -9,12 +9,6 @@ function formatBytecodeVersion(version) {
9
9
  const patch = version % 10;
10
10
  return `v${major}.${minor}.${patch}`;
11
11
  }
12
- function formatTimestamp(timestamp) {
13
- return new Date(timestamp * 1e3).toLocaleString("en-GB", {
14
- dateStyle: "short",
15
- timeStyle: "short"
16
- });
17
- }
18
12
  function shortenHash(hash, chars = 4) {
19
13
  if (!hash) return "";
20
14
  const start = hash.slice(0, chars + 2);
@@ -61,7 +55,6 @@ export {
61
55
  deepJsonParse,
62
56
  formatBytecodeSize,
63
57
  formatBytecodeVersion,
64
- formatTimestamp,
65
58
  shortenHash,
66
59
  significantTrunc
67
60
  };
@@ -69,7 +69,8 @@ class AccountsCounterPlugin extends BasePlugin {
69
69
  }
70
70
  ]
71
71
  ),
72
- allowFailure: false
72
+ allowFailure: false,
73
+ batchSize: 0
73
74
  });
74
75
  this.#accounts = new AddressMap();
75
76
  for (let i = 0; i < cms.length; i++) {
@@ -62,7 +62,8 @@ class BotsPlugin extends BasePlugin {
62
62
  })
63
63
  ),
64
64
  allowFailure: true,
65
- blockNumber: this.sdk.currentBlock
65
+ blockNumber: this.sdk.currentBlock,
66
+ batchSize: 0
66
67
  });
67
68
  const expectedBots = new AddressMap();
68
69
  for (let i = 0; i < configs.length; i++) {
@@ -90,7 +91,8 @@ class BotsPlugin extends BasePlugin {
90
91
  })
91
92
  ),
92
93
  allowFailure: true,
93
- blockNumber: this.sdk.currentBlock
94
+ blockNumber: this.sdk.currentBlock,
95
+ batchSize: 0
94
96
  });
95
97
  for (let i = 0; i < botAddrs.length; i++) {
96
98
  const serialized = serializedBots[i];
@@ -1,4 +1,5 @@
1
1
  import { AddressMap, BasePlugin } from "../../sdk/index.js";
2
+ import { MarketConfiguratorContract } from "../../sdk/market/MarketConfiguratorContract.js";
2
3
  const MAP_LABEL = "degenDistributors";
3
4
  class DegenDistributorsPlugin extends BasePlugin {
4
5
  #distributors;
@@ -16,12 +17,15 @@ class DegenDistributorsPlugin extends BasePlugin {
16
17
  this.sdk.logger?.debug(
17
18
  `loading degen distributors for ${this.sdk.networkType}`
18
19
  );
19
- const distributors = await Promise.allSettled(
20
- configurators.map((cfg) => cfg.getPeripheryContract("DEGEN_DISTRIBUTOR"))
20
+ const distributors = await MarketConfiguratorContract.getPeripheryContractBatch(
21
+ Object.values(configurators),
22
+ this.sdk.client,
23
+ "DEGEN_DISTRIBUTOR"
21
24
  );
22
25
  const distributorByConfigurator = configurators.reduce((acc, cfg, index) => {
23
26
  const cfgLC = cfg.address.toLowerCase();
24
- acc[cfgLC] = distributors[index];
27
+ const distributor = distributors[index];
28
+ acc[cfgLC] = distributor;
25
29
  return acc;
26
30
  }, {});
27
31
  this.#distributors = new AddressMap(void 0, MAP_LABEL);
@@ -30,11 +34,13 @@ class DegenDistributorsPlugin extends BasePlugin {
30
34
  const cfg = m.configurator.address;
31
35
  const cfgLC = cfg.toLowerCase();
32
36
  const r = distributorByConfigurator?.[cfgLC];
33
- if (r.status === "fulfilled") {
34
- this.#distributors?.upsert(pool, r.value);
37
+ if (r.status === "success" && r.result.length > 0) {
38
+ this.#distributors?.upsert(pool, r.result[0]);
35
39
  } else {
36
- this.sdk.logger?.error(
37
- `failed to load degen distributor for market configurator ${this.labelAddress(cfg)} and pool ${this.labelAddress(pool)}: ${r.reason}`
40
+ this.sdk.logger?.warn(
41
+ `failed to load degen distributor for market configurator ${this.labelAddress(
42
+ cfg
43
+ )} and pool ${this.labelAddress(pool)}: ${r.error}`
38
44
  );
39
45
  }
40
46
  });
@@ -25,7 +25,8 @@ class DelayedWithdrawalPlugin extends BasePlugin {
25
25
  args: [cm.creditManager.address]
26
26
  })
27
27
  ) : [],
28
- allowFailure: true
28
+ allowFailure: true,
29
+ batchSize: 0
29
30
  });
30
31
  this.#withdrawableAssets = new AddressMap(void 0, MAP_LABEL);
31
32
  resp.forEach((r, index) => {
@@ -33,7 +33,8 @@ class Pools7DAgoPlugin extends BasePlugin {
33
33
  args: [m.pool.pool.address]
34
34
  })
35
35
  ),
36
- blockNumber: BigIntMath.max(0n, targetBlock)
36
+ blockNumber: BigIntMath.max(0n, targetBlock),
37
+ batchSize: 0
37
38
  });
38
39
  this.#pools7DAgo = new AddressMap(void 0, MAP_LABEL);
39
40
  resp.forEach((r, index) => {
@@ -34,7 +34,8 @@ class ZappersPlugin extends BasePlugin {
34
34
  args: [m.configurator.address, m.pool.pool.address]
35
35
  })
36
36
  ),
37
- allowFailure: true
37
+ allowFailure: true,
38
+ batchSize: 0
38
39
  });
39
40
  this.#zappers = new AddressMap(void 0, "zappers");
40
41
  for (let i = 0; i < resp.length; i++) {
@@ -45,7 +45,7 @@ function createClient(opts, network) {
45
45
  } else {
46
46
  const rpcs = opts.rpcURLs.map(
47
47
  (url) => http(url, {
48
- ...opts.httpClientOptions,
48
+ ...opts.httpTransportOptions,
49
49
  timeout: opts.timeout,
50
50
  retryCount: opts.retryCount
51
51
  })
@@ -61,11 +61,15 @@ function createClient(opts, network) {
61
61
  async function attachClient(options, network) {
62
62
  let { chainId, networkType } = network;
63
63
  const attachClient2 = createClient(options);
64
- if (!networkType) {
64
+ if (networkType) {
65
+ if (!chainId) {
66
+ chainId = getChain(networkType).id;
67
+ }
68
+ } else {
65
69
  networkType = await detectNetwork(attachClient2);
66
- }
67
- if (!chainId) {
68
- chainId = await attachClient2.getChainId();
70
+ if (!chainId) {
71
+ chainId = await attachClient2.getChainId();
72
+ }
69
73
  }
70
74
  return createClient(options, { networkType, chainId });
71
75
  }
@@ -202,9 +202,9 @@ class AbstractCreditAccountService extends SDKConstruct {
202
202
  * @returns call result of getConnectedBots for each credit account
203
203
  */
204
204
  async getConnectedBots(accountsToCheck, legacyMigrationBot, additionalBots) {
205
- const [resp, migration, additional] = await Promise.all([
206
- this.client.multicall({
207
- contracts: accountsToCheck.map((o) => {
205
+ const allResp = await this.client.multicall({
206
+ contracts: [
207
+ ...accountsToCheck.map((o) => {
208
208
  const pool = this.sdk.marketRegister.findByCreditManager(
209
209
  o.creditManager
210
210
  );
@@ -215,32 +215,72 @@ class AbstractCreditAccountService extends SDKConstruct {
215
215
  args: [pool.configurator.address, o.creditAccount]
216
216
  };
217
217
  }),
218
- allowFailure: true
219
- }),
220
- this.getActiveMigrationBots(accountsToCheck, legacyMigrationBot),
221
- this.getActiveBots(accountsToCheck, additionalBots)
222
- ]);
223
- return {
224
- legacy: resp,
225
- additionalBots: additional,
226
- legacyMigration: migration
227
- };
228
- }
229
- async getActiveBots(accountsToCheck, bots) {
230
- const result = await this.client.multicall({
231
- contracts: accountsToCheck.flatMap((ca) => {
232
- const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
233
- return bots.map((bot) => {
218
+ ...legacyMigrationBot ? accountsToCheck.map((ca) => {
219
+ const cm = this.sdk.marketRegister.findCreditManager(
220
+ ca.creditManager
221
+ );
234
222
  return {
235
223
  abi: isV300(cm.creditFacade.version) ? iBotListV300Abi : iBotListV310Abi,
236
224
  address: cm.creditFacade.botList,
237
225
  functionName: "getBotStatus",
238
- args: isV300(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
226
+ args: isV300(cm.creditFacade.version) ? [legacyMigrationBot, ca.creditManager, ca.creditAccount] : [legacyMigrationBot, ca.creditAccount]
239
227
  };
240
- });
241
- }),
242
- allowFailure: true
228
+ }) : [],
229
+ ...accountsToCheck.flatMap((ca) => {
230
+ const cm = this.sdk.marketRegister.findCreditManager(
231
+ ca.creditManager
232
+ );
233
+ return additionalBots.map((bot) => {
234
+ return {
235
+ abi: isV300(cm.creditFacade.version) ? iBotListV300Abi : iBotListV310Abi,
236
+ address: cm.creditFacade.botList,
237
+ functionName: "getBotStatus",
238
+ args: isV300(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
239
+ };
240
+ });
241
+ })
242
+ ],
243
+ allowFailure: true,
244
+ batchSize: 0
243
245
  });
246
+ const legacyStart = 0;
247
+ const legacyEnd = accountsToCheck.length;
248
+ const legacy = allResp.slice(
249
+ legacyStart,
250
+ legacyEnd
251
+ );
252
+ const migrationStart = legacyEnd;
253
+ const migrationEnd = legacyMigrationBot ? migrationStart + accountsToCheck.length : migrationStart;
254
+ const migrationResp = allResp.slice(
255
+ migrationStart,
256
+ migrationEnd
257
+ );
258
+ const additionalStart = migrationEnd;
259
+ const additionalResp = allResp.slice(
260
+ additionalStart
261
+ );
262
+ return {
263
+ legacy,
264
+ additionalBots: this.getActiveBots(
265
+ accountsToCheck,
266
+ additionalBots,
267
+ additionalResp
268
+ ),
269
+ legacyMigration: this.getActiveMigrationBots(
270
+ accountsToCheck,
271
+ legacyMigrationBot,
272
+ migrationResp
273
+ )
274
+ };
275
+ }
276
+ getActiveBots(accountsToCheck, bots, result) {
277
+ if (result.length !== bots.length * accountsToCheck.length) {
278
+ console.error(
279
+ "result length mismatch",
280
+ result.length,
281
+ bots.length * accountsToCheck.length
282
+ );
283
+ }
244
284
  const botsByCAIndex = accountsToCheck.reduce((acc, _, index) => {
245
285
  const r = result.slice(index * bots.length, (index + 1) * bots.length);
246
286
  acc.push({
@@ -250,22 +290,15 @@ class AbstractCreditAccountService extends SDKConstruct {
250
290
  }, []);
251
291
  return botsByCAIndex;
252
292
  }
253
- async getActiveMigrationBots(accountsToCheck, bot) {
293
+ getActiveMigrationBots(accountsToCheck, bot, result) {
254
294
  if (bot) {
255
- const result = await this.client.multicall({
256
- contracts: accountsToCheck.map((ca) => {
257
- const cm = this.sdk.marketRegister.findCreditManager(
258
- ca.creditManager
259
- );
260
- return {
261
- abi: isV300(cm.creditFacade.version) ? iBotListV300Abi : iBotListV310Abi,
262
- address: cm.creditFacade.botList,
263
- functionName: "getBotStatus",
264
- args: isV300(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
265
- };
266
- }),
267
- allowFailure: true
268
- });
295
+ if (result.length !== accountsToCheck.length) {
296
+ console.error(
297
+ "result length mismatch for migration bots",
298
+ result.length,
299
+ accountsToCheck.length
300
+ );
301
+ }
269
302
  return { result, botAddress: bot };
270
303
  }
271
304
  return void 0;
@@ -69,7 +69,8 @@ class TokensMeta extends AddressMap {
69
69
  functionName: "contractType"
70
70
  })
71
71
  ),
72
- allowFailure: true
72
+ allowFailure: true,
73
+ batchSize: 0
73
74
  });
74
75
  for (let i = 0; i < resp.length; i++) {
75
76
  if (resp[i].status === "success") {
@@ -1,13 +1,23 @@
1
1
  import { iVersionAbi } from "../../../abi/iVersion.js";
2
- import { isV300, isV310 } from "../../constants/index.js";
2
+ import {
3
+ ADDRESS_PROVIDER_V310,
4
+ isV300,
5
+ isV310
6
+ } from "../../constants/index.js";
7
+ import { hexEq } from "../../utils/hex.js";
3
8
  import { AddressProviderV300Contract } from "./AddressProviderV300Contract.js";
4
9
  import { AddressProviderV310Contract } from "./AddressProviderV310Contract.js";
5
10
  async function createAddressProvider(sdk, address) {
6
- const v = await sdk.client.readContract({
7
- address,
8
- abi: iVersionAbi,
9
- functionName: "version"
10
- });
11
+ let v;
12
+ if (hexEq(address, ADDRESS_PROVIDER_V310)) {
13
+ v = 310n;
14
+ } else {
15
+ v = await sdk.client.readContract({
16
+ address,
17
+ abi: iVersionAbi,
18
+ functionName: "version"
19
+ });
20
+ }
11
21
  return newAddressProvider(sdk, address, Number(v));
12
22
  }
13
23
  function hydrateAddressProvider(sdk, state) {
@@ -57,7 +57,8 @@ class GaugeStakingService extends SDKConstruct {
57
57
  functionName: "getCurrentEpoch",
58
58
  args: []
59
59
  }
60
- ]
60
+ ],
61
+ batchSize: 0
61
62
  });
62
63
  return {
63
64
  availableBalance,
@@ -10,6 +10,7 @@ export * from "./market/index.js";
10
10
  export * from "./options.js";
11
11
  export * from "./plugins/index.js";
12
12
  export * from "./poolMigration/index.js";
13
+ export * from "./pools/index.js";
13
14
  export * from "./router/index.js";
14
15
  export * from "./sdk-gov-legacy/index.js";
15
16
  export * from "./sdk-legacy/index.js";
@@ -26,6 +26,21 @@ class MarketConfiguratorContract extends BaseContract {
26
26
  `Market configurator ${this.#curatorName}`
27
27
  );
28
28
  }
29
+ static async getPeripheryContractBatch(configurators, client, contract) {
30
+ const resp = await client.multicall({
31
+ allowFailure: true,
32
+ contracts: configurators.map(
33
+ (cfg) => ({
34
+ address: cfg.address,
35
+ abi: cfg.abi,
36
+ functionName: "getPeripheryContracts",
37
+ args: [stringToHex(contract, { size: 32 })]
38
+ })
39
+ ),
40
+ batchSize: 0
41
+ });
42
+ return resp;
43
+ }
29
44
  async getPeripheryContract(contract) {
30
45
  const resp = await this.client.readContract({
31
46
  address: this.address,
@@ -5,7 +5,11 @@ import {
5
5
  } from "../../../abi/v300.js";
6
6
  import { BaseContract } from "../../base/index.js";
7
7
  import { ADDRESS_0X0 } from "../../constants/index.js";
8
- import { fmtBinaryMask, formatBNvalue } from "../../utils/index.js";
8
+ import {
9
+ fmtBinaryMask,
10
+ formatBNvalue,
11
+ formatTimestamp
12
+ } from "../../utils/index.js";
9
13
  const abi = [
10
14
  ...iCreditFacadeV300Abi,
11
15
  ...iCreditFacadeV300MulticallAbi,
@@ -30,7 +34,7 @@ class CreditFacadeV300Contract extends BaseContract {
30
34
  expirable: this.expirable,
31
35
  isDegenMode: this.degenNFT !== ADDRESS_0X0,
32
36
  degenNFT: this.labelAddress(this.degenNFT),
33
- expirationDate: this.expirationDate,
37
+ expirationDate: formatTimestamp(this.expirationDate),
34
38
  maxDebtPerBlockMultiplier: this.maxDebtPerBlockMultiplier,
35
39
  botList: this.labelAddress(this.botList),
36
40
  minDebt: formatBNvalue(this.minDebt, decimals),
@@ -5,7 +5,11 @@ import {
5
5
  import { iPausableAbi } from "../../../abi/iPausable.js";
6
6
  import { BaseContract } from "../../base/index.js";
7
7
  import { ADDRESS_0X0 } from "../../constants/index.js";
8
- import { fmtBinaryMask, formatBNvalue } from "../../utils/index.js";
8
+ import {
9
+ fmtBinaryMask,
10
+ formatBNvalue,
11
+ formatTimestamp
12
+ } from "../../utils/index.js";
9
13
  const abi = [
10
14
  ...iCreditFacadeV310Abi,
11
15
  ...iCreditFacadeMulticallV310Abi,
@@ -30,7 +34,7 @@ class CreditFacadeV310Contract extends BaseContract {
30
34
  expirable: this.expirable,
31
35
  isDegenMode: this.degenNFT !== ADDRESS_0X0,
32
36
  degenNFT: this.labelAddress(this.degenNFT),
33
- expirationDate: this.expirationDate,
37
+ expirationDate: formatTimestamp(this.expirationDate),
34
38
  maxDebtPerBlockMultiplier: this.maxDebtPerBlockMultiplier,
35
39
  botList: this.labelAddress(this.botList),
36
40
  minDebt: formatBNvalue(this.minDebt, decimals),
@@ -113,6 +113,9 @@ class PriceOracleBaseContract extends BaseContract {
113
113
  * @param reserve use reserve price feed instead of main
114
114
  */
115
115
  convertToUSD(from, amount, reserve = false) {
116
+ if (amount === 0n) {
117
+ return 0n;
118
+ }
116
119
  const price = reserve ? this.reservePrice(from) : this.mainPrice(from);
117
120
  const scale = 10n ** BigInt(this.tokensMeta.decimals(from));
118
121
  return amount * price / scale;
@@ -124,6 +127,9 @@ class PriceOracleBaseContract extends BaseContract {
124
127
  * @param reserve use reserve price feed instead of main
125
128
  */
126
129
  convertFromUSD(to, amount, reserve = false) {
130
+ if (amount === 0n) {
131
+ return 0n;
132
+ }
127
133
  const price = reserve ? this.reservePrice(to) : this.mainPrice(to);
128
134
  const scale = 10n ** BigInt(this.tokensMeta.decimals(to));
129
135
  return amount * scale / price;
@@ -0,0 +1,113 @@
1
+ import { ierc20ZapperDepositsAbi } from "../../abi/iERC20ZapperDeposits.js";
2
+ import { iethZapperDepositsAbi } from "../../abi/iETHZapperDeposits.js";
3
+ import { iZapperAbi } from "../../abi/iZapper.js";
4
+ import { iPoolV300Abi } from "../../abi/v300.js";
5
+ import { SDKConstruct } from "../base/index.js";
6
+ class AbstractPoolService extends SDKConstruct {
7
+ #version;
8
+ constructor(sdk, version) {
9
+ super(sdk);
10
+ this.#version = version;
11
+ this.logger?.debug(`Created PoolService with version: ${this.#version}`);
12
+ }
13
+ addLiquidity({
14
+ collateral,
15
+ pool,
16
+ account,
17
+ zapper,
18
+ permit,
19
+ nativeTokenAddress,
20
+ referralCode = 0n,
21
+ migrate
22
+ }) {
23
+ if (zapper?.tokenIn === nativeTokenAddress) {
24
+ return [
25
+ {
26
+ target: zapper.zapper,
27
+ abi: iethZapperDepositsAbi,
28
+ functionName: "depositWithReferral",
29
+ args: [account, referralCode],
30
+ value: collateral.balance
31
+ }
32
+ ];
33
+ } else if (zapper) {
34
+ return permit ? [
35
+ {
36
+ target: zapper.zapper,
37
+ abi: ierc20ZapperDepositsAbi,
38
+ functionName: "depositWithReferralAndPermit",
39
+ args: [
40
+ collateral.balance,
41
+ account,
42
+ referralCode,
43
+ permit.deadline,
44
+ permit.v,
45
+ permit.r,
46
+ permit.s
47
+ ]
48
+ }
49
+ ] : [
50
+ {
51
+ target: zapper.zapper,
52
+ abi: ierc20ZapperDepositsAbi,
53
+ functionName: "depositWithReferral",
54
+ args: [collateral.balance, account, referralCode]
55
+ }
56
+ ];
57
+ } else {
58
+ if (migrate) throw Error("No zapper for migration");
59
+ return [
60
+ {
61
+ target: pool,
62
+ abi: iPoolV300Abi,
63
+ functionName: "depositWithReferral",
64
+ args: [collateral.balance, account, referralCode]
65
+ }
66
+ ];
67
+ }
68
+ }
69
+ removeLiquidity({
70
+ pool,
71
+ amount,
72
+ account,
73
+ zapper,
74
+ permit
75
+ }) {
76
+ if (zapper) {
77
+ return permit ? [
78
+ {
79
+ target: zapper.zapper,
80
+ abi: iZapperAbi,
81
+ functionName: "redeemWithPermit",
82
+ args: [
83
+ amount,
84
+ account,
85
+ permit.deadline,
86
+ permit.v,
87
+ permit.r,
88
+ permit.s
89
+ ]
90
+ }
91
+ ] : [
92
+ {
93
+ target: zapper.zapper,
94
+ abi: iZapperAbi,
95
+ functionName: "redeem",
96
+ args: [amount, account]
97
+ }
98
+ ];
99
+ } else {
100
+ return [
101
+ {
102
+ target: pool,
103
+ abi: iPoolV300Abi,
104
+ functionName: "redeem",
105
+ args: [amount, account, account]
106
+ }
107
+ ];
108
+ }
109
+ }
110
+ }
111
+ export {
112
+ AbstractPoolService
113
+ };
@@ -0,0 +1,6 @@
1
+ import { AbstractPoolService } from "./AbstractPoolService.js";
2
+ class PoolServiceV300 extends AbstractPoolService {
3
+ }
4
+ export {
5
+ PoolServiceV300
6
+ };
@@ -0,0 +1,6 @@
1
+ import { AbstractPoolService } from "./AbstractPoolService.js";
2
+ class PoolServiceV310 extends AbstractPoolService {
3
+ }
4
+ export {
5
+ PoolServiceV310
6
+ };
@@ -0,0 +1,15 @@
1
+ import { isV300, isV310 } from "../constants/index.js";
2
+ import { PoolServiceV300 } from "./PoolServiceV300.js";
3
+ import { PoolServiceV310 } from "./PoolServiceV310.js";
4
+ function createPoolService(sdk, version) {
5
+ if (isV300(version)) {
6
+ return new PoolServiceV300(sdk, version);
7
+ }
8
+ if (isV310(version)) {
9
+ return new PoolServiceV310(sdk, version);
10
+ }
11
+ throw new Error(`Unsupported Pool Service version ${version}`);
12
+ }
13
+ export {
14
+ createPoolService
15
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./AbstractPoolService.js";
2
+ export * from "./createPoolService.js";
3
+ export * from "./types.js";
File without changes
@@ -85,15 +85,9 @@ class GearboxBackendApi {
85
85
  return `${LEADERBOARD_APIS[chainId]}${url}`;
86
86
  };
87
87
  static getReferralUrl = () => REFERRAL_API;
88
- static apyServerAllRewards = (chainId) => URLApi.getRelativeUrl("https://apy-server.fly.dev/api/rewards/tokens/all", {
89
- params: { chain_id: chainId }
90
- });
91
- static apyServerGearAPY = (chainId) => URLApi.getRelativeUrl("https://apy-server.fly.dev/api/rewards/gear-apy", {
92
- params: { chain_id: chainId }
93
- });
94
- static apyServerAllPoolRewards = (chainId) => URLApi.getRelativeUrl("https://apy-server.fly.dev/api/rewards/pools/all", {
95
- params: { chain_id: chainId }
96
- });
88
+ static apyAllRewards = () => URLApi.getRelativeUrl(
89
+ "https://state-cache.gearbox.foundation/apy-server/latest.json"
90
+ );
97
91
  }
98
92
  class URLApi {
99
93
  static getRelativeUrl = (url, options) => {
@@ -95,7 +95,8 @@ class GearboxRewardsApi {
95
95
  const [response] = await Promise.allSettled([
96
96
  provider.multicall({
97
97
  allowFailure: false,
98
- contracts: [...farmInfoCalls, ...rewardTokenCalls, ...farmedCalls]
98
+ contracts: [...farmInfoCalls, ...rewardTokenCalls, ...farmedCalls],
99
+ batchSize: 0
99
100
  })
100
101
  ]);
101
102
  const safeResponse = GearboxRewardsApi.extractFulfilled(response, reportError, "v3Rewards") || [];
@@ -91,12 +91,19 @@ function formatDuration(seconds, raw = true) {
91
91
  function formatNumberToString_(value) {
92
92
  return value.toLocaleString("en-US", { minimumIntegerDigits: 1, useGrouping: true }).replaceAll(",", "_");
93
93
  }
94
+ function formatTimestamp(timestamp) {
95
+ return new Date(timestamp * 1e3).toLocaleString("en-GB", {
96
+ dateStyle: "short",
97
+ timeStyle: "short"
98
+ });
99
+ }
94
100
  export {
95
101
  fmtBinaryMask,
96
102
  formatBN,
97
103
  formatBNvalue,
98
104
  formatDuration,
99
105
  formatNumberToString_,
106
+ formatTimestamp,
100
107
  numberWithCommas,
101
108
  percentFmt,
102
109
  toBigInt