@drift-labs/sdk 0.2.0-master.1 → 0.2.0-master.10

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 (112) hide show
  1. package/lib/accounts/types.d.ts +1 -0
  2. package/lib/admin.d.ts +6 -3
  3. package/lib/admin.js +39 -7
  4. package/lib/clearingHouse.d.ts +13 -14
  5. package/lib/clearingHouse.js +166 -106
  6. package/lib/config.js +1 -1
  7. package/lib/constants/banks.js +8 -1
  8. package/lib/constants/numericConstants.d.ts +1 -0
  9. package/lib/constants/numericConstants.js +2 -1
  10. package/lib/factory/bigNum.d.ts +8 -2
  11. package/lib/factory/bigNum.js +14 -6
  12. package/lib/idl/clearing_house.json +277 -55
  13. package/lib/index.d.ts +2 -1
  14. package/lib/index.js +6 -1
  15. package/lib/math/amm.d.ts +6 -1
  16. package/lib/math/amm.js +124 -41
  17. package/lib/math/auction.js +4 -1
  18. package/lib/math/orders.d.ts +2 -2
  19. package/lib/math/orders.js +18 -11
  20. package/lib/math/position.js +3 -1
  21. package/lib/math/repeg.js +1 -1
  22. package/lib/math/trade.d.ts +1 -1
  23. package/lib/math/trade.js +7 -10
  24. package/lib/orderParams.d.ts +14 -5
  25. package/lib/orderParams.js +8 -96
  26. package/lib/orders.d.ts +1 -2
  27. package/lib/orders.js +6 -85
  28. package/lib/slot/SlotSubscriber.d.ts +7 -0
  29. package/lib/slot/SlotSubscriber.js +3 -0
  30. package/lib/tx/utils.js +1 -1
  31. package/lib/types.d.ts +75 -1
  32. package/lib/types.js +42 -1
  33. package/package.json +3 -3
  34. package/src/accounts/bulkAccountLoader.js +197 -0
  35. package/src/accounts/bulkUserSubscription.js +33 -0
  36. package/src/accounts/fetch.js +29 -0
  37. package/src/accounts/pollingClearingHouseAccountSubscriber.js +311 -0
  38. package/src/accounts/pollingOracleSubscriber.js +93 -0
  39. package/src/accounts/pollingTokenAccountSubscriber.js +90 -0
  40. package/src/accounts/pollingUserAccountSubscriber.js +132 -0
  41. package/src/accounts/types.js +10 -0
  42. package/src/accounts/utils.js +7 -0
  43. package/src/accounts/webSocketAccountSubscriber.js +93 -0
  44. package/src/accounts/webSocketClearingHouseAccountSubscriber.js +233 -0
  45. package/src/accounts/webSocketUserAccountSubscriber.js +62 -0
  46. package/src/addresses/marketAddresses.js +26 -0
  47. package/src/addresses/pda.js +104 -0
  48. package/src/admin.ts +60 -8
  49. package/src/assert/assert.js +9 -0
  50. package/src/clearingHouse.ts +223 -183
  51. package/src/config.ts +1 -1
  52. package/src/constants/banks.ts +8 -1
  53. package/src/constants/numericConstants.ts +1 -0
  54. package/src/events/eventList.js +77 -0
  55. package/src/events/eventSubscriber.js +139 -0
  56. package/src/events/fetchLogs.js +50 -0
  57. package/src/events/pollingLogProvider.js +64 -0
  58. package/src/events/sort.js +44 -0
  59. package/src/events/txEventCache.js +71 -0
  60. package/src/events/types.js +20 -0
  61. package/src/events/webSocketLogProvider.js +41 -0
  62. package/src/examples/makeTradeExample.js +80 -0
  63. package/src/factory/bigNum.js +364 -0
  64. package/src/factory/bigNum.ts +26 -9
  65. package/src/factory/oracleClient.js +20 -0
  66. package/src/idl/clearing_house.json +277 -55
  67. package/src/index.js +69 -0
  68. package/src/index.ts +2 -1
  69. package/src/math/amm.js +369 -0
  70. package/src/math/amm.ts +207 -52
  71. package/src/math/auction.js +42 -0
  72. package/src/math/auction.ts +5 -1
  73. package/src/math/bankBalance.js +75 -0
  74. package/src/math/conversion.js +11 -0
  75. package/src/math/funding.js +248 -0
  76. package/src/math/market.js +57 -0
  77. package/src/math/oracles.js +26 -0
  78. package/src/math/orders.js +110 -0
  79. package/src/math/orders.ts +17 -13
  80. package/src/math/position.js +140 -0
  81. package/src/math/position.ts +5 -1
  82. package/src/math/repeg.js +128 -0
  83. package/src/math/repeg.ts +2 -1
  84. package/src/math/state.js +15 -0
  85. package/src/math/trade.js +253 -0
  86. package/src/math/trade.ts +23 -25
  87. package/src/math/utils.js +0 -1
  88. package/src/mockUSDCFaucet.js +171 -0
  89. package/src/oracles/oracleClientCache.js +19 -0
  90. package/src/oracles/pythClient.js +46 -0
  91. package/src/oracles/quoteAssetOracleClient.js +32 -0
  92. package/src/oracles/switchboardClient.js +69 -0
  93. package/src/oracles/types.js +2 -0
  94. package/src/orderParams.js +20 -0
  95. package/src/orderParams.ts +20 -141
  96. package/src/orders.js +134 -0
  97. package/src/orders.ts +7 -131
  98. package/src/slot/SlotSubscriber.js +39 -0
  99. package/src/slot/SlotSubscriber.ts +11 -1
  100. package/src/token/index.js +38 -0
  101. package/src/tx/retryTxSender.js +188 -0
  102. package/src/tx/types.js +2 -0
  103. package/src/tx/utils.js +17 -0
  104. package/src/tx/utils.ts +1 -1
  105. package/src/types.js +114 -0
  106. package/src/types.ts +69 -3
  107. package/src/userName.js +20 -0
  108. package/src/util/promiseTimeout.js +14 -0
  109. package/src/util/tps.js +27 -0
  110. package/src/wallet.js +35 -0
  111. package/src/util/computeUnits.js +0 -17
  112. package/src/util/computeUnits.js.map +0 -1
@@ -55,7 +55,7 @@ export declare class BigNum {
55
55
  * @returns
56
56
  */
57
57
  print(): string;
58
- prettyPrint(): string;
58
+ prettyPrint(useTradePrecision?: boolean, precisionOverride?: number): string;
59
59
  /**
60
60
  * Print and remove unnecessary trailing zeroes
61
61
  * @returns
@@ -75,7 +75,13 @@ export declare class BigNum {
75
75
  */
76
76
  toPrecision(fixedPrecision: number, trailingZeroes?: boolean): string;
77
77
  toTradePrecision(): string;
78
- toNotional(): string;
78
+ /**
79
+ * Print dollar formatted value. Defaults to fixed decimals two unless a given precision is given.
80
+ * @param useTradePrecision
81
+ * @param precisionOverride
82
+ * @returns
83
+ */
84
+ toNotional(useTradePrecision?: boolean, precisionOverride?: number): string;
79
85
  toMillified(precision?: number): string;
80
86
  toJSON(): {
81
87
  val: string;
@@ -156,8 +156,8 @@ class BigNum {
156
156
  printString = printString.slice(0, printString.length - 1);
157
157
  return printString;
158
158
  }
159
- prettyPrint() {
160
- const [leftSide, rightSide] = this.printShort().split(BigNum.delim);
159
+ prettyPrint(useTradePrecision, precisionOverride) {
160
+ const [leftSide, rightSide] = this.printShort(useTradePrecision, precisionOverride).split(BigNum.delim);
161
161
  let formattedLeftSide = leftSide;
162
162
  const isNeg = formattedLeftSide.includes('-');
163
163
  if (isNeg) {
@@ -254,10 +254,18 @@ class BigNum {
254
254
  toTradePrecision() {
255
255
  return this.toPrecision(6, true);
256
256
  }
257
- toNotional() {
258
- return `${this.lt(BigNum.zero()) ? `-` : ``}$${BigNum.fromPrint(this.toFixed(2), new anchor_1.BN(2))
259
- .prettyPrint()
260
- .replace('-', '')}`;
257
+ /**
258
+ * Print dollar formatted value. Defaults to fixed decimals two unless a given precision is given.
259
+ * @param useTradePrecision
260
+ * @param precisionOverride
261
+ * @returns
262
+ */
263
+ toNotional(useTradePrecision, precisionOverride) {
264
+ const prefix = `${this.lt(BigNum.zero()) ? `-` : ``}$`;
265
+ const val = useTradePrecision || precisionOverride
266
+ ? this.prettyPrint(useTradePrecision, precisionOverride)
267
+ : BigNum.fromPrint(this.toFixed(2), new anchor_1.BN(2)).prettyPrint();
268
+ return `${prefix}${val.replace('-', '')}`;
261
269
  }
262
270
  toMillified(precision = 3) {
263
271
  const stringVal = this.print();
@@ -141,6 +141,10 @@
141
141
  {
142
142
  "name": "maintenanceLiabilityWeight",
143
143
  "type": "u128"
144
+ },
145
+ {
146
+ "name": "imfFactor",
147
+ "type": "u128"
144
148
  }
145
149
  ]
146
150
  },
@@ -381,11 +385,6 @@
381
385
  "name": "authority",
382
386
  "isMut": false,
383
387
  "isSigner": true
384
- },
385
- {
386
- "name": "oracle",
387
- "isMut": false,
388
- "isSigner": false
389
388
  }
390
389
  ],
391
390
  "args": [
@@ -414,17 +413,14 @@
414
413
  "name": "authority",
415
414
  "isMut": false,
416
415
  "isSigner": true
417
- },
418
- {
419
- "name": "oracle",
420
- "isMut": false,
421
- "isSigner": false
422
416
  }
423
417
  ],
424
418
  "args": [
425
419
  {
426
420
  "name": "orderId",
427
- "type": "u64"
421
+ "type": {
422
+ "option": "u64"
423
+ }
428
424
  }
429
425
  ]
430
426
  },
@@ -445,11 +441,6 @@
445
441
  "name": "authority",
446
442
  "isMut": false,
447
443
  "isSigner": true
448
- },
449
- {
450
- "name": "oracle",
451
- "isMut": false,
452
- "isSigner": false
453
444
  }
454
445
  ],
455
446
  "args": [
@@ -481,17 +472,14 @@
481
472
  "name": "user",
482
473
  "isMut": true,
483
474
  "isSigner": false
484
- },
485
- {
486
- "name": "oracle",
487
- "isMut": false,
488
- "isSigner": false
489
475
  }
490
476
  ],
491
477
  "args": [
492
478
  {
493
479
  "name": "orderId",
494
- "type": "u64"
480
+ "type": {
481
+ "option": "u64"
482
+ }
495
483
  },
496
484
  {
497
485
  "name": "makerOrderId",
@@ -518,11 +506,6 @@
518
506
  "name": "authority",
519
507
  "isMut": false,
520
508
  "isSigner": true
521
- },
522
- {
523
- "name": "oracle",
524
- "isMut": false,
525
- "isSigner": false
526
509
  }
527
510
  ],
528
511
  "args": [
@@ -555,18 +538,13 @@
555
538
  },
556
539
  {
557
540
  "name": "taker",
558
- "isMut": false,
541
+ "isMut": true,
559
542
  "isSigner": false
560
543
  },
561
544
  {
562
545
  "name": "authority",
563
546
  "isMut": false,
564
547
  "isSigner": true
565
- },
566
- {
567
- "name": "oracle",
568
- "isMut": false,
569
- "isSigner": false
570
548
  }
571
549
  ],
572
550
  "args": [
@@ -582,6 +560,37 @@
582
560
  }
583
561
  ]
584
562
  },
563
+ {
564
+ "name": "triggerOrder",
565
+ "accounts": [
566
+ {
567
+ "name": "state",
568
+ "isMut": false,
569
+ "isSigner": false
570
+ },
571
+ {
572
+ "name": "authority",
573
+ "isMut": false,
574
+ "isSigner": true
575
+ },
576
+ {
577
+ "name": "filler",
578
+ "isMut": true,
579
+ "isSigner": false
580
+ },
581
+ {
582
+ "name": "user",
583
+ "isMut": true,
584
+ "isSigner": false
585
+ }
586
+ ],
587
+ "args": [
588
+ {
589
+ "name": "orderId",
590
+ "type": "u64"
591
+ }
592
+ ]
593
+ },
585
594
  {
586
595
  "name": "updateAmms",
587
596
  "accounts": [
@@ -711,7 +720,7 @@
711
720
  ]
712
721
  },
713
722
  {
714
- "name": "withdrawFees",
723
+ "name": "withdrawFromMarketToInsuranceVault",
715
724
  "accounts": [
716
725
  {
717
726
  "name": "state",
@@ -725,7 +734,7 @@
725
734
  },
726
735
  {
727
736
  "name": "bank",
728
- "isMut": false,
737
+ "isMut": true,
729
738
  "isSigner": false
730
739
  },
731
740
  {
@@ -830,6 +839,11 @@
830
839
  "isMut": false,
831
840
  "isSigner": false
832
841
  },
842
+ {
843
+ "name": "bank",
844
+ "isMut": true,
845
+ "isSigner": false
846
+ },
833
847
  {
834
848
  "name": "bankVault",
835
849
  "isMut": true,
@@ -993,11 +1007,6 @@
993
1007
  "name": "user",
994
1008
  "isMut": true,
995
1009
  "isSigner": false
996
- },
997
- {
998
- "name": "market",
999
- "isMut": false,
1000
- "isSigner": false
1001
1010
  }
1002
1011
  ],
1003
1012
  "args": []
@@ -1093,6 +1102,62 @@
1093
1102
  }
1094
1103
  ]
1095
1104
  },
1105
+ {
1106
+ "name": "updateMarketImfFactor",
1107
+ "accounts": [
1108
+ {
1109
+ "name": "admin",
1110
+ "isMut": false,
1111
+ "isSigner": true
1112
+ },
1113
+ {
1114
+ "name": "state",
1115
+ "isMut": false,
1116
+ "isSigner": false
1117
+ },
1118
+ {
1119
+ "name": "market",
1120
+ "isMut": true,
1121
+ "isSigner": false
1122
+ }
1123
+ ],
1124
+ "args": [
1125
+ {
1126
+ "name": "imfFactor",
1127
+ "type": "u128"
1128
+ }
1129
+ ]
1130
+ },
1131
+ {
1132
+ "name": "updateMarketUnsettledAssetWeight",
1133
+ "accounts": [
1134
+ {
1135
+ "name": "admin",
1136
+ "isMut": false,
1137
+ "isSigner": true
1138
+ },
1139
+ {
1140
+ "name": "state",
1141
+ "isMut": false,
1142
+ "isSigner": false
1143
+ },
1144
+ {
1145
+ "name": "market",
1146
+ "isMut": true,
1147
+ "isSigner": false
1148
+ }
1149
+ ],
1150
+ "args": [
1151
+ {
1152
+ "name": "unsettledInitialAssetWeight",
1153
+ "type": "u8"
1154
+ },
1155
+ {
1156
+ "name": "unsettledMaintenanceAssetWeight",
1157
+ "type": "u8"
1158
+ }
1159
+ ]
1160
+ },
1096
1161
  {
1097
1162
  "name": "updateCurveUpdateIntensity",
1098
1163
  "accounts": [
@@ -1389,6 +1454,32 @@
1389
1454
  }
1390
1455
  ]
1391
1456
  },
1457
+ {
1458
+ "name": "updateMarketMaxSpread",
1459
+ "accounts": [
1460
+ {
1461
+ "name": "admin",
1462
+ "isMut": false,
1463
+ "isSigner": true
1464
+ },
1465
+ {
1466
+ "name": "state",
1467
+ "isMut": false,
1468
+ "isSigner": false
1469
+ },
1470
+ {
1471
+ "name": "market",
1472
+ "isMut": true,
1473
+ "isSigner": false
1474
+ }
1475
+ ],
1476
+ "args": [
1477
+ {
1478
+ "name": "maxSpread",
1479
+ "type": "u32"
1480
+ }
1481
+ ]
1482
+ },
1392
1483
  {
1393
1484
  "name": "updateMarketBaseAssetAmountStepSize",
1394
1485
  "accounts": [
@@ -1415,6 +1506,58 @@
1415
1506
  }
1416
1507
  ]
1417
1508
  },
1509
+ {
1510
+ "name": "updateMarketMaxSlippageRatio",
1511
+ "accounts": [
1512
+ {
1513
+ "name": "admin",
1514
+ "isMut": false,
1515
+ "isSigner": true
1516
+ },
1517
+ {
1518
+ "name": "state",
1519
+ "isMut": false,
1520
+ "isSigner": false
1521
+ },
1522
+ {
1523
+ "name": "market",
1524
+ "isMut": true,
1525
+ "isSigner": false
1526
+ }
1527
+ ],
1528
+ "args": [
1529
+ {
1530
+ "name": "maxSlippageRatio",
1531
+ "type": "u16"
1532
+ }
1533
+ ]
1534
+ },
1535
+ {
1536
+ "name": "updateMaxBaseAssetAmountRatio",
1537
+ "accounts": [
1538
+ {
1539
+ "name": "admin",
1540
+ "isMut": false,
1541
+ "isSigner": true
1542
+ },
1543
+ {
1544
+ "name": "state",
1545
+ "isMut": false,
1546
+ "isSigner": false
1547
+ },
1548
+ {
1549
+ "name": "market",
1550
+ "isMut": true,
1551
+ "isSigner": false
1552
+ }
1553
+ ],
1554
+ "args": [
1555
+ {
1556
+ "name": "maxBaseAssetAmountRatio",
1557
+ "type": "u16"
1558
+ }
1559
+ ]
1560
+ },
1418
1561
  {
1419
1562
  "name": "updateAdmin",
1420
1563
  "accounts": [
@@ -1537,7 +1680,7 @@
1537
1680
  ]
1538
1681
  },
1539
1682
  {
1540
- "name": "updateOrderAuctionTime",
1683
+ "name": "updateAuctionDuration",
1541
1684
  "accounts": [
1542
1685
  {
1543
1686
  "name": "admin",
@@ -1552,7 +1695,11 @@
1552
1695
  ],
1553
1696
  "args": [
1554
1697
  {
1555
- "name": "orderAuctionTime",
1698
+ "name": "minAuctionDuration",
1699
+ "type": "u8"
1700
+ },
1701
+ {
1702
+ "name": "maxAuctionDuration",
1556
1703
  "type": "u8"
1557
1704
  }
1558
1705
  ]
@@ -1649,6 +1796,10 @@
1649
1796
  {
1650
1797
  "name": "maintenanceLiabilityWeight",
1651
1798
  "type": "u128"
1799
+ },
1800
+ {
1801
+ "name": "imfFactor",
1802
+ "type": "u128"
1652
1803
  }
1653
1804
  ]
1654
1805
  }
@@ -1726,6 +1877,22 @@
1726
1877
  "name": "unsettledLoss",
1727
1878
  "type": "u128"
1728
1879
  },
1880
+ {
1881
+ "name": "imfFactor",
1882
+ "type": "u128"
1883
+ },
1884
+ {
1885
+ "name": "unsettledInitialAssetWeight",
1886
+ "type": "u8"
1887
+ },
1888
+ {
1889
+ "name": "unsettledMaintenanceAssetWeight",
1890
+ "type": "u8"
1891
+ },
1892
+ {
1893
+ "name": "unsettledImfFactor",
1894
+ "type": "u128"
1895
+ },
1729
1896
  {
1730
1897
  "name": "padding0",
1731
1898
  "type": "u32"
@@ -1859,7 +2026,11 @@
1859
2026
  "type": "u128"
1860
2027
  },
1861
2028
  {
1862
- "name": "orderAuctionDuration",
2029
+ "name": "minAuctionDuration",
2030
+ "type": "u8"
2031
+ },
2032
+ {
2033
+ "name": "maxAuctionDuration",
1863
2034
  "type": "u8"
1864
2035
  },
1865
2036
  {
@@ -1964,10 +2135,6 @@
1964
2135
  "name": "userOrderId",
1965
2136
  "type": "u8"
1966
2137
  },
1967
- {
1968
- "name": "quoteAssetAmount",
1969
- "type": "u128"
1970
- },
1971
2138
  {
1972
2139
  "name": "baseAssetAmount",
1973
2140
  "type": "u128"
@@ -2016,6 +2183,10 @@
2016
2183
  "name": "oraclePriceOffset",
2017
2184
  "type": "i128"
2018
2185
  },
2186
+ {
2187
+ "name": "auctionDuration",
2188
+ "type": "u8"
2189
+ },
2019
2190
  {
2020
2191
  "name": "padding0",
2021
2192
  "type": "bool"
@@ -2178,6 +2349,14 @@
2178
2349
  "name": "minimumQuoteAssetTradeSize",
2179
2350
  "type": "u128"
2180
2351
  },
2352
+ {
2353
+ "name": "maxBaseAssetAmountRatio",
2354
+ "type": "u16"
2355
+ },
2356
+ {
2357
+ "name": "maxSlippageRatio",
2358
+ "type": "u16"
2359
+ },
2181
2360
  {
2182
2361
  "name": "baseAssetAmountStepSize",
2183
2362
  "type": "u128"
@@ -2194,6 +2373,10 @@
2194
2373
  "name": "shortSpread",
2195
2374
  "type": "u128"
2196
2375
  },
2376
+ {
2377
+ "name": "maxSpread",
2378
+ "type": "u32"
2379
+ },
2197
2380
  {
2198
2381
  "name": "askBaseAssetReserve",
2199
2382
  "type": "u128"
@@ -2252,7 +2435,7 @@
2252
2435
  },
2253
2436
  {
2254
2437
  "name": "totalFeeMinusDistributions",
2255
- "type": "u128"
2438
+ "type": "i128"
2256
2439
  },
2257
2440
  {
2258
2441
  "name": "totalFeeWithdrawn",
@@ -2658,10 +2841,6 @@
2658
2841
  "defined": "PositionDirection"
2659
2842
  }
2660
2843
  },
2661
- {
2662
- "name": "quoteAssetAmount",
2663
- "type": "u128"
2664
- },
2665
2844
  {
2666
2845
  "name": "baseAssetAmount",
2667
2846
  "type": "u128"
@@ -2712,6 +2891,10 @@
2712
2891
  "defined": "OrderTriggerCondition"
2713
2892
  }
2714
2893
  },
2894
+ {
2895
+ "name": "triggered",
2896
+ "type": "bool"
2897
+ },
2715
2898
  {
2716
2899
  "name": "referrer",
2717
2900
  "type": "publicKey"
@@ -2848,6 +3031,9 @@
2848
3031
  {
2849
3032
  "name": "Fill"
2850
3033
  },
3034
+ {
3035
+ "name": "Trigger"
3036
+ },
2851
3037
  {
2852
3038
  "name": "Expire"
2853
3039
  }
@@ -2867,6 +3053,12 @@
2867
3053
  },
2868
3054
  {
2869
3055
  "name": "OraclePriceBreachedLimitPrice"
3056
+ },
3057
+ {
3058
+ "name": "MarketOrderFilledToLimitPrice"
3059
+ },
3060
+ {
3061
+ "name": "MarketOrderAuctionExpired"
2870
3062
  }
2871
3063
  ]
2872
3064
  }
@@ -3016,6 +3208,11 @@
3016
3208
  "type": "u64",
3017
3209
  "index": false
3018
3210
  },
3211
+ {
3212
+ "name": "oraclePrice",
3213
+ "type": "i128",
3214
+ "index": false
3215
+ },
3019
3216
  {
3020
3217
  "name": "from",
3021
3218
  "type": {
@@ -3217,7 +3414,7 @@
3217
3414
  },
3218
3415
  {
3219
3416
  "name": "totalFeeMinusDistributions",
3220
- "type": "u128",
3417
+ "type": "i128",
3221
3418
  "index": false
3222
3419
  },
3223
3420
  {
@@ -3349,6 +3546,16 @@
3349
3546
  },
3350
3547
  "index": false
3351
3548
  },
3549
+ {
3550
+ "name": "makerUnsettledPnl",
3551
+ "type": "i128",
3552
+ "index": false
3553
+ },
3554
+ {
3555
+ "name": "takerUnsettledPnl",
3556
+ "type": "i128",
3557
+ "index": false
3558
+ },
3352
3559
  {
3353
3560
  "name": "action",
3354
3561
  "type": {
@@ -3639,8 +3846,8 @@
3639
3846
  },
3640
3847
  {
3641
3848
  "code": 6044,
3642
- "name": "CouldNotFillOrder",
3643
- "msg": "CouldNotFillOrder"
3849
+ "name": "FillOrderDidNotUpdateState",
3850
+ "msg": "FillOrderDidNotUpdateState"
3644
3851
  },
3645
3852
  {
3646
3853
  "code": 6045,
@@ -3854,6 +4061,21 @@
3854
4061
  },
3855
4062
  {
3856
4063
  "code": 6087,
4064
+ "name": "OrderMustBeTriggeredFirst",
4065
+ "msg": "OrderMustBeTriggeredFirst"
4066
+ },
4067
+ {
4068
+ "code": 6088,
4069
+ "name": "OrderNotTriggerable",
4070
+ "msg": "OrderNotTriggerable"
4071
+ },
4072
+ {
4073
+ "code": 6089,
4074
+ "name": "OrderDidNotSatisfyTriggerCondition",
4075
+ "msg": "OrderDidNotSatisfyTriggerCondition"
4076
+ },
4077
+ {
4078
+ "code": 6090,
3857
4079
  "name": "DefaultError",
3858
4080
  "msg": "DefaultError"
3859
4081
  }
package/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { BN } from '@project-serum/anchor';
2
2
  import { PublicKey } from '@solana/web3.js';
3
+ import pyth from '@pythnetwork/client';
3
4
  export * from './mockUSDCFaucet';
4
5
  export * from './oracles/types';
5
6
  export * from './oracles/pythClient';
@@ -47,4 +48,4 @@ export * from './util/tps';
47
48
  export * from './math/bankBalance';
48
49
  export * from './constants/banks';
49
50
  export * from './clearingHouseConfig';
50
- export { BN, PublicKey };
51
+ export { BN, PublicKey, pyth };
package/lib/index.js CHANGED
@@ -13,12 +13,17 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
16
19
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.PublicKey = exports.BN = void 0;
20
+ exports.pyth = exports.PublicKey = exports.BN = void 0;
18
21
  const anchor_1 = require("@project-serum/anchor");
19
22
  Object.defineProperty(exports, "BN", { enumerable: true, get: function () { return anchor_1.BN; } });
20
23
  const web3_js_1 = require("@solana/web3.js");
21
24
  Object.defineProperty(exports, "PublicKey", { enumerable: true, get: function () { return web3_js_1.PublicKey; } });
25
+ const client_1 = __importDefault(require("@pythnetwork/client"));
26
+ exports.pyth = client_1.default;
22
27
  __exportStar(require("./mockUSDCFaucet"), exports);
23
28
  __exportStar(require("./oracles/types"), exports);
24
29
  __exportStar(require("./oracles/pythClient"), exports);
package/lib/math/amm.d.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  import { BN } from '@project-serum/anchor';
3
3
  import { AMM, PositionDirection, SwapDirection, MarketAccount } from '../types';
4
4
  import { OraclePriceData } from '../oracles/types';
5
+ export declare function calculatePegFromTargetPrice(targetPrice: BN, baseAssetReserve: BN, quoteAssetReserve: BN): BN;
6
+ export declare function calculateOptimalPegAndBudget(amm: AMM, oraclePriceData: OraclePriceData): [BN, BN, BN, boolean];
5
7
  export declare function calculateNewAmm(amm: AMM, oraclePriceData: OraclePriceData): [BN, BN, BN, BN];
6
8
  export declare function calculateUpdatedAMM(amm: AMM, oraclePriceData: OraclePriceData): AMM;
7
9
  export declare function calculateUpdatedAMMSpreadReserves(amm: AMM, direction: PositionDirection, oraclePriceData: OraclePriceData): {
@@ -10,7 +12,7 @@ export declare function calculateUpdatedAMMSpreadReserves(amm: AMM, direction: P
10
12
  sqrtK: BN;
11
13
  newPeg: BN;
12
14
  };
13
- export declare function calculateBidAskPrice(amm: AMM, oraclePriceData: OraclePriceData): [BN, BN];
15
+ export declare function calculateBidAskPrice(amm: AMM, oraclePriceData: OraclePriceData, withUpdate?: boolean): [BN, BN];
14
16
  /**
15
17
  * Calculates a price given an arbitrary base and quote amount (they must have the same precision)
16
18
  *
@@ -31,6 +33,9 @@ export declare type AssetType = 'quote' | 'base';
31
33
  * @returns quoteAssetReserve and baseAssetReserve after swap. : Precision AMM_RESERVE_PRECISION
32
34
  */
33
35
  export declare function calculateAmmReservesAfterSwap(amm: Pick<AMM, 'pegMultiplier' | 'quoteAssetReserve' | 'sqrtK' | 'baseAssetReserve'>, inputAssetType: AssetType, swapAmount: BN, swapDirection: SwapDirection): [BN, BN];
36
+ export declare function calculateEffectiveLeverage(baseSpread: number, quoteAssetReserve: BN, terminalQuoteAssetReserve: BN, pegMultiplier: BN, netBaseAssetAmount: BN, markPrice: BN, totalFeeMinusDistributions: BN): number;
37
+ export declare function calculateMaxSpread(marginRatioInitial: number): number;
38
+ export declare function calculateSpreadBN(baseSpread: number, lastOracleMarkSpreadPct: BN, lastOracleConfPct: BN, maxSpread: number, quoteAssetReserve: BN, terminalQuoteAssetReserve: BN, pegMultiplier: BN, netBaseAssetAmount: BN, markPrice: BN, totalFeeMinusDistributions: BN): [number, number];
34
39
  export declare function calculateSpread(amm: AMM, direction: PositionDirection, oraclePriceData: OraclePriceData): number;
35
40
  export declare function calculateSpreadReserves(amm: AMM, direction: PositionDirection, oraclePriceData: OraclePriceData): {
36
41
  baseAssetReserve: BN;