zo-sdk 0.1.2 → 0.1.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 (183) hide show
  1. package/dist/abstract/BaseAPI.cjs +3 -4
  2. package/dist/abstract/BaseAPI.cjs.map +1 -1
  3. package/dist/abstract/BaseAPI.d.cts +13 -13
  4. package/dist/abstract/BaseAPI.d.cts.map +1 -1
  5. package/dist/abstract/BaseAPI.d.mts +13 -13
  6. package/dist/abstract/BaseAPI.d.mts.map +1 -1
  7. package/dist/abstract/BaseAPI.mjs +3 -4
  8. package/dist/abstract/BaseAPI.mjs.map +1 -1
  9. package/dist/abstract/BaseDataAPI.cjs +2 -2
  10. package/dist/abstract/BaseDataAPI.cjs.map +1 -1
  11. package/dist/abstract/BaseDataAPI.d.cts +2 -2
  12. package/dist/abstract/BaseDataAPI.d.cts.map +1 -1
  13. package/dist/abstract/BaseDataAPI.d.mts +2 -2
  14. package/dist/abstract/BaseDataAPI.d.mts.map +1 -1
  15. package/dist/abstract/BaseDataAPI.mjs +2 -2
  16. package/dist/abstract/BaseDataAPI.mjs.map +1 -1
  17. package/dist/abstract/index.cjs +3 -3
  18. package/dist/abstract/index.cjs.map +1 -1
  19. package/dist/abstract/index.d.cts +1 -1
  20. package/dist/abstract/index.d.cts.map +1 -1
  21. package/dist/abstract/index.d.mts +1 -1
  22. package/dist/abstract/index.d.mts.map +1 -1
  23. package/dist/abstract/index.mjs +1 -1
  24. package/dist/abstract/index.mjs.map +1 -1
  25. package/dist/api.cjs +2 -1
  26. package/dist/api.cjs.map +1 -1
  27. package/dist/api.d.cts.map +1 -1
  28. package/dist/api.d.mts.map +1 -1
  29. package/dist/api.mjs +2 -1
  30. package/dist/api.mjs.map +1 -1
  31. package/dist/bcs.cjs.map +1 -1
  32. package/dist/bcs.d.cts.map +1 -1
  33. package/dist/bcs.d.mts.map +1 -1
  34. package/dist/bcs.mjs.map +1 -1
  35. package/dist/consts/deployments-slp-mainnet.json +0 -70
  36. package/dist/consts/deployments-usdz-mainnet.json +1 -133
  37. package/dist/consts/index.cjs +21 -14
  38. package/dist/consts/index.cjs.map +1 -1
  39. package/dist/consts/index.d.cts.map +1 -1
  40. package/dist/consts/index.d.mts.map +1 -1
  41. package/dist/consts/index.mjs +21 -14
  42. package/dist/consts/index.mjs.map +1 -1
  43. package/dist/factory/SDKFactory.cjs +21 -14
  44. package/dist/factory/SDKFactory.cjs.map +1 -1
  45. package/dist/factory/SDKFactory.d.cts +4 -4
  46. package/dist/factory/SDKFactory.d.cts.map +1 -1
  47. package/dist/factory/SDKFactory.d.mts +4 -4
  48. package/dist/factory/SDKFactory.d.mts.map +1 -1
  49. package/dist/factory/SDKFactory.mjs +22 -15
  50. package/dist/factory/SDKFactory.mjs.map +1 -1
  51. package/dist/implementations/SLPAPI.cjs +143 -110
  52. package/dist/implementations/SLPAPI.cjs.map +1 -1
  53. package/dist/implementations/SLPAPI.d.cts +49 -47
  54. package/dist/implementations/SLPAPI.d.cts.map +1 -1
  55. package/dist/implementations/SLPAPI.d.mts +49 -47
  56. package/dist/implementations/SLPAPI.d.mts.map +1 -1
  57. package/dist/implementations/SLPAPI.mjs +143 -110
  58. package/dist/implementations/SLPAPI.mjs.map +1 -1
  59. package/dist/implementations/SLPDataAPI.cjs +98 -89
  60. package/dist/implementations/SLPDataAPI.cjs.map +1 -1
  61. package/dist/implementations/SLPDataAPI.d.cts +21 -21
  62. package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
  63. package/dist/implementations/SLPDataAPI.d.mts +21 -21
  64. package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
  65. package/dist/implementations/SLPDataAPI.mjs +98 -89
  66. package/dist/implementations/SLPDataAPI.mjs.map +1 -1
  67. package/dist/implementations/USDZAPI.cjs +128 -84
  68. package/dist/implementations/USDZAPI.cjs.map +1 -1
  69. package/dist/implementations/USDZAPI.d.cts +46 -45
  70. package/dist/implementations/USDZAPI.d.cts.map +1 -1
  71. package/dist/implementations/USDZAPI.d.mts +46 -45
  72. package/dist/implementations/USDZAPI.d.mts.map +1 -1
  73. package/dist/implementations/USDZAPI.mjs +128 -84
  74. package/dist/implementations/USDZAPI.mjs.map +1 -1
  75. package/dist/implementations/USDZDataAPI.cjs +48 -47
  76. package/dist/implementations/USDZDataAPI.cjs.map +1 -1
  77. package/dist/implementations/USDZDataAPI.d.cts +19 -19
  78. package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
  79. package/dist/implementations/USDZDataAPI.d.mts +19 -19
  80. package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
  81. package/dist/implementations/USDZDataAPI.mjs +49 -48
  82. package/dist/implementations/USDZDataAPI.mjs.map +1 -1
  83. package/dist/implementations/ZLPAPI.cjs +137 -89
  84. package/dist/implementations/ZLPAPI.cjs.map +1 -1
  85. package/dist/implementations/ZLPAPI.d.cts +50 -48
  86. package/dist/implementations/ZLPAPI.d.cts.map +1 -1
  87. package/dist/implementations/ZLPAPI.d.mts +50 -48
  88. package/dist/implementations/ZLPAPI.d.mts.map +1 -1
  89. package/dist/implementations/ZLPAPI.mjs +137 -89
  90. package/dist/implementations/ZLPAPI.mjs.map +1 -1
  91. package/dist/implementations/ZLPDataAPI.cjs +62 -63
  92. package/dist/implementations/ZLPDataAPI.cjs.map +1 -1
  93. package/dist/implementations/ZLPDataAPI.d.cts +19 -19
  94. package/dist/implementations/ZLPDataAPI.d.cts.map +1 -1
  95. package/dist/implementations/ZLPDataAPI.d.mts +19 -19
  96. package/dist/implementations/ZLPDataAPI.d.mts.map +1 -1
  97. package/dist/implementations/ZLPDataAPI.mjs +63 -64
  98. package/dist/implementations/ZLPDataAPI.mjs.map +1 -1
  99. package/dist/implementations/index.cjs +5 -5
  100. package/dist/implementations/index.cjs.map +1 -1
  101. package/dist/implementations/index.d.cts +2 -2
  102. package/dist/implementations/index.d.cts.map +1 -1
  103. package/dist/implementations/index.d.mts +2 -2
  104. package/dist/implementations/index.d.mts.map +1 -1
  105. package/dist/implementations/index.mjs +2 -2
  106. package/dist/implementations/index.mjs.map +1 -1
  107. package/dist/index.cjs +9 -9
  108. package/dist/index.cjs.map +1 -1
  109. package/dist/index.d.cts +6 -6
  110. package/dist/index.d.cts.map +1 -1
  111. package/dist/index.d.mts +6 -6
  112. package/dist/index.d.mts.map +1 -1
  113. package/dist/index.mjs +6 -6
  114. package/dist/index.mjs.map +1 -1
  115. package/dist/interfaces/base.cjs +0 -1
  116. package/dist/interfaces/base.cjs.map +1 -1
  117. package/dist/interfaces/base.d.cts +57 -57
  118. package/dist/interfaces/base.d.cts.map +1 -1
  119. package/dist/interfaces/base.d.mts +57 -57
  120. package/dist/interfaces/base.d.mts.map +1 -1
  121. package/dist/interfaces/base.mjs +1 -1
  122. package/dist/interfaces/base.mjs.map +1 -1
  123. package/dist/interfaces/index.d.cts +4 -4
  124. package/dist/interfaces/index.d.cts.map +1 -1
  125. package/dist/interfaces/index.d.mts +4 -4
  126. package/dist/interfaces/index.d.mts.map +1 -1
  127. package/dist/interfaces/slp.cjs +0 -2
  128. package/dist/interfaces/slp.cjs.map +1 -1
  129. package/dist/interfaces/slp.d.cts +5 -5
  130. package/dist/interfaces/slp.d.cts.map +1 -1
  131. package/dist/interfaces/slp.d.mts +5 -5
  132. package/dist/interfaces/slp.d.mts.map +1 -1
  133. package/dist/interfaces/slp.mjs +1 -2
  134. package/dist/interfaces/slp.mjs.map +1 -1
  135. package/dist/interfaces/usdz.d.cts +1 -1
  136. package/dist/interfaces/usdz.d.cts.map +1 -1
  137. package/dist/interfaces/usdz.d.mts +1 -1
  138. package/dist/interfaces/usdz.d.mts.map +1 -1
  139. package/dist/interfaces/zlp.d.cts +5 -5
  140. package/dist/interfaces/zlp.d.cts.map +1 -1
  141. package/dist/interfaces/zlp.d.mts +5 -5
  142. package/dist/interfaces/zlp.d.mts.map +1 -1
  143. package/dist/oracle.cjs +12 -2
  144. package/dist/oracle.cjs.map +1 -1
  145. package/dist/oracle.d.cts +4 -3
  146. package/dist/oracle.d.cts.map +1 -1
  147. package/dist/oracle.d.mts +4 -3
  148. package/dist/oracle.d.mts.map +1 -1
  149. package/dist/oracle.mjs +13 -3
  150. package/dist/oracle.mjs.map +1 -1
  151. package/dist/utils.cjs +1 -1
  152. package/dist/utils.cjs.map +1 -1
  153. package/dist/utils.d.cts.map +1 -1
  154. package/dist/utils.d.mts.map +1 -1
  155. package/dist/utils.mjs +1 -1
  156. package/dist/utils.mjs.map +1 -1
  157. package/eslint.config.mjs +18 -0
  158. package/package.json +16 -15
  159. package/src/abstract/BaseAPI.ts +55 -49
  160. package/src/abstract/BaseDataAPI.ts +19 -17
  161. package/src/abstract/index.ts +1 -1
  162. package/src/api.ts +3 -1
  163. package/src/bcs.ts +9 -9
  164. package/src/consts/deployments-slp-mainnet.json +0 -70
  165. package/src/consts/deployments-usdz-mainnet.json +1 -133
  166. package/src/consts/index.ts +22 -15
  167. package/src/factory/SDKFactory.ts +49 -41
  168. package/src/implementations/SLPAPI.ts +299 -210
  169. package/src/implementations/SLPDataAPI.ts +163 -146
  170. package/src/implementations/USDZAPI.ts +238 -133
  171. package/src/implementations/USDZDataAPI.ts +79 -74
  172. package/src/implementations/ZLPAPI.ts +296 -174
  173. package/src/implementations/ZLPDataAPI.ts +93 -88
  174. package/src/implementations/index.ts +3 -3
  175. package/src/index.ts +17 -17
  176. package/src/interfaces/base.ts +123 -116
  177. package/src/interfaces/index.ts +14 -17
  178. package/src/interfaces/slp.ts +20 -19
  179. package/src/interfaces/usdz.ts +13 -13
  180. package/src/interfaces/zlp.ts +22 -21
  181. package/src/oracle.ts +25 -5
  182. package/src/utils.ts +9 -9
  183. package/tsconfig.json +1 -1
@@ -1,3 +1,6 @@
1
+ /* eslint-disable no-await-in-loop */
2
+ /* eslint-disable @stylistic/indent-binary-ops */
3
+ /* eslint-disable @stylistic/indent */
1
4
  /**
2
5
  * SLP DataAPI implementation
3
6
  * Implements SLP-specific data access methods for Sudo SDK
@@ -6,30 +9,31 @@
6
9
  import type { DynamicFieldInfo, SuiClient } from '@mysten/sui/client'
7
10
  import { Transaction } from '@mysten/sui/transactions'
8
11
  import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils'
12
+
13
+ import { BaseDataAPI } from '../abstract'
14
+ import { Rate, SRate, SymbolsValuation, VaultsValuation } from '../bcs'
9
15
  import type { Network } from '../consts'
10
16
  import { LPToken, SLP_TOKEN_DECIMALS } from '../consts'
11
17
  import type {
18
+ IBaseHistoryResponse,
19
+ ISLPCredential,
12
20
  ISLPDataAPI,
13
- ISLPMarketValuationInfo,
21
+ ISLPFundingFeeModel,
14
22
  ISLPMarketInfo,
15
- ISLPVaultInfo,
16
- ISLPSymbolInfo,
17
- ISLPPositionInfo,
23
+ ISLPMarketValuationInfo,
24
+ ISLPOrderCapInfo,
18
25
  ISLPOrderInfo,
19
- ISLPStakePool,
20
- ISLPCredential,
21
- IBaseHistoryResponse,
22
26
  ISLPPositionCapInfo,
23
- ISLPOrderCapInfo,
24
- ISLPStaked,
25
27
  ISLPPositionConfig,
26
- ISLPFundingFeeModel,
28
+ ISLPPositionInfo,
29
+ ISLPRebaseFeeModel,
27
30
  ISLPReservingFeeModel,
28
- ISLPRebaseFeeModel
31
+ ISLPStaked,
32
+ ISLPStakePool,
33
+ ISLPSymbolInfo,
34
+ ISLPVaultInfo,
29
35
  } from '../interfaces'
30
- import { BaseDataAPI } from '../abstract'
31
36
  import { decimalToObject, joinSymbol, parseSymbolKey, parseValue, suiSymbolToSymbol } from '../utils'
32
- import { Rate, SRate, SymbolsValuation, VaultsValuation } from '../bcs'
33
37
 
34
38
  export interface GetCumulativeAprResponse {
35
39
  generatedAt?: string
@@ -38,14 +42,14 @@ export interface GetCumulativeAprResponse {
38
42
 
39
43
  let aprResponse: GetCumulativeAprResponse = {}
40
44
 
41
- const SECONDS_PER_EIGHT_HOUR = 8 * 60 * 60; // 28800 seconds
45
+ const SECONDS_PER_EIGHT_HOUR = 8 * 60 * 60 // 28800 seconds
42
46
 
43
47
  export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
44
48
  constructor(
45
49
  network: Network,
46
50
  provider: SuiClient,
47
51
  apiEndpoint: string,
48
- connectionURL: string
52
+ connectionURL: string,
49
53
  ) {
50
54
  super(network, provider, apiEndpoint, connectionURL, LPToken.SLP)
51
55
  }
@@ -61,7 +65,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
61
65
  showContent: true,
62
66
  },
63
67
  })
64
- return this.parseRebaseFeeModel(rawData)
68
+ return SLPDataAPI.parseRebaseFeeModel(rawData)
65
69
  }
66
70
 
67
71
  /**
@@ -178,8 +182,8 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
178
182
  sender,
179
183
  })
180
184
 
181
- const symbolsValuationOffset =
182
- Object.keys(this.consts.sudoCore.symbols).length + 1
185
+ const symbolsValuationOffset
186
+ = Object.keys(this.consts.sudoCore.symbols).length + 1
183
187
 
184
188
  const vaultsValuation = VaultsValuation.parse(
185
189
  new Uint8Array(
@@ -200,11 +204,11 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
200
204
  ),
201
205
  )
202
206
 
203
- const result =
204
- Number(
205
- BigInt(vaultsValuation.value) +
206
- BigInt(symbolsValuation.value.value) *
207
- BigInt(symbolsValuation.value.is_positive ? 1 : -1),
207
+ const result
208
+ = Number(
209
+ BigInt(vaultsValuation.value)
210
+ + BigInt(symbolsValuation.value.value)
211
+ * BigInt(symbolsValuation.value.is_positive ? 1 : -1),
208
212
  ) / 1e18
209
213
  return result
210
214
  }
@@ -231,7 +235,6 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
231
235
  ),
232
236
  )
233
237
 
234
-
235
238
  const result = Number(BigInt(vaultsValuation.value)) / 1e18
236
239
  return result
237
240
  }
@@ -245,8 +248,8 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
245
248
  }
246
249
 
247
250
  const marketInfo = await this.getMarketInfo()
248
- let value = await this.simValuateVaults(this.consts.sudoCore.adminCap)
249
- let slpPrice = value / marketInfo.lpSupplyWithDecimals
251
+ const value = await this.simValuateVaults(this.consts.sudoCore.adminCap)
252
+ const slpPrice = value / marketInfo.lpSupplyWithDecimals
250
253
 
251
254
  return {
252
255
  marketCap: value,
@@ -273,7 +276,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
273
276
  })
274
277
  const apr = await this.getCumulativeApr()
275
278
  return {
276
- ...this.parseMarketInfo(rawData),
279
+ ...SLPDataAPI.parseMarketInfo(rawData),
277
280
  apr,
278
281
  }
279
282
  }
@@ -301,10 +304,10 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
301
304
  * Gets SLP symbol information
302
305
  */
303
306
  public async getSymbolInfo(indexToken: string, long: boolean): Promise<ISLPSymbolInfo> {
304
- this.validateCache();
305
- const symbol = joinSymbol(long ? 'long' : 'short', indexToken);
307
+ this.validateCache()
308
+ const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
306
309
  if (this.symbolInfoCache[symbol]) {
307
- return this.symbolInfoCache[symbol];
310
+ return this.symbolInfoCache[symbol]
308
311
  }
309
312
 
310
313
  const rawData = await this.provider.getDynamicFieldObject({
@@ -322,11 +325,11 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
322
325
 
323
326
  public async getPositionInfoList(
324
327
  positionCapInfoList: ISLPPositionCapInfo[],
325
- owner: string
328
+ owner: string,
326
329
  ): Promise<ISLPPositionInfo[]> {
327
330
  const positionInfoList: ISLPPositionInfo[] = []
328
331
  await Promise.all(
329
- positionCapInfoList.map(async positionCapInfo => {
332
+ positionCapInfoList.map(async (positionCapInfo) => {
330
333
  const positionRaw = await this.provider.getDynamicFieldObject({
331
334
  parentId: this.consts.sudoCore.positionsParent,
332
335
  name: {
@@ -356,7 +359,6 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
356
359
  )
357
360
  }
358
361
 
359
-
360
362
  /**
361
363
  * Gets user history for SLP
362
364
  */
@@ -365,7 +367,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
365
367
  page: number,
366
368
  limit: number,
367
369
  orderType?: string,
368
- symbol?: string
370
+ symbol?: string,
369
371
  ): Promise<IBaseHistoryResponse> {
370
372
  const params = new URLSearchParams({
371
373
  trader,
@@ -403,7 +405,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
403
405
  public async getStaked(owner: string): Promise<ISLPStaked> {
404
406
  let rawCredentialsData: any[] = []
405
407
  let queryNextPage = true
406
- let queryCursor = undefined
408
+ let queryCursor
407
409
  const limit = 50
408
410
 
409
411
  while (queryNextPage) {
@@ -425,13 +427,14 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
425
427
 
426
428
  queryNextPage = hasNextPage
427
429
  queryCursor = nextCursor!
428
- if (!data) break
430
+ if (!data)
431
+ break
429
432
  rawCredentialsData = [...rawCredentialsData, ...data]
430
433
  }
431
434
 
432
435
  const pool = await this.getStakePool()
433
436
  const credentials = rawCredentialsData.map((item: any) =>
434
- this.parseCredential(item, pool),
437
+ SLPDataAPI.parseCredential(item, pool),
435
438
  )
436
439
  return {
437
440
  credentials,
@@ -453,13 +456,16 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
453
456
  showContent: true,
454
457
  },
455
458
  })
456
- return this.parseStakePool(raw)
459
+ return SLPDataAPI.parseStakePool(raw)
457
460
  }
458
461
 
459
- public async fundingFeeRate(indexToken: string, long: boolean, sender: string): Promise<number> {
462
+ public async fundingFeeRate(indexToken: string, long: boolean, sender?: string): Promise<number> {
463
+ if (!sender) {
464
+ throw new Error('Sender address is required for fundingFeeRate calculation')
465
+ }
460
466
  const tx = await this.initOracleTxb([indexToken])
461
467
  const symbol_ = joinSymbol(long ? 'long' : 'short', indexToken)
462
- const currentTimestamp = parseInt((+new Date() / 1000).toFixed(0))
468
+ const currentTimestamp = Number.parseInt((Date.now() / 1000).toFixed(0), 10)
463
469
  const symbol = tx.moveCall({
464
470
  target: `${this.consts.sudoCore.package}::market::symbol`,
465
471
  typeArguments: [
@@ -513,13 +519,16 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
513
519
  })
514
520
 
515
521
  const de = SRate.parse(
516
- new Uint8Array(res.results[res.results.length - 1].returnValues[0][0]),
522
+ new Uint8Array(res.results.at(-1).returnValues[0][0]),
517
523
  )
518
524
 
519
525
  return (Number(BigInt(de.value)) / 1e18) * (de.is_positive ? 1 : -1)
520
526
  }
521
527
 
522
- public async rebaseFeeRate(collateralToken: string, increase: boolean, amount: number, sender: string): Promise<number> {
528
+ public async rebaseFeeRate(collateralToken: string, increase: boolean, amount: number, sender?: string): Promise<number> {
529
+ if (!sender) {
530
+ throw new Error('Sender address is required for rebaseFeeRate calculation')
531
+ }
523
532
  const tx1 = await this.initOracleTxb(
524
533
  Object.keys(this.consts.pythFeeder.feeder),
525
534
  )
@@ -536,9 +545,9 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
536
545
  )[1][1],
537
546
  ),
538
547
  )
539
- const singleVaultValue =
540
- BigInt(
541
- // @ts-ignore
548
+ const singleVaultValue
549
+ = BigInt(
550
+ // @ts-expect-error: vaultsValuation.handled type is not properly defined in BCS schema
542
551
  vaultsValuation.handled.find((item: any) =>
543
552
  (item.key || '').includes(this.consts.coins[collateralToken].module.slice(2)) || false,
544
553
  )?.value.value,
@@ -565,23 +574,27 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
565
574
  sender,
566
575
  })
567
576
  const de = Rate.parse(
568
- new Uint8Array(res2.results[res2.results.length - 1].returnValues[0][0]),
577
+ new Uint8Array(res2.results.at(-1).returnValues[0][0]),
569
578
  )
570
579
  return Number(BigInt(de)) / 1e18
571
580
  }
572
581
 
573
- public async reservingFeeRate(collateralToken: string, amount: number, sender: string): Promise<number> {
582
+ public async reservingFeeRate(collateralToken: string, amount: number, sender?: string): Promise<number> {
583
+ if (!sender) {
584
+ throw new Error('Sender address is required for reservingFeeRate calculation')
585
+ }
574
586
  const vaultInfo = await this.getVaultInfo(collateralToken)
575
- const vaultSupply =
576
- vaultInfo.liquidity +
577
- vaultInfo.reservedAmount +
578
- vaultInfo.unrealisedReservingFeeAmount +
579
- amount
587
+ const vaultSupply
588
+ = vaultInfo.liquidity
589
+ + vaultInfo.reservedAmount
590
+ + vaultInfo.unrealisedReservingFeeAmount
591
+ + amount
580
592
  const utilization = vaultSupply
581
- ? parseInt(
593
+ ? Number.parseInt(
582
594
  (((vaultInfo.reservedAmount + amount) / vaultSupply) * 1e18).toFixed(
583
595
  0,
584
596
  ),
597
+ 10,
585
598
  )
586
599
  : 0
587
600
  const tx = new Transaction()
@@ -600,7 +613,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
600
613
  sender,
601
614
  })
602
615
  const de = Rate.parse(
603
- new Uint8Array(res.results[res.results.length - 1].returnValues[0][0]),
616
+ new Uint8Array(res.results.at(-1).returnValues[0][0]),
604
617
  )
605
618
  return Number(BigInt(de)) / 1e18
606
619
  }
@@ -618,17 +631,17 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
618
631
  showContent: true,
619
632
  },
620
633
  })
621
- return this.parsePositionConfig(rawData)
634
+ return SLPDataAPI.parsePositionConfig(rawData)
622
635
  }
623
636
 
624
- public async getOpenPositions(batchSize: number = 50, symbol: string = 'sui'): Promise<ISLPPositionInfo[]> {
637
+ public async getOpenPositions(batchSize = 50, symbol = 'sui'): Promise<ISLPPositionInfo[]> {
625
638
  let positionDynamicFields: DynamicFieldInfo[] = []
626
639
  let _continue = true
627
- let cursor = undefined
640
+ let cursor
628
641
  while (_continue) {
629
642
  // data here will be a list of dynamic fields containing name and value
630
- const { data, nextCursor, hasNextPage } =
631
- await this.provider.getDynamicFields({
643
+ const { data, nextCursor, hasNextPage }
644
+ = await this.provider.getDynamicFields({
632
645
  parentId: this.consts.sudoCore.positionsParent,
633
646
  cursor,
634
647
  })
@@ -639,22 +652,23 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
639
652
  }
640
653
 
641
654
  // Filter by symbol if provided
642
- if (symbol && this.consts.coins[symbol]) {
643
- const coinModule = symbol === 'sui' ? '0x2::sui::SUI' : this.consts.coins[symbol].module
644
- positionDynamicFields = positionDynamicFields.filter(field => {
645
- // Extract the second coin module from PositionName<coin1, coin2, direction>
646
- const typeStr = field.name?.type
647
- if (!typeStr) return false
648
-
649
- const match = typeStr.match(/PositionName<([^,]+),\s*([^,]+),\s*([^>]+)>/)
650
- if (!match) return false
651
-
652
- const secondCoin = match[2].trim()
653
- return secondCoin === coinModule
654
- })
655
- } else {
655
+ if (!(symbol && this.consts.coins[symbol])) {
656
656
  return []
657
657
  }
658
+ const coinModule = symbol === 'sui' ? '0x2::sui::SUI' : this.consts.coins[symbol].module
659
+ positionDynamicFields = positionDynamicFields.filter((field) => {
660
+ // Extract the second coin module from PositionName<coin1, coin2, direction>
661
+ const typeStr = field.name?.type
662
+ if (!typeStr)
663
+ return false
664
+
665
+ const match = typeStr.match(/PositionName<([^,]+),([^,]+),([^>]+)>/)
666
+ if (!match)
667
+ return false
668
+
669
+ const secondCoin = match[2].trim()
670
+ return secondCoin === coinModule
671
+ })
658
672
 
659
673
  // then we query by dynamic field names and order by time
660
674
  const positionInfoList: ISLPPositionInfo[] = []
@@ -663,14 +677,14 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
663
677
  const batch = positionDynamicFields.slice(i, i + batchSize)
664
678
 
665
679
  await Promise.all(
666
- batch.map(async positionDynamicField => {
680
+ batch.map(async (positionDynamicField) => {
667
681
  const positionRaw = await this.provider.getDynamicFieldObject({
668
682
  parentId: this.consts.sudoCore.positionsParent,
669
683
  name: positionDynamicField.name,
670
684
  })
671
685
 
672
686
  if (positionRaw?.data?.content) {
673
- // @ts-ignore
687
+ // @ts-expect-error: content fields type is not properly defined
674
688
  if (positionRaw?.data?.content?.fields?.value?.fields?.closed) {
675
689
  // skip closed positions
676
690
  return
@@ -693,7 +707,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
693
707
  }
694
708
 
695
709
  public async getPositionCapInfoList(owner: string): Promise<ISLPPositionCapInfo[]> {
696
- let cursor: string | undefined | null = undefined
710
+ let cursor: string | undefined | null
697
711
  let hasNextPage = true
698
712
  const positionCapInfoList = []
699
713
 
@@ -732,7 +746,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
732
746
  }
733
747
 
734
748
  public async getOrderCapInfoList(owner: string): Promise<ISLPOrderCapInfo[]> {
735
- let cursor: string | undefined | null = undefined
749
+ let cursor: string | undefined | null
736
750
  let hasNextPage = true
737
751
  const orderCapInfoList = []
738
752
 
@@ -793,17 +807,17 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
793
807
  */
794
808
  public async getOrderInfoList(
795
809
  orderCapInfoList: ISLPOrderCapInfo[],
796
- owner: string
810
+ owner: string,
797
811
  ): Promise<ISLPOrderInfo[]> {
798
812
  const orderInfoList: ISLPOrderInfo[] = []
799
813
  await Promise.all(
800
- orderCapInfoList.map(async orderCapInfo => {
814
+ orderCapInfoList.map(async (orderCapInfo) => {
801
815
  const orderRaw = await this.provider.getDynamicFieldObject({
802
816
  parentId: this.consts.sudoCore.ordersParent,
803
817
  name: {
804
818
  type: `${this.consts.sudoCore.package}::market::OrderName<${orderCapInfo.symbol0
805
819
  }, ${orderCapInfo.symbol1}, ${this.consts.sudoCore.package
806
- }::market::${orderCapInfo.long ? 'LONG' : 'SHORT'}, ${this.consts.coins['sui'].module
820
+ }::market::${orderCapInfo.long ? 'LONG' : 'SHORT'}, ${this.consts.coins.sui.module
807
821
  }>`,
808
822
  value: {
809
823
  owner,
@@ -826,9 +840,9 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
826
840
  const refetchDate = new Date(Date.now() - 3600_000)
827
841
  // fetch new every hour
828
842
  if (
829
- !aprResponse?.generatedAt ||
830
- (aprResponse?.generatedAt &&
831
- refetchDate > new Date(aprResponse?.generatedAt))
843
+ !aprResponse?.generatedAt
844
+ || (aprResponse?.generatedAt
845
+ && refetchDate > new Date(aprResponse?.generatedAt))
832
846
  ) {
833
847
  try {
834
848
  const url = `${this.apiEndpoint}/cumulativeApr`
@@ -839,72 +853,73 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
839
853
  },
840
854
  })
841
855
  const data = await res.json()
856
+ // eslint-disable-next-line require-atomic-updates
842
857
  aprResponse = { ...data }
843
858
  return data.cumulativeApr
844
- } catch (e) {
859
+ }
860
+ catch {
845
861
  console.error('Failed to get cumulative APR')
846
862
  }
847
863
 
848
864
  return 0
849
- } else {
850
- return aprResponse.apr
851
865
  }
866
+ return aprResponse.apr
852
867
  }
853
868
 
854
869
  // Private helper methods
855
- private calculatePositionFundingFee(position: ISLPPositionInfo, symbol: ISLPSymbolInfo, model: ISLPFundingFeeModel, price: number, lpSupplyAmount: number, timestamp: number): number {
856
- const accFundingRate = this.calcAccFundingFeeRate(symbol, model, price, lpSupplyAmount, timestamp, position.long);
857
- return position.fundingFeeValue + (accFundingRate - position.lastFundingRate) * position.positionSize;
870
+ private static calculatePositionFundingFee(position: ISLPPositionInfo, symbol: ISLPSymbolInfo, model: ISLPFundingFeeModel, price: number, lpSupplyAmount: number, timestamp: number): number {
871
+ const accFundingRate = this.calcAccFundingFeeRate(symbol, model, price, lpSupplyAmount, timestamp, position.long)
872
+ return position.fundingFeeValue + (accFundingRate - position.lastFundingRate) * position.positionSize
858
873
  }
859
874
 
860
- private calcAccFundingFeeRate(symbol: ISLPSymbolInfo, model: ISLPFundingFeeModel, price: number, lpSupplyAmount: number, timestamp: number, isLong: boolean): number {
875
+ private static calcAccFundingFeeRate(symbol: ISLPSymbolInfo, model: ISLPFundingFeeModel, price: number, lpSupplyAmount: number, timestamp: number, isLong: boolean): number {
861
876
  if (symbol.lastUpdate > 0) {
862
- const elapsed = timestamp - symbol.lastUpdate;
877
+ const elapsed = timestamp - symbol.lastUpdate
863
878
  if (elapsed > 0) {
864
- const deltaSize = this.calcDeltaSize(symbol, price, isLong);
865
- const pnlPerLp = (symbol.realisedPnl + symbol.unrealisedFundingFeeValue + deltaSize) / lpSupplyAmount;
866
- return symbol.accFundingRate + this.calcFundingFeeRate(model, pnlPerLp, elapsed);
879
+ const deltaSize = this.calcDeltaSize(symbol, price, isLong)
880
+ const pnlPerLp = (symbol.realisedPnl + symbol.unrealisedFundingFeeValue + deltaSize) / lpSupplyAmount
881
+ return symbol.accFundingRate + SLPDataAPI.calcFundingFeeRate(model, pnlPerLp, elapsed)
867
882
  }
868
883
  }
869
- return symbol.accFundingRate;
884
+ return symbol.accFundingRate
870
885
  }
871
886
 
872
- private calcDeltaSize(symbol: ISLPSymbolInfo, price: number, isLong: boolean): number {
873
- const latestSize = symbol.openingAmount * price;
874
- return isLong ? symbol.openingSize - latestSize : latestSize - symbol.openingSize;
887
+ private static calcDeltaSize(symbol: ISLPSymbolInfo, price: number, isLong: boolean): number {
888
+ const latestSize = symbol.openingAmount * price
889
+ return isLong ? symbol.openingSize - latestSize : latestSize - symbol.openingSize
875
890
  }
876
891
 
877
- private calcFundingFeeRate(model: ISLPFundingFeeModel, pnlPerRate: number, elapsed: number): number {
878
- const dailyRate = Math.min(model.multiplier * Math.abs(pnlPerRate), model.max);
879
- const secondsRate = dailyRate * elapsed / SECONDS_PER_EIGHT_HOUR;
880
- return pnlPerRate >= 0 ? -secondsRate : secondsRate;
892
+ private static calcFundingFeeRate(model: ISLPFundingFeeModel, pnlPerRate: number, elapsed: number): number {
893
+ const dailyRate = Math.min(model.multiplier * Math.abs(pnlPerRate), model.max)
894
+ const secondsRate = dailyRate * elapsed / SECONDS_PER_EIGHT_HOUR
895
+ return pnlPerRate >= 0 ? -secondsRate : secondsRate
881
896
  }
882
897
 
883
- private calculatePositionReserveFee(position: ISLPPositionInfo, vault: ISLPVaultInfo, model: ISLPReservingFeeModel, timestamp: number): number {
884
- const accReservingRate = this.calcAccReservingFeeRate(vault, model, timestamp);
885
- return position.reservingFeeAmount + (accReservingRate - position.lastReservingRate) * position.collateralAmount;
898
+ private static calculatePositionReserveFee(position: ISLPPositionInfo, vault: ISLPVaultInfo, model: ISLPReservingFeeModel, timestamp: number): number {
899
+ const accReservingRate = SLPDataAPI.calcAccReservingFeeRate(vault, model, timestamp)
900
+ return position.reservingFeeAmount + (accReservingRate - position.lastReservingRate) * position.collateralAmount
886
901
  }
887
902
 
888
- private calcAccReservingFeeRate(vault: ISLPVaultInfo, model: ISLPReservingFeeModel, timestamp: number): number {
903
+ private static calcAccReservingFeeRate(vault: ISLPVaultInfo, model: ISLPReservingFeeModel, timestamp: number): number {
889
904
  if (vault.lastUpdate > 0) {
890
- const elapsed = timestamp - vault.lastUpdate;
905
+ const elapsed = timestamp - vault.lastUpdate
891
906
  if (elapsed > 0) {
892
- const utilization = this.vaultUtilization(vault);
893
- return vault.accReservingRate + this.calcReservingFeeRate(model, utilization, elapsed);
907
+ const utilization = SLPDataAPI.vaultUtilization(vault)
908
+ return vault.accReservingRate + SLPDataAPI.calcReservingFeeRate(model, utilization, elapsed)
894
909
  }
895
910
  }
896
- return vault.accReservingRate;
911
+ return vault.accReservingRate
897
912
  }
898
913
 
899
- private vaultUtilization(vault: ISLPVaultInfo): number {
900
- return vault.liquidity > 0 ? vault.reservedAmount / vault.liquidity : 0;
914
+ private static vaultUtilization(vault: ISLPVaultInfo): number {
915
+ return vault.liquidity > 0 ? vault.reservedAmount / vault.liquidity : 0
901
916
  }
902
917
 
903
- private calcReservingFeeRate(model: ISLPReservingFeeModel, utilization: number, elapsed: number): number {
918
+ private static calcReservingFeeRate(model: ISLPReservingFeeModel, utilization: number, elapsed: number): number {
904
919
  return model.multiplier * utilization * elapsed / SECONDS_PER_EIGHT_HOUR
905
920
  }
906
921
 
907
- private parsePositionConfig(raw: any): ISLPPositionConfig {
922
+ private static parsePositionConfig(raw: any): ISLPPositionConfig {
908
923
  const positionConfigFields = raw.data.content.fields.inner.fields
909
924
 
910
925
  return {
@@ -923,7 +938,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
923
938
  }
924
939
  }
925
940
 
926
- private parseRebaseFeeModel(raw: any): ISLPRebaseFeeModel {
941
+ private static parseRebaseFeeModel(raw: any): ISLPRebaseFeeModel {
927
942
  const { fields } = raw.data.content
928
943
 
929
944
  return {
@@ -932,7 +947,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
932
947
  }
933
948
  }
934
949
 
935
- private parseFundingFeeModel(raw: any): ISLPFundingFeeModel {
950
+ private static parseFundingFeeModel(raw: any): ISLPFundingFeeModel {
936
951
  const { fields } = raw.data.content
937
952
 
938
953
  return {
@@ -941,7 +956,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
941
956
  }
942
957
  }
943
958
 
944
- private parseMarketInfo(raw: any): ISLPMarketInfo {
959
+ private static parseMarketInfo(raw: any): ISLPMarketInfo {
945
960
  const content = raw.data.content.fields
946
961
 
947
962
  return {
@@ -963,7 +978,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
963
978
  showContent: true,
964
979
  },
965
980
  })
966
- const reservingFeeModel = this.parseReservingFeeModel(reservingFeeModelRaw)
981
+ const reservingFeeModel = SLPDataAPI.parseReservingFeeModel(reservingFeeModelRaw)
967
982
 
968
983
  return {
969
984
  liquidity: parseValue(vaultFields.liquidity),
@@ -985,7 +1000,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
985
1000
  }
986
1001
  }
987
1002
 
988
- private parseReservingFeeModel(raw: any): { multiplier: number } {
1003
+ private static parseReservingFeeModel(raw: any): { multiplier: number } {
989
1004
  const content = raw.data.content.fields
990
1005
  return {
991
1006
  multiplier: parseValue(content.multiplier),
@@ -993,7 +1008,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
993
1008
  }
994
1009
 
995
1010
  private async parseSymbolInfo(raw: any, long: boolean): Promise<ISLPSymbolInfo> {
996
- const fields = raw.data.content.fields.value.fields
1011
+ const { fields } = raw.data.content.fields.value
997
1012
  const fundingFeeModelAddr = fields.funding_fee_model
998
1013
  const fundingFeeModelRaw = await this.provider.getObject({
999
1014
  id: fundingFeeModelAddr,
@@ -1001,7 +1016,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
1001
1016
  showContent: true,
1002
1017
  },
1003
1018
  })
1004
- const fundingFeeModel = this.parseFundingFeeModel(fundingFeeModelRaw)
1019
+ const fundingFeeModel = SLPDataAPI.parseFundingFeeModel(fundingFeeModelRaw)
1005
1020
 
1006
1021
  return {
1007
1022
  openingSize: parseValue(fields.opening_size),
@@ -1027,8 +1042,8 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
1027
1042
  }
1028
1043
 
1029
1044
  private async parsePositionInfo(raw: any, id_: string): Promise<ISLPPositionInfo> {
1030
- const content = raw.data.content
1031
- const fields = content.fields
1045
+ const { content } = raw.data
1046
+ const { fields } = content
1032
1047
  const positionFields = fields.value.fields
1033
1048
  const dataType = fields.name.type
1034
1049
 
@@ -1036,7 +1051,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
1036
1051
  id: id_,
1037
1052
  long: dataType.includes('::market::LONG'),
1038
1053
  owner: fields.name.fields.owner,
1039
- version: parseInt(raw.data.version, 10),
1054
+ version: Number.parseInt(raw.data.version, 10),
1040
1055
  collateralToken: suiSymbolToSymbol(
1041
1056
  dataType.split('<')[1].split(',')[0].trim(),
1042
1057
  this.consts,
@@ -1057,21 +1072,22 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
1057
1072
 
1058
1073
  if (!positionFields.closed) {
1059
1074
  try {
1060
- positionInfo.reservingFeeAmount = this.calculatePositionReserveFee(
1075
+ positionInfo.reservingFeeAmount = SLPDataAPI.calculatePositionReserveFee(
1061
1076
  positionInfo,
1062
1077
  await this.getVaultInfo(positionInfo.collateralToken),
1063
1078
  (await this.getVaultInfo(positionInfo.collateralToken)).reservingFeeModel,
1064
- Date.now() / 1000
1079
+ Date.now() / 1000,
1065
1080
  )
1066
- positionInfo.fundingFeeValue = this.calculatePositionFundingFee(
1081
+ positionInfo.fundingFeeValue = SLPDataAPI.calculatePositionFundingFee(
1067
1082
  positionInfo,
1068
1083
  await this.getSymbolInfo(positionInfo.indexToken, positionInfo.long),
1069
1084
  (await this.getSymbolInfo(positionInfo.indexToken, positionInfo.long)).fundingFeeModel,
1070
1085
  (await this.getOraclePrice(positionInfo.indexToken)).getPriceUnchecked().getPriceAsNumberUnchecked(),
1071
1086
  (await this.getMarketInfo()).lpSupplyWithDecimals,
1072
- Date.now() / 1000
1087
+ Date.now() / 1000,
1073
1088
  )
1074
- } catch (e) {
1089
+ }
1090
+ catch (e) {
1075
1091
  console.error(e)
1076
1092
  positionInfo.reservingFeeAmount = 0
1077
1093
  positionInfo.fundingFeeValue = 0
@@ -1082,17 +1098,17 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
1082
1098
  }
1083
1099
 
1084
1100
  private parseOrderInfo(raw: any, capId: string): ISLPOrderInfo {
1085
- let content = raw.data.content
1086
- let fields = content.fields.value.fields
1101
+ const { content } = raw.data
1102
+ const { fields } = content.fields.value
1087
1103
 
1088
1104
  // Extract tokens from dataType
1089
- let dataType = content.type
1105
+ const dataType = content.type
1090
1106
 
1091
1107
  const orderType = content.fields.value.type.includes('OpenPositionOrder')
1092
1108
  ? 'OPEN_POSITION'
1093
1109
  : 'DECREASE_POSITION'
1094
1110
 
1095
- let ret: ISLPOrderInfo = {
1111
+ const ret: ISLPOrderInfo = {
1096
1112
  id: content.fields.id.id,
1097
1113
  capId,
1098
1114
  executed: fields.executed,
@@ -1120,7 +1136,8 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
1120
1136
  collateralAmount: BigInt(fields.collateral),
1121
1137
  openAmount: BigInt(fields.open_amount),
1122
1138
  }
1123
- } else {
1139
+ }
1140
+ else {
1124
1141
  ret.decreaseOrder = {
1125
1142
  decreaseAmount: BigInt(fields.decrease_amount),
1126
1143
  takeProfit: fields.take_profit,
@@ -1130,7 +1147,7 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
1130
1147
  return ret
1131
1148
  }
1132
1149
 
1133
- private parseCredential(raw: any, pool: ISLPStakePool): ISLPCredential {
1150
+ private static parseCredential(raw: any, pool: ISLPStakePool): ISLPCredential {
1134
1151
  const stakedAmount = BigInt(raw.data.content.fields.stake)
1135
1152
  const accRewardPerShare = BigInt(
1136
1153
  raw.data.content.fields.acc_reward_per_share,
@@ -1141,12 +1158,12 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
1141
1158
  amount: stakedAmount,
1142
1159
  accRewardPerShare,
1143
1160
  claimable:
1144
- ((pool.accRewardPerShare - accRewardPerShare) * stakedAmount) /
1145
- BigInt(1e18),
1161
+ ((pool.accRewardPerShare - accRewardPerShare) * stakedAmount)
1162
+ / BigInt(1e18),
1146
1163
  }
1147
1164
  }
1148
1165
 
1149
- private parseStakePool(raw: any): ISLPStakePool {
1166
+ private static parseStakePool(raw: any): ISLPStakePool {
1150
1167
  const content = raw.data.content.fields
1151
1168
  const pool = {
1152
1169
  id: content.id.id,
@@ -1159,17 +1176,17 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
1159
1176
  accRewardPerShare: BigInt(content.acc_reward_per_share),
1160
1177
  lockDuration: parseValue(content.lock_duration),
1161
1178
  }
1162
- this.refreshPool(pool, Math.floor(Date.now() / 1000))
1179
+ SLPDataAPI.refreshPool(pool, Math.floor(Date.now() / 1000))
1163
1180
  return pool
1164
1181
  }
1165
1182
 
1166
- private refreshPool(pool: ISLPStakePool, timestamp: number): void {
1183
+ private static refreshPool(pool: ISLPStakePool, timestamp: number): void {
1167
1184
  if (timestamp === pool.lastUpdatedTime || timestamp < pool.startTime) {
1168
1185
  return
1169
1186
  }
1170
1187
  if (
1171
- pool.lastUpdatedTime === pool.endTime ||
1172
- pool.stakedAmount === BigInt(0)
1188
+ pool.lastUpdatedTime === pool.endTime
1189
+ || pool.stakedAmount === BigInt(0)
1173
1190
  ) {
1174
1191
  return
1175
1192
  }
@@ -1177,12 +1194,12 @@ export class SLPDataAPI extends BaseDataAPI implements ISLPDataAPI {
1177
1194
  timestamp = pool.endTime
1178
1195
  }
1179
1196
 
1180
- const rewardAmount =
1181
- (pool.reward * BigInt(timestamp - pool.lastUpdatedTime)) /
1182
- BigInt(pool.endTime - pool.lastUpdatedTime)
1197
+ const rewardAmount
1198
+ = (pool.reward * BigInt(timestamp - pool.lastUpdatedTime))
1199
+ / BigInt(pool.endTime - pool.lastUpdatedTime)
1183
1200
 
1184
1201
  pool.lastUpdatedTime = timestamp
1185
1202
  const rewardPerShare = (rewardAmount * BigInt(1e18)) / pool.stakedAmount
1186
1203
  pool.accRewardPerShare += rewardPerShare
1187
1204
  }
1188
- }
1205
+ }