@d8x/perpetuals-sdk 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2926,6 +2926,127 @@
2926
2926
  "stateMutability": "view",
2927
2927
  "type": "function"
2928
2928
  },
2929
+ {
2930
+ "inputs": [
2931
+ {
2932
+ "internalType": "uint8",
2933
+ "name": "_poolIdFrom",
2934
+ "type": "uint8"
2935
+ },
2936
+ {
2937
+ "internalType": "uint8",
2938
+ "name": "_poolIdTo",
2939
+ "type": "uint8"
2940
+ }
2941
+ ],
2942
+ "name": "getLiquidityPools",
2943
+ "outputs": [
2944
+ {
2945
+ "components": [
2946
+ {
2947
+ "internalType": "bool",
2948
+ "name": "isRunning",
2949
+ "type": "bool"
2950
+ },
2951
+ {
2952
+ "internalType": "uint8",
2953
+ "name": "iPerpetualCount",
2954
+ "type": "uint8"
2955
+ },
2956
+ {
2957
+ "internalType": "uint8",
2958
+ "name": "id",
2959
+ "type": "uint8"
2960
+ },
2961
+ {
2962
+ "internalType": "uint16",
2963
+ "name": "iTargetPoolSizeUpdateTime",
2964
+ "type": "uint16"
2965
+ },
2966
+ {
2967
+ "internalType": "address",
2968
+ "name": "marginTokenAddress",
2969
+ "type": "address"
2970
+ },
2971
+ {
2972
+ "internalType": "int128",
2973
+ "name": "fFundAllocationNormalizationCC",
2974
+ "type": "int128"
2975
+ },
2976
+ {
2977
+ "internalType": "int128",
2978
+ "name": "fDefaultFundCashCC",
2979
+ "type": "int128"
2980
+ },
2981
+ {
2982
+ "internalType": "uint64",
2983
+ "name": "prevAnchor",
2984
+ "type": "uint64"
2985
+ },
2986
+ {
2987
+ "internalType": "int32",
2988
+ "name": "fRedemptionRate",
2989
+ "type": "int32"
2990
+ },
2991
+ {
2992
+ "internalType": "address",
2993
+ "name": "shareTokenAddress",
2994
+ "type": "address"
2995
+ },
2996
+ {
2997
+ "internalType": "int128",
2998
+ "name": "fPnLparticipantsCashCC",
2999
+ "type": "int128"
3000
+ },
3001
+ {
3002
+ "internalType": "int128",
3003
+ "name": "fAMMFundCashCC",
3004
+ "type": "int128"
3005
+ },
3006
+ {
3007
+ "internalType": "int128",
3008
+ "name": "fTargetAMMFundSize",
3009
+ "type": "int128"
3010
+ },
3011
+ {
3012
+ "internalType": "int128",
3013
+ "name": "fTargetDFSize",
3014
+ "type": "int128"
3015
+ },
3016
+ {
3017
+ "internalType": "int128",
3018
+ "name": "fMaxTransferPerConvergencePeriod",
3019
+ "type": "int128"
3020
+ },
3021
+ {
3022
+ "internalType": "int128",
3023
+ "name": "fBrokerCollateralLotSize",
3024
+ "type": "int128"
3025
+ },
3026
+ {
3027
+ "internalType": "uint128",
3028
+ "name": "prevTokenAmount",
3029
+ "type": "uint128"
3030
+ },
3031
+ {
3032
+ "internalType": "uint128",
3033
+ "name": "nextTokenAmount",
3034
+ "type": "uint128"
3035
+ },
3036
+ {
3037
+ "internalType": "uint128",
3038
+ "name": "totalSupplyShareToken",
3039
+ "type": "uint128"
3040
+ }
3041
+ ],
3042
+ "internalType": "struct PerpStorage.LiquidityPoolData[]",
3043
+ "name": "",
3044
+ "type": "tuple[]"
3045
+ }
3046
+ ],
3047
+ "stateMutability": "view",
3048
+ "type": "function"
3049
+ },
2929
3050
  {
2930
3051
  "inputs": [
2931
3052
  {
@@ -3502,6 +3623,289 @@
3502
3623
  "stateMutability": "view",
3503
3624
  "type": "function"
3504
3625
  },
3626
+ {
3627
+ "inputs": [
3628
+ {
3629
+ "internalType": "uint24[]",
3630
+ "name": "perpetualIds",
3631
+ "type": "uint24[]"
3632
+ }
3633
+ ],
3634
+ "name": "getPerpetuals",
3635
+ "outputs": [
3636
+ {
3637
+ "components": [
3638
+ {
3639
+ "internalType": "uint8",
3640
+ "name": "poolId",
3641
+ "type": "uint8"
3642
+ },
3643
+ {
3644
+ "internalType": "uint24",
3645
+ "name": "id",
3646
+ "type": "uint24"
3647
+ },
3648
+ {
3649
+ "internalType": "int32",
3650
+ "name": "fInitialMarginRate",
3651
+ "type": "int32"
3652
+ },
3653
+ {
3654
+ "internalType": "int32",
3655
+ "name": "fMaintenanceMarginRate",
3656
+ "type": "int32"
3657
+ },
3658
+ {
3659
+ "internalType": "int32",
3660
+ "name": "fSigma2",
3661
+ "type": "int32"
3662
+ },
3663
+ {
3664
+ "internalType": "uint64",
3665
+ "name": "iLastFundingTime",
3666
+ "type": "uint64"
3667
+ },
3668
+ {
3669
+ "internalType": "uint64",
3670
+ "name": "iLastSettlementPriceUpdateTimestamp",
3671
+ "type": "uint64"
3672
+ },
3673
+ {
3674
+ "internalType": "enum PerpStorage.PerpetualState",
3675
+ "name": "state",
3676
+ "type": "uint8"
3677
+ },
3678
+ {
3679
+ "internalType": "enum AMMPerpLogic.CollateralCurrency",
3680
+ "name": "eCollateralCurrency",
3681
+ "type": "uint8"
3682
+ },
3683
+ {
3684
+ "internalType": "uint16",
3685
+ "name": "minimalSpreadTbps",
3686
+ "type": "uint16"
3687
+ },
3688
+ {
3689
+ "internalType": "uint16",
3690
+ "name": "incentiveSpreadTbps",
3691
+ "type": "uint16"
3692
+ },
3693
+ {
3694
+ "internalType": "uint16",
3695
+ "name": "jumpSpreadTbps",
3696
+ "type": "uint16"
3697
+ },
3698
+ {
3699
+ "internalType": "uint16",
3700
+ "name": "liquidationPenaltyRateTbps",
3701
+ "type": "uint16"
3702
+ },
3703
+ {
3704
+ "internalType": "int32",
3705
+ "name": "fSigma3",
3706
+ "type": "int32"
3707
+ },
3708
+ {
3709
+ "internalType": "bytes4",
3710
+ "name": "S2BaseCCY",
3711
+ "type": "bytes4"
3712
+ },
3713
+ {
3714
+ "internalType": "bytes4",
3715
+ "name": "S2QuoteCCY",
3716
+ "type": "bytes4"
3717
+ },
3718
+ {
3719
+ "internalType": "bytes4",
3720
+ "name": "S3BaseCCY",
3721
+ "type": "bytes4"
3722
+ },
3723
+ {
3724
+ "internalType": "bytes4",
3725
+ "name": "S3QuoteCCY",
3726
+ "type": "bytes4"
3727
+ },
3728
+ {
3729
+ "components": [
3730
+ {
3731
+ "internalType": "int128",
3732
+ "name": "fPrice",
3733
+ "type": "int128"
3734
+ },
3735
+ {
3736
+ "internalType": "uint64",
3737
+ "name": "time",
3738
+ "type": "uint64"
3739
+ }
3740
+ ],
3741
+ "internalType": "struct PerpStorage.OraclePriceData",
3742
+ "name": "currentMarkPremiumRate",
3743
+ "type": "tuple"
3744
+ },
3745
+ {
3746
+ "internalType": "int128[2]",
3747
+ "name": "fDFLambda",
3748
+ "type": "int128[2]"
3749
+ },
3750
+ {
3751
+ "internalType": "int128[2]",
3752
+ "name": "fCurrentAMMExposureEMA",
3753
+ "type": "int128[2]"
3754
+ },
3755
+ {
3756
+ "internalType": "int128[2]",
3757
+ "name": "fAMMTargetDD",
3758
+ "type": "int128[2]"
3759
+ },
3760
+ {
3761
+ "internalType": "int128[2]",
3762
+ "name": "fStressReturnS2",
3763
+ "type": "int128[2]"
3764
+ },
3765
+ {
3766
+ "internalType": "int128[2]",
3767
+ "name": "fStressReturnS3",
3768
+ "type": "int128[2]"
3769
+ },
3770
+ {
3771
+ "internalType": "int128",
3772
+ "name": "premiumRatesEMA",
3773
+ "type": "int128"
3774
+ },
3775
+ {
3776
+ "internalType": "int128",
3777
+ "name": "fTargetDFSize",
3778
+ "type": "int128"
3779
+ },
3780
+ {
3781
+ "internalType": "int128",
3782
+ "name": "fFundAllocationWeightCC",
3783
+ "type": "int128"
3784
+ },
3785
+ {
3786
+ "internalType": "int128",
3787
+ "name": "fOpenInterest",
3788
+ "type": "int128"
3789
+ },
3790
+ {
3791
+ "internalType": "int128",
3792
+ "name": "fTargetAMMFundSize",
3793
+ "type": "int128"
3794
+ },
3795
+ {
3796
+ "internalType": "int128",
3797
+ "name": "fCurrentTraderExposureEMA",
3798
+ "type": "int128"
3799
+ },
3800
+ {
3801
+ "internalType": "int128",
3802
+ "name": "fCurrentFundingRate",
3803
+ "type": "int128"
3804
+ },
3805
+ {
3806
+ "internalType": "int128",
3807
+ "name": "fUnitAccumulatedFunding",
3808
+ "type": "int128"
3809
+ },
3810
+ {
3811
+ "internalType": "int128",
3812
+ "name": "fLotSizeBC",
3813
+ "type": "int128"
3814
+ },
3815
+ {
3816
+ "internalType": "int128",
3817
+ "name": "fkStar",
3818
+ "type": "int128"
3819
+ },
3820
+ {
3821
+ "internalType": "int128",
3822
+ "name": "fAMMFundCashCC",
3823
+ "type": "int128"
3824
+ },
3825
+ {
3826
+ "internalType": "int128",
3827
+ "name": "fAMMMinSizeCC",
3828
+ "type": "int128"
3829
+ },
3830
+ {
3831
+ "internalType": "int128",
3832
+ "name": "fMinimalTraderExposureEMA",
3833
+ "type": "int128"
3834
+ },
3835
+ {
3836
+ "internalType": "int128",
3837
+ "name": "fMinimalAMMExposureEMA",
3838
+ "type": "int128"
3839
+ },
3840
+ {
3841
+ "internalType": "int128",
3842
+ "name": "fTotalMarginBalance",
3843
+ "type": "int128"
3844
+ },
3845
+ {
3846
+ "internalType": "int128",
3847
+ "name": "fSettlementS3PriceData",
3848
+ "type": "int128"
3849
+ },
3850
+ {
3851
+ "internalType": "int128",
3852
+ "name": "fReferralRebateCC",
3853
+ "type": "int128"
3854
+ },
3855
+ {
3856
+ "internalType": "int128",
3857
+ "name": "fSettlementS2PriceData",
3858
+ "type": "int128"
3859
+ },
3860
+ {
3861
+ "internalType": "uint64",
3862
+ "name": "iLastPriceJumpTimestamp",
3863
+ "type": "uint64"
3864
+ },
3865
+ {
3866
+ "internalType": "uint64",
3867
+ "name": "iLastDefaultFundTransfer",
3868
+ "type": "uint64"
3869
+ },
3870
+ {
3871
+ "internalType": "uint64",
3872
+ "name": "iLastTargetPoolSizeTime",
3873
+ "type": "uint64"
3874
+ },
3875
+ {
3876
+ "internalType": "int32",
3877
+ "name": "fMarkPriceEMALambda",
3878
+ "type": "int32"
3879
+ },
3880
+ {
3881
+ "internalType": "int32",
3882
+ "name": "fFundingRateClamp",
3883
+ "type": "int32"
3884
+ },
3885
+ {
3886
+ "internalType": "int32",
3887
+ "name": "fMaximalTradeSizeBumpUp",
3888
+ "type": "int32"
3889
+ },
3890
+ {
3891
+ "internalType": "int32",
3892
+ "name": "fRho23",
3893
+ "type": "int32"
3894
+ },
3895
+ {
3896
+ "internalType": "int32",
3897
+ "name": "fDFCoverNRate",
3898
+ "type": "int32"
3899
+ }
3900
+ ],
3901
+ "internalType": "struct PerpStorage.PerpetualData[]",
3902
+ "name": "",
3903
+ "type": "tuple[]"
3904
+ }
3905
+ ],
3906
+ "stateMutability": "view",
3907
+ "type": "function"
3908
+ },
3505
3909
  {
3506
3910
  "inputs": [],
3507
3911
  "name": "getPoolCount",
@@ -4199,6 +4603,30 @@
4199
4603
  "stateMutability": "view",
4200
4604
  "type": "function"
4201
4605
  },
4606
+ {
4607
+ "inputs": [
4608
+ {
4609
+ "internalType": "uint24[]",
4610
+ "name": "perpetualIds",
4611
+ "type": "uint24[]"
4612
+ },
4613
+ {
4614
+ "internalType": "int128[]",
4615
+ "name": "idxPriceDataPairs",
4616
+ "type": "int128[]"
4617
+ }
4618
+ ],
4619
+ "name": "queryMidPrices",
4620
+ "outputs": [
4621
+ {
4622
+ "internalType": "int128[]",
4623
+ "name": "",
4624
+ "type": "int128[]"
4625
+ }
4626
+ ],
4627
+ "stateMutability": "view",
4628
+ "type": "function"
4629
+ },
4202
4630
  {
4203
4631
  "inputs": [
4204
4632
  {
@@ -305,5 +305,24 @@ export default class MarketData extends PerpetualDataHandler {
305
305
  * @returns a loyality score (4 worst, 1 best)
306
306
  */
307
307
  getTraderLoyalityScore(traderAddr: string, brokerAddr?: string): Promise<number>;
308
- static _exchangeInfo(_proxyContract: ethers.Contract, _poolStaticInfos: Array<PoolStaticInfo>, _symbolToPerpStaticInfo: Map<string, PerpetualStaticInfo>, _nestedPerpetualIDs: Array<Array<number>>, _symbolList: Map<string, string>, _priceFeedGetter: PriceFeeds): Promise<ExchangeInfo>;
308
+ /**
309
+ * Get all off-chain prices
310
+ * @param _symbolToPerpStaticInfo mapping: PerpetualStaticInfo for each perpetual
311
+ * @param _priceFeedGetter priceFeed class from which we can get offchain price data
312
+ * @returns mapping of symbol-pair (e.g. BTC-USD) to price/isMarketClosed
313
+ */
314
+ private static _getAllIndexPrices;
315
+ /**
316
+ * Collect all mid-prices
317
+ * @param _proxyContract contract instance
318
+ * @param _nestedPerpetualIDs contains all perpetual ids for each pool
319
+ * @param _symbolToPerpStaticInfo maps symbol to static info
320
+ * @param _perpetualIdToSymbol maps perpetual id to symbol of the form BTC-USD-MATIC
321
+ * @param _idxPriceMap symbol to price/market closed
322
+ * @returns perpetual symbol to mid-prices mapping
323
+ */
324
+ private static _queryMidPrices;
325
+ private static _queryPoolStates;
326
+ private static _queryPerpetualStates;
327
+ static _exchangeInfo(_proxyContract: ethers.Contract, _poolStaticInfos: Array<PoolStaticInfo>, _symbolToPerpStaticInfo: Map<string, PerpetualStaticInfo>, _perpetualIdToSymbol: Map<number, string>, _nestedPerpetualIDs: Array<Array<number>>, _symbolList: Map<string, string>, _priceFeedGetter: PriceFeeds): Promise<ExchangeInfo>;
309
328
  }