@gmx-io/sdk 0.1.1 → 0.2.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/README.md +31 -5
  2. package/build/src/configs/batch.d.ts +2 -3
  3. package/build/src/configs/chains.d.ts +5 -1
  4. package/build/src/configs/chains.js +9 -2
  5. package/build/src/configs/contracts.d.ts +220 -1
  6. package/build/src/configs/contracts.js +67 -8
  7. package/build/src/configs/markets.js +70 -0
  8. package/build/src/configs/tokens.js +128 -5
  9. package/build/src/modules/accounts/accounts.spec.js +1 -0
  10. package/build/src/modules/markets/index.js +2 -8
  11. package/build/src/modules/markets/markets.spec.js +1 -0
  12. package/build/src/modules/markets/query-builders.d.ts +1 -1
  13. package/build/src/modules/markets/query-builders.js +1 -1
  14. package/build/src/modules/markets/types.d.ts +4 -1
  15. package/build/src/modules/orders/orders.spec.js +1 -0
  16. package/build/src/modules/orders/utils.js +1 -1
  17. package/build/src/modules/positions/positions.d.ts +2 -2
  18. package/build/src/modules/positions/positions.js +21 -8
  19. package/build/src/modules/positions/positions.spec.js +2 -1
  20. package/build/src/modules/tokens/tokens.spec.js +1 -0
  21. package/build/src/modules/trades/trades.spec.js +1 -0
  22. package/build/src/modules/utils/utils.d.ts +1 -1
  23. package/build/src/modules/utils/utils.js +1 -1
  24. package/build/src/prebuilt/hashedKinkModelMarketRatesKeys.json +80 -0
  25. package/build/src/prebuilt/hashedMarketConfigKeys.json +500 -0
  26. package/build/src/prebuilt/hashedMarketValuesKeys.json +150 -0
  27. package/build/src/types/common.d.ts +1 -0
  28. package/build/src/types/fees.d.ts +2 -1
  29. package/build/src/types/markets.d.ts +7 -19
  30. package/build/src/types/orders.d.ts +3 -5
  31. package/build/src/types/positions.d.ts +11 -4
  32. package/build/src/types/trade.d.ts +1 -0
  33. package/build/src/types/tradeHistory.d.ts +4 -1
  34. package/build/src/utils/__tests__/LruCache.spec.d.ts +1 -0
  35. package/build/src/utils/__tests__/LruCache.spec.js +43 -0
  36. package/build/src/utils/__tests__/bigmath.spec.d.ts +1 -0
  37. package/build/src/utils/__tests__/bigmath.spec.js +38 -0
  38. package/build/src/utils/__tests__/fees.spec.d.ts +1 -0
  39. package/build/src/utils/__tests__/fees.spec.js +62 -0
  40. package/build/src/utils/__tests__/hash.spec.d.ts +1 -0
  41. package/build/src/utils/__tests__/hash.spec.js +41 -0
  42. package/build/src/utils/__tests__/markets.spec.d.ts +1 -0
  43. package/build/src/utils/__tests__/markets.spec.js +265 -0
  44. package/build/src/utils/__tests__/numbers.spec.d.ts +1 -0
  45. package/build/src/utils/__tests__/numbers.spec.js +81 -0
  46. package/build/src/utils/__tests__/objects.spec.d.ts +1 -0
  47. package/build/src/utils/__tests__/objects.spec.js +59 -0
  48. package/build/src/utils/__tests__/positions.spec.d.ts +1 -0
  49. package/build/src/utils/__tests__/positions.spec.js +178 -0
  50. package/build/src/utils/__tests__/prices.spec.d.ts +1 -0
  51. package/build/src/utils/__tests__/prices.spec.js +59 -0
  52. package/build/src/utils/__tests__/referrals.spec.d.ts +1 -0
  53. package/build/src/utils/__tests__/referrals.spec.js +18 -0
  54. package/build/src/utils/__tests__/subgraph.spec.d.ts +1 -0
  55. package/build/src/utils/__tests__/subgraph.spec.js +163 -0
  56. package/build/src/utils/__tests__/tokens.spec.d.ts +1 -0
  57. package/build/src/utils/__tests__/tokens.spec.js +83 -0
  58. package/build/src/utils/__tests__/trade.spec.d.ts +1 -0
  59. package/build/src/utils/__tests__/trade.spec.js +36 -0
  60. package/build/src/utils/bigmath.d.ts +1 -1
  61. package/build/src/utils/bigmath.js +6 -1
  62. package/build/src/utils/callContract.js +5 -1
  63. package/build/src/utils/common.d.ts +6 -1
  64. package/build/src/utils/common.js +9 -1
  65. package/build/src/utils/contracts.d.ts +4 -0
  66. package/build/src/utils/contracts.js +2 -0
  67. package/build/src/utils/fees/executionFee.d.ts +22 -21
  68. package/build/src/utils/fees/executionFee.js +26 -26
  69. package/build/src/utils/fees/executionFee.spec.d.ts +1 -0
  70. package/build/src/utils/fees/executionFee.spec.js +64 -0
  71. package/build/src/utils/fees/index.d.ts +2 -0
  72. package/build/src/utils/fees/index.js +21 -9
  73. package/build/src/utils/markets.d.ts +9 -2
  74. package/build/src/utils/markets.js +33 -10
  75. package/build/src/utils/multicall.js +4 -3
  76. package/build/src/utils/numbers.d.ts +2 -0
  77. package/build/src/utils/numbers.js +28 -0
  78. package/build/src/utils/orders.js +0 -8
  79. package/build/src/utils/positions.js +3 -3
  80. package/build/src/utils/prices.d.ts +1 -6
  81. package/build/src/utils/prices.js +0 -9
  82. package/build/src/utils/referrals.d.ts +2 -0
  83. package/build/src/utils/referrals.js +17 -15
  84. package/build/src/utils/swapStats.d.ts +1 -0
  85. package/build/src/utils/swapStats.js +12 -1
  86. package/build/src/utils/testUtil.d.ts +14314 -326
  87. package/build/src/utils/tokens.d.ts +4 -0
  88. package/build/src/utils/tokens.js +4 -0
  89. package/build/tsconfig.tsbuildinfo +1 -1
  90. package/package.json +6 -29
  91. package/build/src/types/amounts.d.ts +0 -223
  92. package/build/src/types/amounts.js +0 -17
  93. package/build/src/types/syntheticsEvents.d.ts +0 -88
  94. /package/build/src/types/{syntheticsEvents.js → common.js} +0 -0
@@ -280,6 +280,7 @@ export const TOKENS = {
280
280
  priceDecimals: 4,
281
281
  address: "0x565609fAF65B92F7be02468acF86f8979423e514",
282
282
  decimals: 18,
283
+ categories: ["layer1"],
283
284
  imageUrl: "https://assets.coingecko.com/coins/images/12559/small/coin-round-red.png?1604021818",
284
285
  coingeckoUrl: "https://www.coingecko.com/en/coins/avalanche",
285
286
  coingeckoSymbol: "AVAX",
@@ -300,7 +301,7 @@ export const TOKENS = {
300
301
  symbol: "PEPE",
301
302
  address: "0x25d887Ce7a35172C62FeBFD67a1856F20FaEbB00",
302
303
  decimals: 18,
303
- priceDecimals: 6,
304
+ priceDecimals: 8,
304
305
  categories: ["meme"],
305
306
  imageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776",
306
307
  coingeckoUrl: "https://www.coingecko.com/en/coins/pepe",
@@ -359,7 +360,7 @@ export const TOKENS = {
359
360
  assetSymbol: "SHIB",
360
361
  address: "0x3E57D02f9d196873e55727382974b02EdebE6bfd",
361
362
  decimals: 18,
362
- priceDecimals: 6,
363
+ priceDecimals: 9,
363
364
  categories: ["meme"],
364
365
  imageUrl: "https://assets.coingecko.com/coins/images/11939/standard/shiba.png?1696511800",
365
366
  coingeckoUrl: "https://www.coingecko.com/en/coins/shiba-inu",
@@ -389,7 +390,7 @@ export const TOKENS = {
389
390
  symbol: "SATS",
390
391
  address: "0x2cD2eB61D17b78239Fcd19aafF72981B5D5eF319",
391
392
  decimals: 6,
392
- priceDecimals: 5,
393
+ priceDecimals: 11,
393
394
  categories: ["meme"],
394
395
  imageUrl: "https://assets.coingecko.com/coins/images/30666/standard/_dD8qr3M_400x400.png?1702913020",
395
396
  coingeckoUrl: "https://www.coingecko.com/en/coins/sats-ordinals",
@@ -498,7 +499,7 @@ export const TOKENS = {
498
499
  symbol: "BONK",
499
500
  address: "0x1FD10E767187A92f0AB2ABDEEF4505e319cA06B2",
500
501
  decimals: 5,
501
- priceDecimals: 6,
502
+ priceDecimals: 9,
502
503
  categories: ["meme"],
503
504
  imageUrl: "https://assets.coingecko.com/coins/images/28600/standard/bonk.jpg?1696527587",
504
505
  coingeckoUrl: "https://www.coingecko.com/en/coins/bonk",
@@ -532,7 +533,7 @@ export const TOKENS = {
532
533
  symbol: "FLOKI",
533
534
  address: "0x6792c5B8962ffbDD020c6b6FD0Be7b182e0e33a3",
534
535
  decimals: 9,
535
- priceDecimals: 5,
536
+ priceDecimals: 8,
536
537
  categories: ["meme"],
537
538
  imageUrl: "https://assets.coingecko.com/coins/images/16746/standard/PNG_image.png?1696516318",
538
539
  coingeckoUrl: "https://www.coingecko.com/en/coins/floki",
@@ -635,6 +636,105 @@ export const TOKENS = {
635
636
  coingeckoUrl: "https://www.coingecko.com/en/coins/render",
636
637
  isSynthetic: true,
637
638
  },
639
+ {
640
+ name: "Filecoin",
641
+ symbol: "FIL",
642
+ address: "0x3AeBb98f57081DcBEb0B8EA823Cf84900A31e5D8",
643
+ decimals: 18,
644
+ categories: ["layer1"],
645
+ priceDecimals: 4,
646
+ imageUrl: "https://assets.coingecko.com/coins/images/12817/standard/filecoin.png?1696512609",
647
+ coingeckoUrl: "https://www.coingecko.com/en/coins/filecoin",
648
+ isSynthetic: true,
649
+ },
650
+ {
651
+ name: "dYdX",
652
+ symbol: "DYDX",
653
+ address: "0x0739Ad7AeA69aD36EdEb91b0e55cAC140427c632",
654
+ decimals: 18,
655
+ priceDecimals: 4,
656
+ categories: ["layer1", "defi"],
657
+ imageUrl: "https://assets.coingecko.com/coins/images/32594/standard/dydx.png?1698673495",
658
+ coingeckoUrl: "https://www.coingecko.com/en/coins/dydx-chain",
659
+ isSynthetic: true,
660
+ },
661
+ {
662
+ name: "Injective",
663
+ symbol: "INJ",
664
+ address: "0xfdE73EddbE6c5712A12B72c470F8FE5c77A7fF17",
665
+ decimals: 18,
666
+ priceDecimals: 4,
667
+ categories: ["layer1"],
668
+ imageUrl: "https://assets.coingecko.com/coins/images/12882/standard/Secondary_Symbol.png?1696512670",
669
+ coingeckoUrl: "https://www.coingecko.com/en/coins/injective",
670
+ isSynthetic: true,
671
+ },
672
+ {
673
+ name: "Official Trump",
674
+ symbol: "TRUMP",
675
+ address: "0x30021aFA4767Ad66aA52A06dF8a5AB3acA9371fD",
676
+ decimals: 6,
677
+ priceDecimals: 4,
678
+ categories: ["meme"],
679
+ imageUrl: "https://assets.coingecko.com/coins/images/53746/standard/trump.png?1737171561",
680
+ coingeckoUrl: "https://www.coingecko.com/en/coins/official-trump",
681
+ isSynthetic: true,
682
+ },
683
+ {
684
+ name: "Melania Meme",
685
+ symbol: "MELANIA",
686
+ address: "0xfa4F8E582214eBCe1A08eB2a65e08082053E441F",
687
+ decimals: 6,
688
+ priceDecimals: 4,
689
+ categories: ["meme"],
690
+ imageUrl: "https://assets.coingecko.com/coins/images/53775/standard/melania-meme.png?1737329885",
691
+ coingeckoUrl: "https://www.coingecko.com/en/coins/melania-meme",
692
+ isSynthetic: true,
693
+ },
694
+ {
695
+ name: "Ethena Governance Token",
696
+ symbol: "ENA",
697
+ address: "0xfe1Aac2CD9C5cC77b58EeCfE75981866ed0c8b7a",
698
+ decimals: 18,
699
+ priceDecimals: 4,
700
+ categories: ["defi"],
701
+ imageUrl: "https://assets.coingecko.com/coins/images/36530/standard/ethena.png?1711701436",
702
+ coingeckoUrl: "https://www.coingecko.com/en/coins/ethena",
703
+ isSynthetic: true,
704
+ },
705
+ {
706
+ name: "ai16z",
707
+ symbol: "AI16Z",
708
+ address: "0xBb69bd9dc152C2c0F083507641a46193d2B61EBb",
709
+ decimals: 9,
710
+ priceDecimals: 5,
711
+ categories: ["meme"],
712
+ imageUrl: "https://assets.coingecko.com/coins/images/51090/standard/AI16Z.jpg?1730027175",
713
+ coingeckoUrl: "https://www.coingecko.com/en/coins/ai16z",
714
+ isSynthetic: true,
715
+ },
716
+ {
717
+ name: "Animecoin",
718
+ symbol: "ANIME",
719
+ address: "0x37a645648dF29205C6261289983FB04ECD70b4B3",
720
+ decimals: 18,
721
+ priceDecimals: 6,
722
+ categories: ["meme"],
723
+ imageUrl: "https://assets.coingecko.com/coins/images/53575/standard/anime.jpg?1736748703",
724
+ coingeckoUrl: "https://www.coingecko.com/en/coins/anime",
725
+ isSynthetic: false,
726
+ },
727
+ {
728
+ name: "Fartcoin",
729
+ symbol: "FARTCOIN",
730
+ address: "0xaca341E61aB6177B0b0Df46a612e4311F8a7605f",
731
+ decimals: 6,
732
+ priceDecimals: 4,
733
+ categories: ["meme"],
734
+ imageUrl: "https://assets.coingecko.com/coins/images/50891/standard/fart.jpg?1729503972",
735
+ coingeckoUrl: "https://www.coingecko.com/en/coins/fartcoin",
736
+ isSynthetic: true,
737
+ },
638
738
  {
639
739
  name: "GMX LP",
640
740
  symbol: "GLP",
@@ -682,6 +782,7 @@ export const TOKENS = {
682
782
  address: "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",
683
783
  isWrapped: true,
684
784
  baseSymbol: "AVAX",
785
+ categories: ["layer1"],
685
786
  imageUrl: "https://assets.coingecko.com/coins/images/12559/small/coin-round-red.png?1604021818",
686
787
  coingeckoUrl: "https://www.coingecko.com/en/coins/avalanche",
687
788
  explorerUrl: "https://snowtrace.io/address/0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",
@@ -862,6 +963,28 @@ export const TOKENS = {
862
963
  coingeckoUrl: "https://www.coingecko.com/en/coins/gmx",
863
964
  explorerUrl: "https://snowtrace.io/address/0x62edc0692bd897d2295872a9ffcac5425011c661",
864
965
  },
966
+ {
967
+ name: "Official Trump",
968
+ symbol: "TRUMP",
969
+ address: "0x2f6d7be53fab5538065a226BA091015d422a7528",
970
+ decimals: 6,
971
+ priceDecimals: 4,
972
+ categories: ["meme"],
973
+ imageUrl: "https://assets.coingecko.com/coins/images/53746/standard/trump.png?1737171561",
974
+ coingeckoUrl: "https://www.coingecko.com/en/coins/official-trump",
975
+ isSynthetic: true,
976
+ },
977
+ {
978
+ name: "Melania Meme",
979
+ symbol: "MELANIA",
980
+ address: "0xd42C991a4FAb293C57a7bf25C2E2ec5aE1dB1714",
981
+ decimals: 6,
982
+ priceDecimals: 4,
983
+ categories: ["meme"],
984
+ imageUrl: "https://assets.coingecko.com/coins/images/53775/standard/melania-meme.png?1737329885",
985
+ coingeckoUrl: "https://www.coingecko.com/en/coins/melania-meme",
986
+ isSynthetic: true,
987
+ },
865
988
  {
866
989
  name: "Escrowed GMX",
867
990
  symbol: "esGMX",
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from "vitest";
1
2
  import { arbitrumSdk } from "../../utils/testUtil";
2
3
  describe("Accounts", () => {
3
4
  it("should be able to get delegates", async () => {
@@ -57,7 +57,7 @@ export class Markets extends Module {
57
57
  // Skip invalid market
58
58
  if (!readerValues || !dataStoreValues || readerErrors || dataStoreErrors) {
59
59
  // eslint-disable-next-line no-console
60
- console.log("market info error", marketAddress, readerErrors, dataStoreErrors, readerValues);
60
+ console.warn(`No market found ${marketAddress} in getMarketsValues`);
61
61
  return acc;
62
62
  }
63
63
  const market = getByKey(marketsData, marketAddress);
@@ -90,12 +90,6 @@ export class Markets extends Module {
90
90
  positionImpactPoolAmount: dataStoreValues.positionImpactPoolAmount.returnValues[0],
91
91
  swapImpactPoolAmountLong: dataStoreValues.swapImpactPoolAmountLong.returnValues[0],
92
92
  swapImpactPoolAmountShort: dataStoreValues.swapImpactPoolAmountShort.returnValues[0],
93
- pnlLongMax: poolValueInfoMax.longPnl,
94
- pnlLongMin: poolValueInfoMin.longPnl,
95
- pnlShortMax: poolValueInfoMax.shortPnl,
96
- pnlShortMin: poolValueInfoMin.shortPnl,
97
- netPnlMax: poolValueInfoMax.netPnl,
98
- netPnlMin: poolValueInfoMin.netPnl,
99
93
  borrowingFactorPerSecondForLongs: readerValues.marketInfo.returnValues.borrowingFactorPerSecondForLongs,
100
94
  borrowingFactorPerSecondForShorts: readerValues.marketInfo.returnValues.borrowingFactorPerSecondForShorts,
101
95
  fundingFactorPerSecond: nextFunding.fundingFactorPerSecond,
@@ -320,7 +314,7 @@ export class Markets extends Module {
320
314
  return data?.positionsVolume.length
321
315
  ? data?.positionsVolume.reduce((acc, { market, volume }) => {
322
316
  return { ...acc, [market]: BigInt(volume) };
323
- })
317
+ }, {})
324
318
  : {};
325
319
  });
326
320
  }
@@ -1,5 +1,6 @@
1
1
  import { GmxSdk } from "../../index";
2
2
  import { arbitrumSdk, arbitrumSdkConfig } from "../../utils/testUtil";
3
+ import { describe, expect, it } from "vitest";
3
4
  describe("Markets", () => {
4
5
  describe("getMarkets", () => {
5
6
  it("should be able to get markets data", async () => {
@@ -32,7 +32,7 @@ export declare function buildMarketsConfigsRequest(chainId: number, { marketsDat
32
32
  dataStoreAddress: string;
33
33
  }): Promise<import("./types").MarketValuesMulticallRequestConfig<{
34
34
  [key: `${string}-dataStore`]: {
35
- calls: Record<"isDisabled" | "maxLongPoolAmount" | "maxShortPoolAmount" | "maxLongPoolUsdForDeposit" | "maxShortPoolUsdForDeposit" | "longPoolAmountAdjustment" | "shortPoolAmountAdjustment" | "reserveFactorLong" | "reserveFactorShort" | "openInterestReserveFactorLong" | "openInterestReserveFactorShort" | "maxOpenInterestLong" | "maxOpenInterestShort" | "borrowingFactorLong" | "borrowingFactorShort" | "borrowingExponentFactorLong" | "borrowingExponentFactorShort" | "fundingFactor" | "fundingExponentFactor" | "fundingIncreaseFactorPerSecond" | "fundingDecreaseFactorPerSecond" | "thresholdForStableFunding" | "thresholdForDecreaseFunding" | "minFundingFactorPerSecond" | "maxFundingFactorPerSecond" | "minPositionImpactPoolAmount" | "positionImpactPoolDistributionRate" | "minCollateralFactor" | "minCollateralFactorForOpenInterestLong" | "minCollateralFactorForOpenInterestShort" | "maxPnlFactorForTradersLong" | "maxPnlFactorForTradersShort" | "positionFeeFactorForPositiveImpact" | "positionFeeFactorForNegativeImpact" | "positionImpactFactorPositive" | "positionImpactFactorNegative" | "maxPositionImpactFactorPositive" | "maxPositionImpactFactorNegative" | "maxPositionImpactFactorForLiquidations" | "positionImpactExponentFactor" | "swapFeeFactorForPositiveImpact" | "swapFeeFactorForNegativeImpact" | "swapImpactFactorPositive" | "swapImpactFactorNegative" | "swapImpactExponentFactor" | "virtualMarketId" | "virtualLongTokenId" | "virtualShortTokenId", {
35
+ calls: Record<"maxFundingFactorPerSecond" | "isDisabled" | "maxLongPoolAmount" | "maxShortPoolAmount" | "maxLongPoolUsdForDeposit" | "maxShortPoolUsdForDeposit" | "longPoolAmountAdjustment" | "shortPoolAmountAdjustment" | "reserveFactorLong" | "reserveFactorShort" | "openInterestReserveFactorLong" | "openInterestReserveFactorShort" | "maxOpenInterestLong" | "maxOpenInterestShort" | "borrowingFactorLong" | "borrowingFactorShort" | "borrowingExponentFactorLong" | "borrowingExponentFactorShort" | "fundingFactor" | "fundingExponentFactor" | "fundingIncreaseFactorPerSecond" | "fundingDecreaseFactorPerSecond" | "thresholdForStableFunding" | "thresholdForDecreaseFunding" | "minFundingFactorPerSecond" | "minPositionImpactPoolAmount" | "positionImpactPoolDistributionRate" | "minCollateralFactor" | "minCollateralFactorForOpenInterestLong" | "minCollateralFactorForOpenInterestShort" | "maxPnlFactorForTradersLong" | "maxPnlFactorForTradersShort" | "positionFeeFactorForPositiveImpact" | "positionFeeFactorForNegativeImpact" | "positionImpactFactorPositive" | "positionImpactFactorNegative" | "maxPositionImpactFactorPositive" | "maxPositionImpactFactorNegative" | "maxPositionImpactFactorForLiquidations" | "positionImpactExponentFactor" | "swapFeeFactorForPositiveImpact" | "swapFeeFactorForNegativeImpact" | "swapImpactFactorPositive" | "swapImpactFactorNegative" | "swapImpactExponentFactor" | "virtualMarketId" | "virtualLongTokenId" | "virtualShortTokenId", {
36
36
  methodName: string;
37
37
  params: any[];
38
38
  }>;
@@ -50,7 +50,7 @@ export async function buildMarketsValuesRequest(chainId, { marketsAddresses, mar
50
50
  const marketPrices = getContractMarketPrices(tokensData, market);
51
51
  if (!marketPrices) {
52
52
  // eslint-disable-next-line no-console
53
- console.warn("missed market prices", market);
53
+ console.warn(`No market prices for ${marketAddress}, skipping market values request`);
54
54
  continue;
55
55
  }
56
56
  const marketProps = {
@@ -11,7 +11,10 @@ export type MarketsInfoResult = {
11
11
  tokensData?: TokensData;
12
12
  pricesUpdatedAt?: number;
13
13
  };
14
- export type MarketValues = Pick<MarketInfo, "longInterestUsd" | "shortInterestUsd" | "longInterestInTokens" | "shortInterestInTokens" | "longPoolAmount" | "shortPoolAmount" | "poolValueMin" | "poolValueMax" | "totalBorrowingFees" | "positionImpactPoolAmount" | "swapImpactPoolAmountLong" | "swapImpactPoolAmountShort" | "pnlLongMax" | "pnlLongMin" | "pnlShortMax" | "pnlShortMin" | "netPnlMax" | "netPnlMin" | "borrowingFactorPerSecondForLongs" | "borrowingFactorPerSecondForShorts" | "fundingFactorPerSecond" | "longsPayShorts" | "virtualPoolAmountForLongToken" | "virtualPoolAmountForShortToken" | "virtualInventoryForPositions">;
14
+ /**
15
+ * Updates frequently
16
+ */
17
+ export type MarketValues = Pick<MarketInfo, "longInterestUsd" | "shortInterestUsd" | "longInterestInTokens" | "shortInterestInTokens" | "longPoolAmount" | "shortPoolAmount" | "poolValueMin" | "poolValueMax" | "totalBorrowingFees" | "positionImpactPoolAmount" | "swapImpactPoolAmountLong" | "swapImpactPoolAmountShort" | "borrowingFactorPerSecondForLongs" | "borrowingFactorPerSecondForShorts" | "fundingFactorPerSecond" | "longsPayShorts" | "virtualPoolAmountForLongToken" | "virtualPoolAmountForShortToken" | "virtualInventoryForPositions">;
15
18
  /**
16
19
  * Updates seldom
17
20
  */
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from "vitest";
1
2
  import { arbitrumSdk } from "../../utils/testUtil";
2
3
  describe("Positions", () => {
3
4
  describe("read", () => {
@@ -16,7 +16,7 @@ export const getOrderExecutionFee = (sdk, swapsCount, decreasePositionSwapType,
16
16
  swapsCount: swapsCount ?? 0,
17
17
  });
18
18
  const oraclePriceCount = estimateOrderOraclePriceCount(swapsCount);
19
- return getExecutionFee(sdk, gasLimits, tokensData, estimatedGas, gasPrice, oraclePriceCount);
19
+ return getExecutionFee(sdk.chainId, gasLimits, tokensData, estimatedGas, gasPrice, oraclePriceCount);
20
20
  };
21
21
  export const getExecutionFeeAmountForEntry = (sdk, entry, gasLimits, tokensData, gasPrice) => {
22
22
  if (!entry.txnType || entry.txnType === "cancel")
@@ -18,8 +18,8 @@ export declare class Positions extends Module {
18
18
  private getKeysAndPricesParams;
19
19
  private getPositionsData;
20
20
  getPositions(p: {
21
- marketsInfoData: MarketsData | undefined;
22
- tokensData: TokensData | undefined;
21
+ marketsData: MarketsData;
22
+ tokensData: TokensData;
23
23
  start?: number;
24
24
  end?: number;
25
25
  }): Promise<PositionsResult>;
@@ -4,7 +4,7 @@ import ReferralStorage from "../../abis/ReferralStorage.json";
4
4
  import SyntheticsReader from "../../abis/SyntheticsReader.json";
5
5
  import { getContract } from "../../configs/contracts";
6
6
  import { hashedPositionKey, MAX_AUTO_CANCEL_ORDERS_KEY, MIN_COLLATERAL_USD_KEY, MIN_POSITION_SIZE_USD_KEY, uiFeeFactorKey, } from "../../configs/dataStore";
7
- import { getContractMarketPrices, getMaxAllowedLeverageByMinCollateralFactor } from "../../utils/markets";
7
+ import { getContractMarketPrices, getMarketIndexName, getMarketPoolName, getMaxAllowedLeverageByMinCollateralFactor, } from "../../utils/markets";
8
8
  import { getByKey } from "../../utils/objects";
9
9
  import { getEntryPrice, getLeverage, getLiquidationPrice, getPositionKey, getPositionNetValue, getPositionPnlUsd, } from "../../utils/positions";
10
10
  import { Module } from "../base";
@@ -20,17 +20,17 @@ export class Positions extends Module {
20
20
  this._positionsConstants = undefined;
21
21
  }
22
22
  getKeysAndPricesParams(p) {
23
- const { marketsInfoData, tokensData } = p;
23
+ const { marketsData, tokensData } = p;
24
24
  const account = this.account;
25
25
  const values = {
26
26
  allPositionsKeys: [],
27
27
  marketsPrices: [],
28
28
  marketsKeys: [],
29
29
  };
30
- if (!account || !marketsInfoData || !tokensData) {
30
+ if (!account || !marketsData || !tokensData) {
31
31
  return values;
32
32
  }
33
- const markets = Object.values(marketsInfoData);
33
+ const markets = Object.values(marketsData);
34
34
  for (const market of markets) {
35
35
  const marketPrices = getContractMarketPrices(tokensData, market);
36
36
  if (!marketPrices || market.isSpotOnly) {
@@ -97,11 +97,11 @@ export class Positions extends Module {
97
97
  const positions = await this.sdk.executeMulticall(request).then((res) => {
98
98
  const positions = res.data.reader.positions.returnValues;
99
99
  return positions.reduce((positionsMap, positionInfo) => {
100
- const { position, fees } = positionInfo;
100
+ const { position, fees, basePnlUsd } = positionInfo;
101
101
  const { addresses, numbers, flags, data } = position;
102
102
  const { account, market: marketAddress, collateralToken: collateralTokenAddress } = addresses;
103
103
  // Empty position
104
- if (BigInt(numbers.increasedAtTime) == 0n) {
104
+ if (numbers.increasedAtTime == 0n) {
105
105
  return positionsMap;
106
106
  }
107
107
  const positionKey = getPositionKey(account, marketAddress, collateralTokenAddress, flags.isLong);
@@ -122,6 +122,10 @@ export class Positions extends Module {
122
122
  fundingFeeAmount: fees.funding.fundingFeeAmount,
123
123
  claimableLongTokenAmount: fees.funding.claimableLongTokenAmount,
124
124
  claimableShortTokenAmount: fees.funding.claimableShortTokenAmount,
125
+ pnl: basePnlUsd,
126
+ positionFeeAmount: fees.positionFeeAmount,
127
+ traderDiscountAmount: fees.referral.traderDiscountAmount,
128
+ uiFeeAmount: fees.ui.uiFeeAmount,
125
129
  data,
126
130
  };
127
131
  return positionsMap;
@@ -367,7 +371,7 @@ export class Positions extends Module {
367
371
  async getPositionsInfo(p) {
368
372
  const { showPnlInLeverage, marketsInfoData, tokensData } = p;
369
373
  const { positionsData } = await this.getPositions({
370
- marketsInfoData,
374
+ marketsData: marketsInfoData,
371
375
  tokensData,
372
376
  });
373
377
  const { minCollateralUsd } = await this.getPositionsConstants();
@@ -380,9 +384,11 @@ export class Positions extends Module {
380
384
  const position = getByKey(positionsData, positionKey);
381
385
  const marketInfo = getByKey(marketsInfoData, position.marketAddress);
382
386
  const indexToken = marketInfo?.indexToken;
387
+ const longToken = getByKey(tokensData, marketInfo?.longTokenAddress);
388
+ const shortToken = getByKey(tokensData, marketInfo?.shortTokenAddress);
383
389
  const pnlToken = position.isLong ? marketInfo?.longToken : marketInfo?.shortToken;
384
390
  const collateralToken = getByKey(tokensData, position.collateralTokenAddress);
385
- if (!marketInfo || !indexToken || !pnlToken || !collateralToken) {
391
+ if (!marketInfo || !indexToken || !pnlToken || !collateralToken || !longToken || !shortToken) {
386
392
  return acc;
387
393
  }
388
394
  const markPrice = getMarkPrice({ prices: indexToken.prices, isLong: position.isLong, isIncrease: false });
@@ -454,12 +460,19 @@ export class Positions extends Module {
454
460
  pendingFundingFeesUsd,
455
461
  isLong: position.isLong,
456
462
  });
463
+ const indexName = getMarketIndexName({ indexToken, isSpotOnly: false });
464
+ const poolName = getMarketPoolName({ longToken, shortToken });
457
465
  acc[positionKey] = {
458
466
  ...position,
467
+ market: marketInfo,
459
468
  marketInfo,
469
+ indexName,
470
+ poolName,
460
471
  indexToken,
461
472
  collateralToken,
462
473
  pnlToken,
474
+ longToken,
475
+ shortToken,
463
476
  markPrice,
464
477
  entryPrice,
465
478
  liquidationPrice,
@@ -1,4 +1,5 @@
1
1
  import { arbitrumSdk } from "../../utils/testUtil";
2
+ import { describe, expect, it } from "vitest";
2
3
  describe("Positions", () => {
3
4
  describe("getPositions", () => {
4
5
  it("should be able to get positions data", async () => {
@@ -6,7 +7,7 @@ describe("Positions", () => {
6
7
  if (!tokensData || !marketsInfoData) {
7
8
  throw new Error("Tokens data or markets info is not available");
8
9
  }
9
- const positions = await arbitrumSdk.positions.getPositions({ tokensData, marketsInfoData });
10
+ const positions = await arbitrumSdk.positions.getPositions({ tokensData, marketsData: marketsInfoData });
10
11
  expect(positions).toBeDefined();
11
12
  });
12
13
  it("should be able to get positions info", async () => {
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from "vitest";
1
2
  import { GmxSdk } from "../..";
2
3
  import { arbitrumSdk, arbitrumSdkConfig } from "../../utils/testUtil";
3
4
  describe("Tokens", () => {
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from "vitest";
1
2
  import { arbitrumSdk } from "../../utils/testUtil";
2
3
  describe("Trades", () => {
3
4
  it("should be able to get positions", async () => {
@@ -1,4 +1,4 @@
1
- import type { IncreasePositionAmounts } from "../../types/amounts";
1
+ import type { IncreasePositionAmounts } from "../../types/trade";
2
2
  import type { GasLimitsConfig } from "../../types/fees";
3
3
  import type { DecreasePositionAmounts, SwapAmounts, TradeFeesType } from "../../types/trade";
4
4
  import { TokensData } from "../../types/tokens";
@@ -157,7 +157,7 @@ export class Utils extends Module {
157
157
  if (gasPrice === undefined)
158
158
  return undefined;
159
159
  const oraclePriceCount = estimateOrderOraclePriceCount(swapsCount);
160
- return getExecutionFee(this.sdk, gasLimits, tokensData, estimatedGas, gasPrice, oraclePriceCount);
160
+ return getExecutionFee(this.chainId, gasLimits, tokensData, estimatedGas, gasPrice, oraclePriceCount);
161
161
  }
162
162
  async getGasPrice() {
163
163
  const executionFeeConfig = EXECUTION_FEE_CONFIG_V2[this.chainId];
@@ -479,6 +479,70 @@
479
479
  "baseBorrowingFactorShort": "0x488ad2e07ed1c47aa04dd86e97f77426c6197bfa6cff17a8b805a1cd15dd2d90",
480
480
  "aboveOptimalUsageBorrowingFactorLong": "0x09bb0347a83fe3a7c85be68bdd48acc437af0a5df63af4d71f89958060a5183b",
481
481
  "aboveOptimalUsageBorrowingFactorShort": "0xf537f2f92d9f7d503800034e53ed5df8212d23c932b380ad03aa870876595a35"
482
+ },
483
+ "0x467C4A46287F6C4918dDF780D4fd7b46419c2291": {
484
+ "optimalUsageFactorLong": "0x964962aaee802042c5a9840c0ccec35a3c08b7c3a99b7acec279fdfd6d0f5602",
485
+ "optimalUsageFactorShort": "0x9497c0e6a7adc621b90db81d6d028f6f5b1583b345b578cfcc4833e7d1279906",
486
+ "baseBorrowingFactorLong": "0x1640108e55e6399e5b8517089cb4f7862284b1a447a5547af7daa4aa0f6f164c",
487
+ "baseBorrowingFactorShort": "0x3c5f5cf695ab4f79a081f2a1136a0fd87e68f0a2c119db8c2805f8ca0ece90c6",
488
+ "aboveOptimalUsageBorrowingFactorLong": "0x5e9f8c8af639f59403d5633aefaa65be94ee1ac99b0910b200b02283d34f2e85",
489
+ "aboveOptimalUsageBorrowingFactorShort": "0x278832c9b87471c0f856e3f31aa6f860be363c8ebaa0397627c85081e39b12fc"
490
+ },
491
+ "0x16466a03449CB9218EB6A980Aa4a44aaCEd27C25": {
492
+ "optimalUsageFactorLong": "0x9e8b87143824c5582617f91611124f33711bb42d4018d803aa1d9450ad89043d",
493
+ "optimalUsageFactorShort": "0xaddecfb296f8550d3cbdbe1b9d83a97c06ff83f1fbd39396ff2ac28b43671a66",
494
+ "baseBorrowingFactorLong": "0x5537e1948501ad11928dc214dc0d165620884e871e9cbbcf5bc4ce6144ff3a11",
495
+ "baseBorrowingFactorShort": "0xc756628a72705a8f2ba1b0737509bc1e2e38afc2559cf5369c055de4e159007d",
496
+ "aboveOptimalUsageBorrowingFactorLong": "0xc60421377286117683d89fd5d15804d8e99a3d162b76d2bf5b70c22b1342f0cb",
497
+ "aboveOptimalUsageBorrowingFactorShort": "0x408b169f8bb5ede6252afb6fc2febaf67d40eb8856da18f261c616a86f65d233"
498
+ },
499
+ "0xFec8f404FBCa3b11aFD3b3f0c57507C2a06dE636": {
500
+ "optimalUsageFactorLong": "0xb0bbe375e4a0501194eb24c6d72a6e1485a2fc7a71a3ba2210452efc231ce057",
501
+ "optimalUsageFactorShort": "0x9f2221ea701bbe10945f600b466ed40242c81f78347b6bb09f44d7d2f3890a37",
502
+ "baseBorrowingFactorLong": "0x2e95da37022c244a6d69eb66549f0a98ec05b21cc542e91d1f96ef352d9cd076",
503
+ "baseBorrowingFactorShort": "0x2e2b3ae8ca19b0139b5ff461e52810bdae6e3994baf60c61d60db402bf0a4406",
504
+ "aboveOptimalUsageBorrowingFactorLong": "0x77b2d3054c40f15792ca1cf076c931172af3d568fed4f7e5ad53e20072d45b5f",
505
+ "aboveOptimalUsageBorrowingFactorShort": "0x1c89eecfb665a04121de2af51dfe78fe9aecf9c8882b0f9a418cee6a7ed94958"
506
+ },
507
+ "0x12fD1A4BdB96219E637180Ff5293409502b2951D": {
508
+ "optimalUsageFactorLong": "0x479fdcf30b5a854aba48b6691930693cbee17e30a881b7f8e48a1bfecb3dd864",
509
+ "optimalUsageFactorShort": "0x53e8dcac5f6deb6fe5ae5a88615623bf66ade2f16a3c2825b9ad64417737bc35",
510
+ "baseBorrowingFactorLong": "0x6e0a8720c61c3e59b5da2275b93dfb83970df9aa5a1acede764d15e6994b28cb",
511
+ "baseBorrowingFactorShort": "0x67ff5c4e5943c164dcef85b16fc224f121483949ff19eef16ee873bb9ef0576b",
512
+ "aboveOptimalUsageBorrowingFactorLong": "0xa2fdc799365df5bd5e1c044b5794dab5e068d0477767fffee9ef8e8467d40ae8",
513
+ "aboveOptimalUsageBorrowingFactorShort": "0xd537c4a116ec4b7c4208d06b1fd1ecab101a8383bfeeb397df76173d2a7d9cb4"
514
+ },
515
+ "0x9F159014CC218e942E9E9481742fE5BFa9ac5A2C": {
516
+ "optimalUsageFactorLong": "0x23d964c7f529332c527b32496d2c7584043bcb4a032c84a4a0d1928a8ed16ea8",
517
+ "optimalUsageFactorShort": "0x82eca7ce02a1cc911dbaaf1c1ee6cd9b9988d5183b463f98547fd9f8ba42e355",
518
+ "baseBorrowingFactorLong": "0xd72ad88d228a8f07e39f354ed72fcb630aec2409bd1e0af6986ca41045e14200",
519
+ "baseBorrowingFactorShort": "0x16f6b247f7bf2ee09645fa83cc36b5aa463d55aa0447d7f51b2479fdb4e2ec45",
520
+ "aboveOptimalUsageBorrowingFactorLong": "0xece909a3ef5682c0d9d37820c7d1784bb27446df836612338ecf1ed24c853c82",
521
+ "aboveOptimalUsageBorrowingFactorShort": "0x4514eb5674c6c7d4cd73f6964e8060c240feab38036e8e7a8f759be8e48a2f0f"
522
+ },
523
+ "0xD60f1BA6a76979eFfE706BF090372Ebc0A5bF169": {
524
+ "optimalUsageFactorLong": "0x55658eac170e10c6f18135229a5cd852ddbe9379e57b941b6a1bf4e25ef2b4bb",
525
+ "optimalUsageFactorShort": "0x31e32683757b51cd2eedb16b4237745fa64400ce3abfac1893d3e2d8ce47d554",
526
+ "baseBorrowingFactorLong": "0x928867d35ecfb7bddf91974c2353c54236c57c3d577d8178a2491792e7d18d0e",
527
+ "baseBorrowingFactorShort": "0x7a8c6c03f5296a37c3cd0c79575ce4a504312306517afb9c59e5d54060e21904",
528
+ "aboveOptimalUsageBorrowingFactorLong": "0x54a980fd43d2e55afc8be3887d69bcdd0e8549f174179079e6d959e221c62d92",
529
+ "aboveOptimalUsageBorrowingFactorShort": "0x4a3089b46f753b101fd2a53d57d690ac834487a47bb46ec5023ef9f98ca1fdfc"
530
+ },
531
+ "0x5707673D95a8fD317e2745C4217aCD64ca021B68": {
532
+ "optimalUsageFactorLong": "0xb0e47d3696191eb5be864851a04aeb5e6a0795e4d0196e51011449cb96b01faf",
533
+ "optimalUsageFactorShort": "0x7224a50d83d1bf9108f22e4c8df0c88af24c0ddc817e6af8f7f75ad0c7192b57",
534
+ "baseBorrowingFactorLong": "0x6107b04045c786d2f7c8adf1d3a20f6bf44da36930aadbc2ae2feefb52fb08b5",
535
+ "baseBorrowingFactorShort": "0xb9b472fd43ea13bb65376f593ada49267d44656b95b776b37498b2ef4cbab468",
536
+ "aboveOptimalUsageBorrowingFactorLong": "0x731a32303b33745516ec459821d85db78020e88f324927ab62bbce07e075f932",
537
+ "aboveOptimalUsageBorrowingFactorShort": "0x128931b8e124b9d6f88ce1b5c577f88347d62b2e6497db4ac5478004cbc6d990"
538
+ },
539
+ "0xe2730Ffe2136aA549327EBce93D58160df7821CB": {
540
+ "optimalUsageFactorLong": "0xc6b9442f62e4f55eb5fe1e04ba7396adb90e9c8a43c1b0e9e70b018028eb2c8f",
541
+ "optimalUsageFactorShort": "0x7e396f9ce3f43a358d0cb5f64499c0d67edeb3c7bd98458e2e3e74cffeb0b49c",
542
+ "baseBorrowingFactorLong": "0xdc1930499a55e33e556accdab5044862e5e9e78e992fdd2f5afdebb74403630a",
543
+ "baseBorrowingFactorShort": "0xe4d0f172b0c6812c375dd191721e9dc46fdd36f37ff90d3bf6a6e935b4c6a199",
544
+ "aboveOptimalUsageBorrowingFactorLong": "0x04cb2b6b6235deede58442bb4611047e5e0b592694f577eb5c1eec6e759a98dc",
545
+ "aboveOptimalUsageBorrowingFactorShort": "0xd7565150af4992698334b8aca479724f8ad2d8a8de5822d46f743df2ea396c12"
482
546
  }
483
547
  },
484
548
  "43113": {
@@ -755,6 +819,22 @@
755
819
  "baseBorrowingFactorShort": "0xbb7ec07c70a28de1cbbe5372353ce2ae56214bd8d4df7cfb88f5292d0fd8e986",
756
820
  "aboveOptimalUsageBorrowingFactorLong": "0x2d50e2fd7aa7c1a800871f76bf798880937acdefef831df2ab8b70ad119054a9",
757
821
  "aboveOptimalUsageBorrowingFactorShort": "0x1f38479f355604bf3afbc9b8c1386261eae99dfa180bc7b42c7002f5b9823d08"
822
+ },
823
+ "0xfB626c4e3E153947A6A94041814c25E449064dAD": {
824
+ "optimalUsageFactorLong": "0xc19685baf2f3c11e34a2ea899bf5e2076744a533454dceabac8a0de4d84d454a",
825
+ "optimalUsageFactorShort": "0xc68a6bdbdd4367d1bc718e959d704f212865848fa6649aa24fb80dc9fdedecaf",
826
+ "baseBorrowingFactorLong": "0xe9d576a976cd7f8c7f910e89167e8d500f259b82884772d13989c1ab381905b6",
827
+ "baseBorrowingFactorShort": "0xfd5fb2feee66aff94676d715ab29959330117afcdf3611a0fb980a4f6a19e093",
828
+ "aboveOptimalUsageBorrowingFactorLong": "0x385cfbaddf7c612dc705c771a6e5b624ee4864e7136c2ea934422fa1db893563",
829
+ "aboveOptimalUsageBorrowingFactorShort": "0x57605e0c3285622481bd93af6fef15b512c931b5db53b9a072c8d86dd6621c6a"
830
+ },
831
+ "0xe19da27Bf9733c429445E289B662bECDCa6ce10b": {
832
+ "optimalUsageFactorLong": "0xd1ab5e55b2308a1fc00f0a4dcfa2bec105ae69918cf2032de077717e35624e27",
833
+ "optimalUsageFactorShort": "0xdf7b1d9202e4bb2e7abb6a573cc70593772b89fa9a7e9bad4e139938666044a9",
834
+ "baseBorrowingFactorLong": "0x3241b54354e87d5ae06a41e4aeaa6a34115dadf063d9621f814b2e11099307c8",
835
+ "baseBorrowingFactorShort": "0x3755d19ffde034f5b43c13d0b7904191836ca26a80930493bba489db125153f9",
836
+ "aboveOptimalUsageBorrowingFactorLong": "0x80a3a0af00d7c7d55e7bfffde6bc8ea69b652dafd94d7ebe4f20b2a4cdb7537b",
837
+ "aboveOptimalUsageBorrowingFactorShort": "0xe08a60ae243116c5d4e8f5c2df48367eb2edac52889485b82e216877ffb4ff34"
758
838
  }
759
839
  }
760
840
  }