@drift-labs/sdk 0.1.18-orders.1 → 0.1.18-orders.5

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 +2 -1
  2. package/lib/accounts/bulkAccountLoader.d.ts +31 -0
  3. package/lib/accounts/bulkAccountLoader.js +175 -0
  4. package/lib/accounts/bulkUserSubscription.d.ts +7 -0
  5. package/lib/accounts/bulkUserSubscription.js +28 -0
  6. package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +49 -0
  7. package/lib/accounts/pollingClearingHouseAccountSubscriber.js +228 -0
  8. package/lib/accounts/pollingTokenAccountSubscriber.d.ts +25 -0
  9. package/lib/accounts/pollingTokenAccountSubscriber.js +79 -0
  10. package/lib/accounts/pollingUserAccountSubscriber.d.ts +32 -0
  11. package/lib/accounts/pollingUserAccountSubscriber.js +136 -0
  12. package/lib/accounts/types.d.ts +34 -25
  13. package/lib/accounts/utils.d.ts +1 -0
  14. package/lib/accounts/utils.js +7 -0
  15. package/lib/accounts/webSocketAccountSubscriber.d.ts +6 -2
  16. package/lib/accounts/webSocketAccountSubscriber.js +43 -12
  17. package/lib/accounts/{defaultClearingHouseAccountSubscriber.d.ts → webSocketClearingHouseAccountSubscriber.d.ts} +6 -4
  18. package/lib/accounts/{defaultClearingHouseAccountSubscriber.js → webSocketClearingHouseAccountSubscriber.js} +5 -4
  19. package/lib/accounts/{defaultUserAccountSubscriber.d.ts → webSocketUserAccountSubscriber.d.ts} +3 -1
  20. package/lib/accounts/{defaultUserAccountSubscriber.js → webSocketUserAccountSubscriber.js} +10 -7
  21. package/lib/addresses.d.ts +2 -2
  22. package/lib/addresses.js +4 -4
  23. package/lib/admin.d.ts +3 -0
  24. package/lib/admin.js +61 -13
  25. package/lib/clearingHouse.d.ts +20 -4
  26. package/lib/clearingHouse.js +90 -10
  27. package/lib/clearingHouseUser.d.ts +12 -4
  28. package/lib/clearingHouseUser.js +35 -25
  29. package/lib/config.js +1 -1
  30. package/lib/constants/markets.d.ts +2 -1
  31. package/lib/constants/markets.js +35 -14
  32. package/lib/constants/numericConstants.d.ts +3 -1
  33. package/lib/constants/numericConstants.js +15 -17
  34. package/lib/examples/makeTradeExample.js +1 -1
  35. package/lib/factory/clearingHouse.d.ts +25 -0
  36. package/lib/factory/clearingHouse.js +64 -0
  37. package/lib/factory/clearingHouseUser.d.ts +19 -0
  38. package/lib/factory/clearingHouseUser.js +34 -0
  39. package/lib/idl/clearing_house.json +366 -17
  40. package/lib/index.d.ts +8 -3
  41. package/lib/index.js +9 -3
  42. package/lib/math/conversion.d.ts +1 -1
  43. package/lib/math/funding.js +4 -1
  44. package/lib/math/insuranceFund.d.ts +2 -1
  45. package/lib/math/insuranceFund.js +3 -6
  46. package/lib/math/position.d.ts +2 -1
  47. package/lib/math/position.js +2 -5
  48. package/lib/math/utils.d.ts +2 -1
  49. package/lib/math/utils.js +3 -3
  50. package/lib/mockUSDCFaucet.d.ts +2 -1
  51. package/lib/orderParams.d.ts +3 -3
  52. package/lib/orderParams.js +28 -8
  53. package/lib/orders.d.ts +3 -2
  54. package/lib/orders.js +8 -8
  55. package/lib/token/index.d.ts +3 -0
  56. package/lib/token/index.js +38 -0
  57. package/lib/types.d.ts +20 -8
  58. package/lib/types.js +2 -2
  59. package/package.json +11 -3
  60. package/src/accounts/bulkAccountLoader.ts +215 -0
  61. package/src/accounts/bulkUserSubscription.ts +28 -0
  62. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +326 -0
  63. package/src/accounts/pollingTokenAccountSubscriber.ts +99 -0
  64. package/src/accounts/pollingUserAccountSubscriber.ts +194 -0
  65. package/src/accounts/types.ts +40 -30
  66. package/src/accounts/utils.ts +3 -0
  67. package/src/accounts/webSocketAccountSubscriber.ts +67 -17
  68. package/src/accounts/{defaultClearingHouseAccountSubscriber.ts → webSocketClearingHouseAccountSubscriber.ts} +9 -6
  69. package/src/accounts/{defaultUserAccountSubscriber.ts → webSocketUserAccountSubscriber.ts} +10 -5
  70. package/src/addresses.ts +6 -4
  71. package/src/admin.ts +73 -20
  72. package/src/clearingHouse.ts +125 -25
  73. package/src/clearingHouseUser.ts +28 -8
  74. package/src/config.ts +1 -1
  75. package/src/constants/markets.ts +25 -1
  76. package/src/constants/numericConstants.ts +2 -1
  77. package/src/examples/makeTradeExample.ts +4 -1
  78. package/src/factory/clearingHouse.ts +125 -0
  79. package/src/factory/clearingHouseUser.ts +73 -0
  80. package/src/idl/clearing_house.json +366 -17
  81. package/src/index.ts +8 -3
  82. package/src/math/conversion.ts +1 -1
  83. package/src/math/funding.ts +5 -1
  84. package/src/math/insuranceFund.ts +1 -1
  85. package/src/math/position.ts +1 -1
  86. package/src/math/utils.ts +1 -1
  87. package/src/mockUSDCFaucet.ts +1 -1
  88. package/src/orderParams.ts +30 -7
  89. package/src/orders.ts +13 -7
  90. package/src/token/index.ts +37 -0
  91. package/src/types.ts +17 -6
  92. package/lib/accounts/defaultHistoryAccountSubscriber.d.ts +0 -28
  93. package/lib/accounts/defaultHistoryAccountSubscriber.js +0 -110
  94. package/src/accounts/defaultHistoryAccountSubscriber.ts +0 -176
@@ -0,0 +1,73 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+ import { ClearingHouse } from '../clearingHouse';
3
+ import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
4
+ import { ClearingHouseUser } from '../clearingHouseUser';
5
+ import { UserAccountSubscriber } from '../accounts/types';
6
+ import { WebSocketUserAccountSubscriber } from '../accounts/webSocketUserAccountSubscriber';
7
+ import { PollingUserAccountSubscriber } from '../accounts/pollingUserAccountSubscriber';
8
+
9
+ export type ClearingHouseUserConfigType = 'websocket' | 'polling' | 'custom';
10
+
11
+ type BaseClearingHouseUserConfig = {
12
+ type: ClearingHouseUserConfigType;
13
+ clearingHouse: ClearingHouse;
14
+ authority: PublicKey;
15
+ };
16
+
17
+ type WebSocketClearingHouseUserConfig = BaseClearingHouseUserConfig;
18
+
19
+ type PollingClearingHouseUserConfig = BaseClearingHouseUserConfig & {
20
+ accountLoader: BulkAccountLoader;
21
+ };
22
+
23
+ type ClearingHouseUserConfig =
24
+ | PollingClearingHouseUserConfig
25
+ | WebSocketClearingHouseUserConfig;
26
+
27
+ export function getWebSocketClearingHouseUserConfig(
28
+ clearingHouse: ClearingHouse,
29
+ authority: PublicKey
30
+ ): WebSocketClearingHouseUserConfig {
31
+ return {
32
+ type: 'websocket',
33
+ clearingHouse,
34
+ authority,
35
+ };
36
+ }
37
+
38
+ export function getPollingClearingHouseUserConfig(
39
+ clearingHouse: ClearingHouse,
40
+ authority: PublicKey,
41
+ accountLoader: BulkAccountLoader
42
+ ): PollingClearingHouseUserConfig {
43
+ return {
44
+ type: 'polling',
45
+ clearingHouse,
46
+ authority,
47
+ accountLoader,
48
+ };
49
+ }
50
+
51
+ export function getClearingHouseUser(
52
+ config: ClearingHouseUserConfig
53
+ ): ClearingHouseUser {
54
+ let accountSubscriber: UserAccountSubscriber;
55
+ if (config.type === 'websocket') {
56
+ accountSubscriber = new WebSocketUserAccountSubscriber(
57
+ config.clearingHouse.program,
58
+ config.authority
59
+ );
60
+ } else if (config.type === 'polling') {
61
+ accountSubscriber = new PollingUserAccountSubscriber(
62
+ config.clearingHouse.program,
63
+ config.authority,
64
+ (config as PollingClearingHouseUserConfig).accountLoader
65
+ );
66
+ }
67
+
68
+ return new ClearingHouseUser(
69
+ config.clearingHouse,
70
+ config.authority,
71
+ accountSubscriber
72
+ );
73
+ }
@@ -604,13 +604,69 @@
604
604
  ]
605
605
  },
606
606
  {
607
- "name": "fillOrder",
607
+ "name": "cancelOrderByUserId",
608
608
  "accounts": [
609
609
  {
610
610
  "name": "state",
611
+ "isMut": false,
612
+ "isSigner": false
613
+ },
614
+ {
615
+ "name": "orderState",
616
+ "isMut": false,
617
+ "isSigner": false
618
+ },
619
+ {
620
+ "name": "user",
621
+ "isMut": false,
622
+ "isSigner": false
623
+ },
624
+ {
625
+ "name": "authority",
626
+ "isMut": false,
627
+ "isSigner": true
628
+ },
629
+ {
630
+ "name": "markets",
611
631
  "isMut": true,
612
632
  "isSigner": false
613
633
  },
634
+ {
635
+ "name": "userPositions",
636
+ "isMut": true,
637
+ "isSigner": false
638
+ },
639
+ {
640
+ "name": "userOrders",
641
+ "isMut": true,
642
+ "isSigner": false
643
+ },
644
+ {
645
+ "name": "fundingPaymentHistory",
646
+ "isMut": true,
647
+ "isSigner": false
648
+ },
649
+ {
650
+ "name": "orderHistory",
651
+ "isMut": true,
652
+ "isSigner": false
653
+ }
654
+ ],
655
+ "args": [
656
+ {
657
+ "name": "userOrderId",
658
+ "type": "u8"
659
+ }
660
+ ]
661
+ },
662
+ {
663
+ "name": "fillOrder",
664
+ "accounts": [
665
+ {
666
+ "name": "state",
667
+ "isMut": false,
668
+ "isSigner": false
669
+ },
614
670
  {
615
671
  "name": "orderState",
616
672
  "isMut": false,
@@ -666,6 +722,11 @@
666
722
  "isMut": true,
667
723
  "isSigner": false
668
724
  },
725
+ {
726
+ "name": "extendedCurveHistory",
727
+ "isMut": true,
728
+ "isSigner": false
729
+ },
669
730
  {
670
731
  "name": "oracle",
671
732
  "isMut": false,
@@ -737,6 +798,11 @@
737
798
  "isMut": true,
738
799
  "isSigner": false
739
800
  },
801
+ {
802
+ "name": "extendedCurveHistory",
803
+ "isMut": true,
804
+ "isSigner": false
805
+ },
740
806
  {
741
807
  "name": "oracle",
742
808
  "isMut": false,
@@ -1043,6 +1109,78 @@
1043
1109
  }
1044
1110
  ]
1045
1111
  },
1112
+ {
1113
+ "name": "updateAmmOracleTwap",
1114
+ "accounts": [
1115
+ {
1116
+ "name": "state",
1117
+ "isMut": false,
1118
+ "isSigner": false
1119
+ },
1120
+ {
1121
+ "name": "markets",
1122
+ "isMut": true,
1123
+ "isSigner": false
1124
+ },
1125
+ {
1126
+ "name": "oracle",
1127
+ "isMut": false,
1128
+ "isSigner": false
1129
+ },
1130
+ {
1131
+ "name": "admin",
1132
+ "isMut": false,
1133
+ "isSigner": true
1134
+ },
1135
+ {
1136
+ "name": "curveHistory",
1137
+ "isMut": true,
1138
+ "isSigner": false
1139
+ }
1140
+ ],
1141
+ "args": [
1142
+ {
1143
+ "name": "marketIndex",
1144
+ "type": "u64"
1145
+ }
1146
+ ]
1147
+ },
1148
+ {
1149
+ "name": "resetAmmOracleTwap",
1150
+ "accounts": [
1151
+ {
1152
+ "name": "state",
1153
+ "isMut": false,
1154
+ "isSigner": false
1155
+ },
1156
+ {
1157
+ "name": "markets",
1158
+ "isMut": true,
1159
+ "isSigner": false
1160
+ },
1161
+ {
1162
+ "name": "oracle",
1163
+ "isMut": false,
1164
+ "isSigner": false
1165
+ },
1166
+ {
1167
+ "name": "admin",
1168
+ "isMut": false,
1169
+ "isSigner": true
1170
+ },
1171
+ {
1172
+ "name": "curveHistory",
1173
+ "isMut": true,
1174
+ "isSigner": false
1175
+ }
1176
+ ],
1177
+ "args": [
1178
+ {
1179
+ "name": "marketIndex",
1180
+ "type": "u64"
1181
+ }
1182
+ ]
1183
+ },
1046
1184
  {
1047
1185
  "name": "initializeUser",
1048
1186
  "accounts": [
@@ -1284,6 +1422,11 @@
1284
1422
  "isMut": true,
1285
1423
  "isSigner": false
1286
1424
  },
1425
+ {
1426
+ "name": "oracle",
1427
+ "isMut": false,
1428
+ "isSigner": false
1429
+ },
1287
1430
  {
1288
1431
  "name": "curveHistory",
1289
1432
  "isMut": true,
@@ -1301,6 +1444,32 @@
1301
1444
  }
1302
1445
  ]
1303
1446
  },
1447
+ {
1448
+ "name": "updateCurveHistory",
1449
+ "accounts": [
1450
+ {
1451
+ "name": "admin",
1452
+ "isMut": false,
1453
+ "isSigner": true
1454
+ },
1455
+ {
1456
+ "name": "state",
1457
+ "isMut": true,
1458
+ "isSigner": false
1459
+ },
1460
+ {
1461
+ "name": "extendedCurveHistory",
1462
+ "isMut": true,
1463
+ "isSigner": false
1464
+ },
1465
+ {
1466
+ "name": "curveHistory",
1467
+ "isMut": false,
1468
+ "isSigner": false
1469
+ }
1470
+ ],
1471
+ "args": []
1472
+ },
1304
1473
  {
1305
1474
  "name": "updateMarginRatio",
1306
1475
  "accounts": [
@@ -1771,7 +1940,7 @@
1771
1940
  "type": "u64"
1772
1941
  },
1773
1942
  {
1774
- "name": "depositRecords",
1943
+ "name": "curveRecords",
1775
1944
  "type": {
1776
1945
  "array": [
1777
1946
  {
@@ -1784,6 +1953,29 @@
1784
1953
  ]
1785
1954
  }
1786
1955
  },
1956
+ {
1957
+ "name": "ExtendedCurveHistory",
1958
+ "type": {
1959
+ "kind": "struct",
1960
+ "fields": [
1961
+ {
1962
+ "name": "head",
1963
+ "type": "u64"
1964
+ },
1965
+ {
1966
+ "name": "curveRecords",
1967
+ "type": {
1968
+ "array": [
1969
+ {
1970
+ "defined": "ExtendedCurveRecord"
1971
+ },
1972
+ 1024
1973
+ ]
1974
+ }
1975
+ }
1976
+ ]
1977
+ }
1978
+ },
1787
1979
  {
1788
1980
  "name": "DepositHistory",
1789
1981
  "type": {
@@ -1940,6 +2132,15 @@
1940
2132
  {
1941
2133
  "name": "minOrderQuoteAssetAmount",
1942
2134
  "type": "u128"
2135
+ },
2136
+ {
2137
+ "name": "padding",
2138
+ "type": {
2139
+ "array": [
2140
+ "u128",
2141
+ 10
2142
+ ]
2143
+ }
1943
2144
  }
1944
2145
  ]
1945
2146
  }
@@ -2093,6 +2294,10 @@
2093
2294
  "name": "orderState",
2094
2295
  "type": "publicKey"
2095
2296
  },
2297
+ {
2298
+ "name": "extendedCurveHistory",
2299
+ "type": "publicKey"
2300
+ },
2096
2301
  {
2097
2302
  "name": "padding0",
2098
2303
  "type": "u128"
@@ -2108,14 +2313,6 @@
2108
2313
  {
2109
2314
  "name": "padding3",
2110
2315
  "type": "u128"
2111
- },
2112
- {
2113
- "name": "padding4",
2114
- "type": "u128"
2115
- },
2116
- {
2117
- "name": "padding5",
2118
- "type": "u128"
2119
2316
  }
2120
2317
  ]
2121
2318
  }
@@ -2292,6 +2489,10 @@
2292
2489
  "defined": "PositionDirection"
2293
2490
  }
2294
2491
  },
2492
+ {
2493
+ "name": "userOrderId",
2494
+ "type": "u8"
2495
+ },
2295
2496
  {
2296
2497
  "name": "quoteAssetAmount",
2297
2498
  "type": "u128"
@@ -2335,6 +2536,22 @@
2335
2536
  "type": {
2336
2537
  "defined": "OrderParamsOptionalAccounts"
2337
2538
  }
2539
+ },
2540
+ {
2541
+ "name": "positionLimit",
2542
+ "type": "u128"
2543
+ },
2544
+ {
2545
+ "name": "oraclePriceOffset",
2546
+ "type": "u128"
2547
+ },
2548
+ {
2549
+ "name": "padding0",
2550
+ "type": "bool"
2551
+ },
2552
+ {
2553
+ "name": "padding1",
2554
+ "type": "bool"
2338
2555
  }
2339
2556
  ]
2340
2557
  }
@@ -2435,6 +2652,103 @@
2435
2652
  ]
2436
2653
  }
2437
2654
  },
2655
+ {
2656
+ "name": "ExtendedCurveRecord",
2657
+ "type": {
2658
+ "kind": "struct",
2659
+ "fields": [
2660
+ {
2661
+ "name": "ts",
2662
+ "type": "i64"
2663
+ },
2664
+ {
2665
+ "name": "recordId",
2666
+ "type": "u128"
2667
+ },
2668
+ {
2669
+ "name": "marketIndex",
2670
+ "type": "u64"
2671
+ },
2672
+ {
2673
+ "name": "pegMultiplierBefore",
2674
+ "type": "u128"
2675
+ },
2676
+ {
2677
+ "name": "baseAssetReserveBefore",
2678
+ "type": "u128"
2679
+ },
2680
+ {
2681
+ "name": "quoteAssetReserveBefore",
2682
+ "type": "u128"
2683
+ },
2684
+ {
2685
+ "name": "sqrtKBefore",
2686
+ "type": "u128"
2687
+ },
2688
+ {
2689
+ "name": "pegMultiplierAfter",
2690
+ "type": "u128"
2691
+ },
2692
+ {
2693
+ "name": "baseAssetReserveAfter",
2694
+ "type": "u128"
2695
+ },
2696
+ {
2697
+ "name": "quoteAssetReserveAfter",
2698
+ "type": "u128"
2699
+ },
2700
+ {
2701
+ "name": "sqrtKAfter",
2702
+ "type": "u128"
2703
+ },
2704
+ {
2705
+ "name": "baseAssetAmountLong",
2706
+ "type": "u128"
2707
+ },
2708
+ {
2709
+ "name": "baseAssetAmountShort",
2710
+ "type": "u128"
2711
+ },
2712
+ {
2713
+ "name": "baseAssetAmount",
2714
+ "type": "i128"
2715
+ },
2716
+ {
2717
+ "name": "openInterest",
2718
+ "type": "u128"
2719
+ },
2720
+ {
2721
+ "name": "totalFee",
2722
+ "type": "u128"
2723
+ },
2724
+ {
2725
+ "name": "totalFeeMinusDistributions",
2726
+ "type": "u128"
2727
+ },
2728
+ {
2729
+ "name": "adjustmentCost",
2730
+ "type": "i128"
2731
+ },
2732
+ {
2733
+ "name": "oraclePrice",
2734
+ "type": "i128"
2735
+ },
2736
+ {
2737
+ "name": "tradeRecord",
2738
+ "type": "u128"
2739
+ },
2740
+ {
2741
+ "name": "padding",
2742
+ "type": {
2743
+ "array": [
2744
+ "u128",
2745
+ 5
2746
+ ]
2747
+ }
2748
+ }
2749
+ ]
2750
+ }
2751
+ },
2438
2752
  {
2439
2753
  "name": "DepositRecord",
2440
2754
  "type": {
@@ -2783,16 +3097,16 @@
2783
3097
  "type": "i64"
2784
3098
  },
2785
3099
  {
2786
- "name": "minimumBaseAssetTradeSize",
2787
- "type": "u128"
3100
+ "name": "lastOraclePrice",
3101
+ "type": "i128"
2788
3102
  },
2789
3103
  {
2790
- "name": "padding0",
2791
- "type": "u64"
3104
+ "name": "minimumBaseAssetTradeSize",
3105
+ "type": "u128"
2792
3106
  },
2793
3107
  {
2794
3108
  "name": "padding1",
2795
- "type": "u128"
3109
+ "type": "u64"
2796
3110
  },
2797
3111
  {
2798
3112
  "name": "padding2",
@@ -2861,6 +3175,15 @@
2861
3175
  {
2862
3176
  "name": "fillerReward",
2863
3177
  "type": "u128"
3178
+ },
3179
+ {
3180
+ "name": "padding",
3181
+ "type": {
3182
+ "array": [
3183
+ "u64",
3184
+ 10
3185
+ ]
3186
+ }
2864
3187
  }
2865
3188
  ]
2866
3189
  }
@@ -3212,6 +3535,10 @@
3212
3535
  "name": "orderId",
3213
3536
  "type": "u128"
3214
3537
  },
3538
+ {
3539
+ "name": "userOrderId",
3540
+ "type": "u8"
3541
+ },
3215
3542
  {
3216
3543
  "name": "marketIndex",
3217
3544
  "type": "u64"
@@ -3220,6 +3547,10 @@
3220
3547
  "name": "price",
3221
3548
  "type": "u128"
3222
3549
  },
3550
+ {
3551
+ "name": "userBaseAssetAmount",
3552
+ "type": "i128"
3553
+ },
3223
3554
  {
3224
3555
  "name": "quoteAssetAmount",
3225
3556
  "type": "u128"
@@ -3277,6 +3608,19 @@
3277
3608
  {
3278
3609
  "name": "referrer",
3279
3610
  "type": "publicKey"
3611
+ },
3612
+ {
3613
+ "name": "oraclePriceOffset",
3614
+ "type": "i128"
3615
+ },
3616
+ {
3617
+ "name": "padding",
3618
+ "type": {
3619
+ "array": [
3620
+ "u16",
3621
+ 3
3622
+ ]
3623
+ }
3280
3624
  }
3281
3625
  ]
3282
3626
  }
@@ -3394,10 +3738,10 @@
3394
3738
  "name": "Limit"
3395
3739
  },
3396
3740
  {
3397
- "name": "Stop"
3741
+ "name": "TriggerMarket"
3398
3742
  },
3399
3743
  {
3400
- "name": "StopLimit"
3744
+ "name": "TriggerLimit"
3401
3745
  }
3402
3746
  ]
3403
3747
  }
@@ -3715,6 +4059,11 @@
3715
4059
  "code": 6054,
3716
4060
  "name": "MarketOrderMustBeInPlaceAndFill",
3717
4061
  "msg": "Market order must be in place and fill"
4062
+ },
4063
+ {
4064
+ "code": 6055,
4065
+ "name": "UserOrderIdAlreadyInUse",
4066
+ "msg": "User Order Id Already In Use"
3718
4067
  }
3719
4068
  ]
3720
4069
  }
package/src/index.ts CHANGED
@@ -1,16 +1,21 @@
1
1
  import { BN } from '@project-serum/anchor';
2
+ import { PublicKey } from '@solana/web3.js';
2
3
 
3
4
  export * from './mockUSDCFaucet';
4
5
  export * from './pythClient';
5
6
  export * from './types';
6
7
  export * from './constants/markets';
7
- export * from './accounts/defaultHistoryAccountSubscriber';
8
- export * from './accounts/defaultClearingHouseAccountSubscriber';
8
+ export * from './accounts/webSocketClearingHouseAccountSubscriber';
9
+ export * from './accounts/bulkAccountLoader';
10
+ export * from './accounts/pollingClearingHouseAccountSubscriber';
11
+ export * from './accounts/pollingTokenAccountSubscriber';
9
12
  export * from './accounts/types';
10
13
  export * from './addresses';
11
14
  export * from './admin';
12
15
  export * from './clearingHouseUser';
13
16
  export * from './clearingHouse';
17
+ export * from './factory/clearingHouse';
18
+ export * from './factory/clearingHouseUser';
14
19
  export * from './math/conversion';
15
20
  export * from './math/funding';
16
21
  export * from './math/insuranceFund';
@@ -29,4 +34,4 @@ export * from './constants/numericConstants';
29
34
  export * from './util/computeUnits';
30
35
  export * from './util/tps';
31
36
 
32
- export { BN };
37
+ export { BN, PublicKey };
@@ -1,4 +1,4 @@
1
- import BN from 'bn.js';
1
+ import { BN } from '../';
2
2
  import {
3
3
  MARK_PRICE_PRECISION,
4
4
  PEG_PRECISION,
@@ -120,6 +120,7 @@ export async function calculateAllEstimatedFundingRate(
120
120
  .mul(periodAdjustment)
121
121
  .div(hoursInDay)
122
122
  .div(MARK_PRICE_PRECISION.div(QUOTE_PRECISION));
123
+
123
124
  let feePoolSize = calculateFundingPool(market);
124
125
  if (interpRateQuote.lt(new BN(0))) {
125
126
  feePoolSize = feePoolSize.mul(new BN(-1));
@@ -289,7 +290,10 @@ export function calculateFundingPool(market: Market): BN {
289
290
  const totalFeeLB = market.amm.totalFee.div(new BN(2));
290
291
  const feePool = BN.max(
291
292
  ZERO,
292
- market.amm.totalFeeMinusDistributions.sub(totalFeeLB)
293
+ market.amm.totalFeeMinusDistributions
294
+ .sub(totalFeeLB)
295
+ .mul(new BN(2))
296
+ .div(new BN(3))
293
297
  );
294
298
  return feePool;
295
299
  }
@@ -1,5 +1,5 @@
1
1
  import { MarketsAccount, StateAccount } from '../types';
2
- import BN from 'bn.js';
2
+ import { BN } from '../';
3
3
  import { Connection } from '@solana/web3.js';
4
4
 
5
5
  /**
@@ -1,4 +1,4 @@
1
- import BN from 'bn.js';
1
+ import { BN } from '../';
2
2
  import {
3
3
  AMM_RESERVE_PRECISION,
4
4
  AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO,
package/src/math/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BN } from 'bn.js';
1
+ import { BN } from '../';
2
2
 
3
3
  export const squareRootBN = (n, closeness = new BN(1)) => {
4
4
  // Assuming the sqrt of n as n only
@@ -17,7 +17,7 @@ import {
17
17
  TransactionInstruction,
18
18
  TransactionSignature,
19
19
  } from '@solana/web3.js';
20
- import BN from 'bn.js';
20
+ import { BN } from '.';
21
21
  import mockUSDCFaucetIDL from './idl/mock_usdc_faucet.json';
22
22
  import { IWallet } from './types';
23
23