@gmx-io/sdk 2.2.1 → 2.3.2

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 (31) hide show
  1. package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +32 -0
  2. package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +272 -0
  3. package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +60 -0
  4. package/build/cjs/src/configs/markets.js +28 -0
  5. package/build/cjs/src/test/mock.js +32 -4
  6. package/build/cjs/src/utils/markets/utils.js +45 -1
  7. package/build/cjs/src/utils/trade/__tests__/increaseMarginCheck.spec.js +14 -35
  8. package/build/cjs/src/utils/trade/__tests__/twapIncreaseMarginCheck.spec.js +368 -0
  9. package/build/cjs/src/utils/trade/increaseMarginCheck.js +27 -13
  10. package/build/cjs/src/utils/trade/twapIncreaseMarginCheck.js +180 -0
  11. package/build/cjs/src/utils/twap/index.js +13 -4
  12. package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +32 -0
  13. package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +272 -0
  14. package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +60 -0
  15. package/build/esm/src/configs/markets.js +28 -0
  16. package/build/esm/src/test/mock.js +27 -0
  17. package/build/esm/src/utils/markets/utils.js +44 -1
  18. package/build/esm/src/utils/trade/__tests__/increaseMarginCheck.spec.js +15 -36
  19. package/build/esm/src/utils/trade/__tests__/twapIncreaseMarginCheck.spec.js +366 -0
  20. package/build/esm/src/utils/trade/increaseMarginCheck.js +24 -11
  21. package/build/esm/src/utils/trade/twapIncreaseMarginCheck.js +172 -0
  22. package/build/esm/src/utils/twap/index.js +10 -3
  23. package/build/tsconfig.tsbuildinfo +1 -1
  24. package/build/types/src/codegen/prebuilt/index.d.ts +364 -0
  25. package/build/types/src/test/mock.d.ts +5 -0
  26. package/build/types/src/utils/markets/utils.d.ts +3 -0
  27. package/build/types/src/utils/trade/__tests__/twapIncreaseMarginCheck.spec.d.ts +1 -0
  28. package/build/types/src/utils/trade/increaseMarginCheck.d.ts +15 -7
  29. package/build/types/src/utils/trade/twapIncreaseMarginCheck.d.ts +50 -0
  30. package/build/types/src/utils/twap/index.d.ts +2 -0
  31. package/package.json +10 -1
@@ -1952,6 +1952,66 @@ export declare const HASHED_MARKET_VALUES_KEYS: {
1952
1952
  shortInterestInTokensUsingLongToken: string;
1953
1953
  shortInterestInTokensUsingShortToken: string;
1954
1954
  };
1955
+ "0x54bc430A788DFFD4ae35e751E10899489f5a953f": {
1956
+ longPoolAmount: string;
1957
+ shortPoolAmount: string;
1958
+ positionImpactPoolAmount: string;
1959
+ swapImpactPoolAmountLong: string;
1960
+ swapImpactPoolAmountShort: string;
1961
+ longInterestUsingLongToken: string;
1962
+ longInterestUsingShortToken: string;
1963
+ shortInterestUsingLongToken: string;
1964
+ shortInterestUsingShortToken: string;
1965
+ longInterestInTokensUsingLongToken: string;
1966
+ longInterestInTokensUsingShortToken: string;
1967
+ shortInterestInTokensUsingLongToken: string;
1968
+ shortInterestInTokensUsingShortToken: string;
1969
+ };
1970
+ "0xc9ED746D613eEfC0F196658f6030e90482593004": {
1971
+ longPoolAmount: string;
1972
+ shortPoolAmount: string;
1973
+ positionImpactPoolAmount: string;
1974
+ swapImpactPoolAmountLong: string;
1975
+ swapImpactPoolAmountShort: string;
1976
+ longInterestUsingLongToken: string;
1977
+ longInterestUsingShortToken: string;
1978
+ shortInterestUsingLongToken: string;
1979
+ shortInterestUsingShortToken: string;
1980
+ longInterestInTokensUsingLongToken: string;
1981
+ longInterestInTokensUsingShortToken: string;
1982
+ shortInterestInTokensUsingLongToken: string;
1983
+ shortInterestInTokensUsingShortToken: string;
1984
+ };
1985
+ "0x2CeEafcA180B07C9d1d2f1086f8f59AAFd282832": {
1986
+ longPoolAmount: string;
1987
+ shortPoolAmount: string;
1988
+ positionImpactPoolAmount: string;
1989
+ swapImpactPoolAmountLong: string;
1990
+ swapImpactPoolAmountShort: string;
1991
+ longInterestUsingLongToken: string;
1992
+ longInterestUsingShortToken: string;
1993
+ shortInterestUsingLongToken: string;
1994
+ shortInterestUsingShortToken: string;
1995
+ longInterestInTokensUsingLongToken: string;
1996
+ longInterestInTokensUsingShortToken: string;
1997
+ shortInterestInTokensUsingLongToken: string;
1998
+ shortInterestInTokensUsingShortToken: string;
1999
+ };
2000
+ "0x162C091263fBb3dfAf1D55DCC979533EB341DA5f": {
2001
+ longPoolAmount: string;
2002
+ shortPoolAmount: string;
2003
+ positionImpactPoolAmount: string;
2004
+ swapImpactPoolAmountLong: string;
2005
+ swapImpactPoolAmountShort: string;
2006
+ longInterestUsingLongToken: string;
2007
+ longInterestUsingShortToken: string;
2008
+ shortInterestUsingLongToken: string;
2009
+ shortInterestUsingShortToken: string;
2010
+ longInterestInTokensUsingLongToken: string;
2011
+ longInterestInTokensUsingShortToken: string;
2012
+ shortInterestInTokensUsingLongToken: string;
2013
+ shortInterestInTokensUsingShortToken: string;
2014
+ };
1955
2015
  };
1956
2016
  "43113": {
1957
2017
  "0xD996ff47A1F763E1e55415BC4437c59292D1F415": {
@@ -11509,6 +11569,278 @@ export declare const HASHED_MARKET_CONFIG_KEYS: {
11509
11569
  virtualLongTokenId: string;
11510
11570
  virtualShortTokenId: string;
11511
11571
  };
11572
+ "0x54bc430A788DFFD4ae35e751E10899489f5a953f": {
11573
+ isDisabled: string;
11574
+ maxLongPoolAmount: string;
11575
+ maxShortPoolAmount: string;
11576
+ maxLongPoolUsdForDeposit: string;
11577
+ maxShortPoolUsdForDeposit: string;
11578
+ reserveFactorLong: string;
11579
+ reserveFactorShort: string;
11580
+ openInterestReserveFactorLong: string;
11581
+ openInterestReserveFactorShort: string;
11582
+ maxOpenInterestLong: string;
11583
+ maxOpenInterestShort: string;
11584
+ maxCollateralSumLongTokenLong: string;
11585
+ maxCollateralSumLongTokenShort: string;
11586
+ maxCollateralSumShortTokenLong: string;
11587
+ maxCollateralSumShortTokenShort: string;
11588
+ minPositionImpactPoolAmount: string;
11589
+ positionImpactPoolDistributionRate: string;
11590
+ borrowingFactorLong: string;
11591
+ borrowingFactorShort: string;
11592
+ borrowingExponentFactorLong: string;
11593
+ borrowingExponentFactorShort: string;
11594
+ fundingFactor: string;
11595
+ fundingExponentFactor: string;
11596
+ fundingIncreaseFactorPerSecond: string;
11597
+ minFundingIncreaseRatePerSecond: string;
11598
+ fundingDecreaseFactorPerSecond: string;
11599
+ thresholdForStableFunding: string;
11600
+ thresholdForDecreaseFunding: string;
11601
+ minFundingFactorPerSecondLong: string;
11602
+ minFundingFactorPerSecondShort: string;
11603
+ maxFundingFactorPerSecondLong: string;
11604
+ maxFundingFactorPerSecondShort: string;
11605
+ maxPnlFactorForTradersLong: string;
11606
+ maxPnlFactorForTradersShort: string;
11607
+ maxPnlFactorForDepositsLong: string;
11608
+ maxPnlFactorForDepositsShort: string;
11609
+ maxPnlFactorForWithdrawalsLong: string;
11610
+ maxPnlFactorForWithdrawalsShort: string;
11611
+ positionFeeFactorForBalanceWasImproved: string;
11612
+ positionFeeFactorForBalanceWasNotImproved: string;
11613
+ positionImpactFactorPositive: string;
11614
+ positionImpactFactorNegative: string;
11615
+ maxPositionImpactFactorPositive: string;
11616
+ maxPositionImpactFactorNegative: string;
11617
+ maxPositionImpactFactorForLiquidations: string;
11618
+ maxLendableImpactFactor: string;
11619
+ maxLendableImpactFactorForWithdrawals: string;
11620
+ maxLendableImpactUsd: string;
11621
+ lentPositionImpactPoolAmount: string;
11622
+ minCollateralFactor: string;
11623
+ minCollateralFactorForLiquidation: string;
11624
+ minCollateralFactorForOpenInterestLong: string;
11625
+ minCollateralFactorForOpenInterestShort: string;
11626
+ positionImpactExponentFactorPositive: string;
11627
+ positionImpactExponentFactorNegative: string;
11628
+ swapFeeFactorForBalanceWasImproved: string;
11629
+ swapFeeFactorForBalanceWasNotImproved: string;
11630
+ atomicSwapFeeFactor: string;
11631
+ swapImpactFactorPositive: string;
11632
+ swapImpactFactorNegative: string;
11633
+ swapImpactExponentFactor: string;
11634
+ withdrawalFeeFactorBalanceWasImproved: string;
11635
+ withdrawalFeeFactorBalanceWasNotImproved: string;
11636
+ virtualMarketId: string;
11637
+ virtualLongTokenId: string;
11638
+ virtualShortTokenId: string;
11639
+ };
11640
+ "0xc9ED746D613eEfC0F196658f6030e90482593004": {
11641
+ isDisabled: string;
11642
+ maxLongPoolAmount: string;
11643
+ maxShortPoolAmount: string;
11644
+ maxLongPoolUsdForDeposit: string;
11645
+ maxShortPoolUsdForDeposit: string;
11646
+ reserveFactorLong: string;
11647
+ reserveFactorShort: string;
11648
+ openInterestReserveFactorLong: string;
11649
+ openInterestReserveFactorShort: string;
11650
+ maxOpenInterestLong: string;
11651
+ maxOpenInterestShort: string;
11652
+ maxCollateralSumLongTokenLong: string;
11653
+ maxCollateralSumLongTokenShort: string;
11654
+ maxCollateralSumShortTokenLong: string;
11655
+ maxCollateralSumShortTokenShort: string;
11656
+ minPositionImpactPoolAmount: string;
11657
+ positionImpactPoolDistributionRate: string;
11658
+ borrowingFactorLong: string;
11659
+ borrowingFactorShort: string;
11660
+ borrowingExponentFactorLong: string;
11661
+ borrowingExponentFactorShort: string;
11662
+ fundingFactor: string;
11663
+ fundingExponentFactor: string;
11664
+ fundingIncreaseFactorPerSecond: string;
11665
+ minFundingIncreaseRatePerSecond: string;
11666
+ fundingDecreaseFactorPerSecond: string;
11667
+ thresholdForStableFunding: string;
11668
+ thresholdForDecreaseFunding: string;
11669
+ minFundingFactorPerSecondLong: string;
11670
+ minFundingFactorPerSecondShort: string;
11671
+ maxFundingFactorPerSecondLong: string;
11672
+ maxFundingFactorPerSecondShort: string;
11673
+ maxPnlFactorForTradersLong: string;
11674
+ maxPnlFactorForTradersShort: string;
11675
+ maxPnlFactorForDepositsLong: string;
11676
+ maxPnlFactorForDepositsShort: string;
11677
+ maxPnlFactorForWithdrawalsLong: string;
11678
+ maxPnlFactorForWithdrawalsShort: string;
11679
+ positionFeeFactorForBalanceWasImproved: string;
11680
+ positionFeeFactorForBalanceWasNotImproved: string;
11681
+ positionImpactFactorPositive: string;
11682
+ positionImpactFactorNegative: string;
11683
+ maxPositionImpactFactorPositive: string;
11684
+ maxPositionImpactFactorNegative: string;
11685
+ maxPositionImpactFactorForLiquidations: string;
11686
+ maxLendableImpactFactor: string;
11687
+ maxLendableImpactFactorForWithdrawals: string;
11688
+ maxLendableImpactUsd: string;
11689
+ lentPositionImpactPoolAmount: string;
11690
+ minCollateralFactor: string;
11691
+ minCollateralFactorForLiquidation: string;
11692
+ minCollateralFactorForOpenInterestLong: string;
11693
+ minCollateralFactorForOpenInterestShort: string;
11694
+ positionImpactExponentFactorPositive: string;
11695
+ positionImpactExponentFactorNegative: string;
11696
+ swapFeeFactorForBalanceWasImproved: string;
11697
+ swapFeeFactorForBalanceWasNotImproved: string;
11698
+ atomicSwapFeeFactor: string;
11699
+ swapImpactFactorPositive: string;
11700
+ swapImpactFactorNegative: string;
11701
+ swapImpactExponentFactor: string;
11702
+ withdrawalFeeFactorBalanceWasImproved: string;
11703
+ withdrawalFeeFactorBalanceWasNotImproved: string;
11704
+ virtualMarketId: string;
11705
+ virtualLongTokenId: string;
11706
+ virtualShortTokenId: string;
11707
+ };
11708
+ "0x2CeEafcA180B07C9d1d2f1086f8f59AAFd282832": {
11709
+ isDisabled: string;
11710
+ maxLongPoolAmount: string;
11711
+ maxShortPoolAmount: string;
11712
+ maxLongPoolUsdForDeposit: string;
11713
+ maxShortPoolUsdForDeposit: string;
11714
+ reserveFactorLong: string;
11715
+ reserveFactorShort: string;
11716
+ openInterestReserveFactorLong: string;
11717
+ openInterestReserveFactorShort: string;
11718
+ maxOpenInterestLong: string;
11719
+ maxOpenInterestShort: string;
11720
+ maxCollateralSumLongTokenLong: string;
11721
+ maxCollateralSumLongTokenShort: string;
11722
+ maxCollateralSumShortTokenLong: string;
11723
+ maxCollateralSumShortTokenShort: string;
11724
+ minPositionImpactPoolAmount: string;
11725
+ positionImpactPoolDistributionRate: string;
11726
+ borrowingFactorLong: string;
11727
+ borrowingFactorShort: string;
11728
+ borrowingExponentFactorLong: string;
11729
+ borrowingExponentFactorShort: string;
11730
+ fundingFactor: string;
11731
+ fundingExponentFactor: string;
11732
+ fundingIncreaseFactorPerSecond: string;
11733
+ minFundingIncreaseRatePerSecond: string;
11734
+ fundingDecreaseFactorPerSecond: string;
11735
+ thresholdForStableFunding: string;
11736
+ thresholdForDecreaseFunding: string;
11737
+ minFundingFactorPerSecondLong: string;
11738
+ minFundingFactorPerSecondShort: string;
11739
+ maxFundingFactorPerSecondLong: string;
11740
+ maxFundingFactorPerSecondShort: string;
11741
+ maxPnlFactorForTradersLong: string;
11742
+ maxPnlFactorForTradersShort: string;
11743
+ maxPnlFactorForDepositsLong: string;
11744
+ maxPnlFactorForDepositsShort: string;
11745
+ maxPnlFactorForWithdrawalsLong: string;
11746
+ maxPnlFactorForWithdrawalsShort: string;
11747
+ positionFeeFactorForBalanceWasImproved: string;
11748
+ positionFeeFactorForBalanceWasNotImproved: string;
11749
+ positionImpactFactorPositive: string;
11750
+ positionImpactFactorNegative: string;
11751
+ maxPositionImpactFactorPositive: string;
11752
+ maxPositionImpactFactorNegative: string;
11753
+ maxPositionImpactFactorForLiquidations: string;
11754
+ maxLendableImpactFactor: string;
11755
+ maxLendableImpactFactorForWithdrawals: string;
11756
+ maxLendableImpactUsd: string;
11757
+ lentPositionImpactPoolAmount: string;
11758
+ minCollateralFactor: string;
11759
+ minCollateralFactorForLiquidation: string;
11760
+ minCollateralFactorForOpenInterestLong: string;
11761
+ minCollateralFactorForOpenInterestShort: string;
11762
+ positionImpactExponentFactorPositive: string;
11763
+ positionImpactExponentFactorNegative: string;
11764
+ swapFeeFactorForBalanceWasImproved: string;
11765
+ swapFeeFactorForBalanceWasNotImproved: string;
11766
+ atomicSwapFeeFactor: string;
11767
+ swapImpactFactorPositive: string;
11768
+ swapImpactFactorNegative: string;
11769
+ swapImpactExponentFactor: string;
11770
+ withdrawalFeeFactorBalanceWasImproved: string;
11771
+ withdrawalFeeFactorBalanceWasNotImproved: string;
11772
+ virtualMarketId: string;
11773
+ virtualLongTokenId: string;
11774
+ virtualShortTokenId: string;
11775
+ };
11776
+ "0x162C091263fBb3dfAf1D55DCC979533EB341DA5f": {
11777
+ isDisabled: string;
11778
+ maxLongPoolAmount: string;
11779
+ maxShortPoolAmount: string;
11780
+ maxLongPoolUsdForDeposit: string;
11781
+ maxShortPoolUsdForDeposit: string;
11782
+ reserveFactorLong: string;
11783
+ reserveFactorShort: string;
11784
+ openInterestReserveFactorLong: string;
11785
+ openInterestReserveFactorShort: string;
11786
+ maxOpenInterestLong: string;
11787
+ maxOpenInterestShort: string;
11788
+ maxCollateralSumLongTokenLong: string;
11789
+ maxCollateralSumLongTokenShort: string;
11790
+ maxCollateralSumShortTokenLong: string;
11791
+ maxCollateralSumShortTokenShort: string;
11792
+ minPositionImpactPoolAmount: string;
11793
+ positionImpactPoolDistributionRate: string;
11794
+ borrowingFactorLong: string;
11795
+ borrowingFactorShort: string;
11796
+ borrowingExponentFactorLong: string;
11797
+ borrowingExponentFactorShort: string;
11798
+ fundingFactor: string;
11799
+ fundingExponentFactor: string;
11800
+ fundingIncreaseFactorPerSecond: string;
11801
+ minFundingIncreaseRatePerSecond: string;
11802
+ fundingDecreaseFactorPerSecond: string;
11803
+ thresholdForStableFunding: string;
11804
+ thresholdForDecreaseFunding: string;
11805
+ minFundingFactorPerSecondLong: string;
11806
+ minFundingFactorPerSecondShort: string;
11807
+ maxFundingFactorPerSecondLong: string;
11808
+ maxFundingFactorPerSecondShort: string;
11809
+ maxPnlFactorForTradersLong: string;
11810
+ maxPnlFactorForTradersShort: string;
11811
+ maxPnlFactorForDepositsLong: string;
11812
+ maxPnlFactorForDepositsShort: string;
11813
+ maxPnlFactorForWithdrawalsLong: string;
11814
+ maxPnlFactorForWithdrawalsShort: string;
11815
+ positionFeeFactorForBalanceWasImproved: string;
11816
+ positionFeeFactorForBalanceWasNotImproved: string;
11817
+ positionImpactFactorPositive: string;
11818
+ positionImpactFactorNegative: string;
11819
+ maxPositionImpactFactorPositive: string;
11820
+ maxPositionImpactFactorNegative: string;
11821
+ maxPositionImpactFactorForLiquidations: string;
11822
+ maxLendableImpactFactor: string;
11823
+ maxLendableImpactFactorForWithdrawals: string;
11824
+ maxLendableImpactUsd: string;
11825
+ lentPositionImpactPoolAmount: string;
11826
+ minCollateralFactor: string;
11827
+ minCollateralFactorForLiquidation: string;
11828
+ minCollateralFactorForOpenInterestLong: string;
11829
+ minCollateralFactorForOpenInterestShort: string;
11830
+ positionImpactExponentFactorPositive: string;
11831
+ positionImpactExponentFactorNegative: string;
11832
+ swapFeeFactorForBalanceWasImproved: string;
11833
+ swapFeeFactorForBalanceWasNotImproved: string;
11834
+ atomicSwapFeeFactor: string;
11835
+ swapImpactFactorPositive: string;
11836
+ swapImpactFactorNegative: string;
11837
+ swapImpactExponentFactor: string;
11838
+ withdrawalFeeFactorBalanceWasImproved: string;
11839
+ withdrawalFeeFactorBalanceWasNotImproved: string;
11840
+ virtualMarketId: string;
11841
+ virtualLongTokenId: string;
11842
+ virtualShortTokenId: string;
11843
+ };
11512
11844
  };
11513
11845
  "43113": {
11514
11846
  "0xD996ff47A1F763E1e55415BC4437c59292D1F415": {
@@ -15757,6 +16089,38 @@ export declare const HASHED_KINK_MODEL_MARKET_RATES_KEYS: {
15757
16089
  aboveOptimalUsageBorrowingFactorLong: string;
15758
16090
  aboveOptimalUsageBorrowingFactorShort: string;
15759
16091
  };
16092
+ "0x54bc430A788DFFD4ae35e751E10899489f5a953f": {
16093
+ optimalUsageFactorLong: string;
16094
+ optimalUsageFactorShort: string;
16095
+ baseBorrowingFactorLong: string;
16096
+ baseBorrowingFactorShort: string;
16097
+ aboveOptimalUsageBorrowingFactorLong: string;
16098
+ aboveOptimalUsageBorrowingFactorShort: string;
16099
+ };
16100
+ "0xc9ED746D613eEfC0F196658f6030e90482593004": {
16101
+ optimalUsageFactorLong: string;
16102
+ optimalUsageFactorShort: string;
16103
+ baseBorrowingFactorLong: string;
16104
+ baseBorrowingFactorShort: string;
16105
+ aboveOptimalUsageBorrowingFactorLong: string;
16106
+ aboveOptimalUsageBorrowingFactorShort: string;
16107
+ };
16108
+ "0x2CeEafcA180B07C9d1d2f1086f8f59AAFd282832": {
16109
+ optimalUsageFactorLong: string;
16110
+ optimalUsageFactorShort: string;
16111
+ baseBorrowingFactorLong: string;
16112
+ baseBorrowingFactorShort: string;
16113
+ aboveOptimalUsageBorrowingFactorLong: string;
16114
+ aboveOptimalUsageBorrowingFactorShort: string;
16115
+ };
16116
+ "0x162C091263fBb3dfAf1D55DCC979533EB341DA5f": {
16117
+ optimalUsageFactorLong: string;
16118
+ optimalUsageFactorShort: string;
16119
+ baseBorrowingFactorLong: string;
16120
+ baseBorrowingFactorShort: string;
16121
+ aboveOptimalUsageBorrowingFactorLong: string;
16122
+ aboveOptimalUsageBorrowingFactorShort: string;
16123
+ };
15760
16124
  };
15761
16125
  "43113": {
15762
16126
  "0xD996ff47A1F763E1e55415BC4437c59292D1F415": {
@@ -10,6 +10,11 @@ export declare function mockTokensData(overrides?: {
10
10
  * @param marketKeys - array of market keys in the following format: indexToken-longToken-shortToken
11
11
  */
12
12
  export { mockMarketsData, mockMarketsInfoData } from "../utils/markets/__tests__/mockMarkets";
13
+ /**
14
+ * A BTC market with a 1% min collateral factor (100x) and 0.5% for liquidation.
15
+ * Fees, price impact and open interest are off unless overridden.
16
+ */
17
+ export declare function mockMarginCheckMarketInfo(tokensData: TokensData, overrides?: Record<string, bigint | boolean>): import("../utils/markets").MarketInfo;
13
18
  export declare function mockExternalSwap({ inToken, outToken, amountIn, amountOut, priceIn, priceOut, feesUsd, // $5 default fee
14
19
  data, to, receiver, }: {
15
20
  inToken: Token;
@@ -2,6 +2,7 @@ import type { ContractsChainId } from "../../configs/chains";
2
2
  import { type MarketConfig as ConfigMarketConfig } from "../../configs/markets";
3
3
  import type { DayPriceCandle } from "../24h/types";
4
4
  import type { Token, TokenPrices, TokensData } from "../tokens/types";
5
+ import type { SwapStats } from "../trade/types";
5
6
  import type { ClaimableFundingData, ContractMarketPrices, Market, MarketConfig, MarketInfo, MarketsData, MarketsInfoData, MarketTicker, MarketValues, MarketWithTiers, RawMarketConfig, RawMarketInfo, RawMarketsInfoData, RawMarketValues } from "./types";
6
7
  export declare function getMarketFullName(p: {
7
8
  longToken: Token;
@@ -84,6 +85,8 @@ export declare function getMarketInfoWithOpenInterestDelta({ marketInfo, collate
84
85
  sizeDeltaUsd: bigint;
85
86
  sizeDeltaInTokens: bigint;
86
87
  }): MarketInfo;
88
+ /** The market a swap step leaves: the pools and the swap impact pools move as in `SwapUtils._swap`. */
89
+ export declare function getMarketInfoWithSwapDelta(marketInfo: MarketInfo, swapStep: SwapStats): MarketInfo;
87
90
  export declare function getOpenInterestForBalance(marketInfo: MarketInfo, isLong: boolean): bigint;
88
91
  export declare function getPriceForPnl(prices: TokenPrices, isLong: boolean, maximize: boolean): bigint;
89
92
  export declare function getIsMarketAvailableForExpressSwaps(marketInfo: MarketInfo): boolean;
@@ -5,7 +5,8 @@ export declare enum PositionMarginFailureReason {
5
5
  MinCollateral = "min collateral",
6
6
  NonPositiveRemainingMargin = "< 0",
7
7
  MinCollateralForLeverage = "min collateral for leverage",
8
- InsufficientCollateralUsd = "insufficient collateral usd"
8
+ InsufficientCollateralUsd = "insufficient collateral usd",
9
+ MaxAllowedLeverage = "max allowed leverage"
9
10
  }
10
11
  export declare function getIsMaxLeverageMarginReason(reason: PositionMarginFailureReason | undefined): boolean;
11
12
  export type PositionMarginState = {
@@ -34,16 +35,17 @@ export type PositionMarginStateParams = {
34
35
  * after an increase.
35
36
  */
36
37
  export declare function getResultingPositionMarginState(p: PositionMarginStateParams): PositionMarginState;
38
+ export type IncreasePositionState = {
39
+ sizeInUsd: bigint;
40
+ sizeInTokens: bigint;
41
+ collateralAmount: bigint;
42
+ pendingImpactAmount: bigint;
43
+ };
37
44
  export type IncreaseResultingPositionMarginStateParams = {
38
45
  marketInfo: MarketInfo;
39
46
  collateralToken: TokenData;
40
47
  isLong: boolean;
41
- existingPosition: {
42
- sizeInUsd: bigint;
43
- sizeInTokens: bigint;
44
- collateralAmount: bigint;
45
- pendingImpactAmount: bigint;
46
- } | undefined;
48
+ existingPosition: IncreasePositionState | undefined;
47
49
  sizeDeltaUsd: bigint;
48
50
  sizeDeltaInTokens: bigint;
49
51
  collateralDeltaAmount: bigint;
@@ -52,6 +54,11 @@ export type IncreaseResultingPositionMarginStateParams = {
52
54
  proDiscountFactor?: bigint;
53
55
  indexPriceForEvaluation?: bigint;
54
56
  };
57
+ export type IncreaseResultingPositionState = {
58
+ marginState: PositionMarginState;
59
+ position: IncreasePositionState;
60
+ marketInfo: MarketInfo;
61
+ };
55
62
  /**
56
63
  * Mirrors the post-increase gates of `IncreasePositionUtils.increasePosition` from the gmx-synthetics
57
64
  * build deployed on Arbitrum (release_2.2.1 @ 23c9d160: release-v2.2c plus MarketUtils.getPositivePnl
@@ -59,3 +66,4 @@ export type IncreaseResultingPositionMarginStateParams = {
59
66
  * then `validatePosition` on the resulting position.
60
67
  */
61
68
  export declare function getIncreaseResultingPositionMarginState(p: IncreaseResultingPositionMarginStateParams): PositionMarginState | undefined;
69
+ export declare function getIncreaseResultingPositionState(p: IncreaseResultingPositionMarginStateParams): IncreaseResultingPositionState | undefined;
@@ -0,0 +1,50 @@
1
+ import { MarketInfo, MarketsInfoData } from "../markets/types";
2
+ import { UserReferralInfo } from "../referrals/types";
3
+ import { TokenData } from "../tokens/types";
4
+ import { IncreasePositionState, PositionMarginState } from "./increaseMarginCheck";
5
+ import { IncreasePositionAmounts } from "./types";
6
+ export type TwapIncreaseSequenceParams = {
7
+ numberOfParts: number;
8
+ partDelaysSeconds: number[];
9
+ partGrossCollateralUsds: bigint[];
10
+ };
11
+ export type TwapIncreaseAggregateAmounts = {
12
+ sizeDeltaUsd: bigint;
13
+ pendingFeesUsd: bigint;
14
+ };
15
+ export type TwapIncreasePartAmounts = {
16
+ partSizeDeltaUsd: bigint;
17
+ pendingFeesUsd: bigint;
18
+ };
19
+ export type TwapIncreasePartsCollateralParams = {
20
+ marketsInfoData: MarketsInfoData;
21
+ swapPath: string[];
22
+ initialCollateralToken: TokenData;
23
+ collateralToken: TokenData;
24
+ initialCollateralAmountPerPart: bigint;
25
+ numberOfParts: number;
26
+ uiFeeFactor: bigint;
27
+ wrappedNativeTokenAddress: string;
28
+ };
29
+ export type TwapIncreaseSequentialMarginStateParams = TwapIncreaseSequenceParams & TwapIncreasePartAmounts & {
30
+ marketInfo: MarketInfo;
31
+ collateralToken: TokenData;
32
+ isLong: boolean;
33
+ existingPosition: IncreasePositionState | undefined;
34
+ uiFeeFactor: bigint;
35
+ minCollateralUsd: bigint;
36
+ userReferralInfo: UserReferralInfo | undefined;
37
+ proDiscountFactor?: bigint;
38
+ };
39
+ export type TwapIncreaseSequentialMarginState = {
40
+ numberOfParts: number;
41
+ failingPartIndex: number | undefined;
42
+ isFailingPartEligibleNow: boolean;
43
+ marginState: PositionMarginState;
44
+ contractMarginState: PositionMarginState;
45
+ };
46
+ export declare function getTwapIncreaseAggregateAmounts(increaseAmounts: IncreasePositionAmounts): TwapIncreaseAggregateAmounts;
47
+ export declare function getTwapIncreasePartAmounts({ sizeDeltaUsd, pendingFeesUsd }: TwapIncreaseAggregateAmounts, numberOfParts: number): TwapIncreasePartAmounts;
48
+ export declare function getTwapIncreasePartsGrossCollateralUsd(p: TwapIncreasePartsCollateralParams): bigint[] | undefined;
49
+ export declare function getTwapIncreaseSequentialMarginState(p: TwapIncreaseSequentialMarginStateParams): TwapIncreaseSequentialMarginState | undefined;
50
+ export declare function getIsTwapIncreaseSequenceSafe(state: TwapIncreaseSequentialMarginState | undefined): boolean;
@@ -4,7 +4,9 @@ export * from "./types";
4
4
  export { UI_FEE_SOURCE_UI, UI_FEE_SOURCE_API } from "./uiFeeReceiver";
5
5
  export declare function getIsValidTwapParams(duration: TwapDuration, numberOfParts: number): boolean;
6
6
  export declare function getTwapDurationInSeconds(duration: TwapDuration): number;
7
+ export declare function getTwapPartDelaySeconds(duration: TwapDuration, numberOfParts: number, partIndex: number): number;
7
8
  export declare function getTwapValidFromTime(duration: TwapDuration, numberOfParts: number, partIndex: number): bigint;
9
+ export declare function getTwapPartDelaysSeconds(duration: TwapDuration, numberOfParts: number): number[];
8
10
  export declare function changeTwapNumberOfPartsValue(value: number): number;
9
11
  export declare function getTwapOrderKey({ twapId, orderType, pool, isLong, collateralTokenSymbol, swapPath, account, initialCollateralToken, }: {
10
12
  twapId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmx-io/sdk",
3
- "version": "2.2.1",
3
+ "version": "2.3.2",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -155,6 +155,9 @@
155
155
  ],
156
156
  "utils/gas/*": [
157
157
  "./build/types/src/utils/gas/*.d.ts"
158
+ ],
159
+ "utils/twap/uiFeeReceiver": [
160
+ "./build/types/src/utils/twap/uiFeeReceiver.d.ts"
158
161
  ]
159
162
  }
160
163
  },
@@ -488,6 +491,12 @@
488
491
  "import": "./build/esm/src/utils/gas/*.js",
489
492
  "require": "./build/cjs/src/utils/gas/*.js",
490
493
  "default": "./build/cjs/src/utils/gas/*.js"
494
+ },
495
+ "./utils/twap/uiFeeReceiver": {
496
+ "types": "./build/types/src/utils/twap/uiFeeReceiver.d.ts",
497
+ "import": "./build/esm/src/utils/twap/uiFeeReceiver.js",
498
+ "require": "./build/cjs/src/utils/twap/uiFeeReceiver.js",
499
+ "default": "./build/cjs/src/utils/twap/uiFeeReceiver.js"
491
500
  }
492
501
  },
493
502
  "scripts": {