@drift-labs/sdk 0.2.0-master.7 → 0.2.0-master.8

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 (65) hide show
  1. package/lib/clearingHouse.js +38 -25
  2. package/lib/constants/banks.js +9 -1
  3. package/package.json +1 -1
  4. package/src/accounts/bulkAccountLoader.js +197 -0
  5. package/src/accounts/bulkUserSubscription.js +33 -0
  6. package/src/accounts/fetch.js +29 -0
  7. package/src/accounts/pollingClearingHouseAccountSubscriber.js +311 -0
  8. package/src/accounts/pollingOracleSubscriber.js +93 -0
  9. package/src/accounts/pollingTokenAccountSubscriber.js +90 -0
  10. package/src/accounts/pollingUserAccountSubscriber.js +132 -0
  11. package/src/accounts/types.js +10 -0
  12. package/src/accounts/utils.js +7 -0
  13. package/src/accounts/webSocketAccountSubscriber.js +93 -0
  14. package/src/accounts/webSocketClearingHouseAccountSubscriber.js +233 -0
  15. package/src/accounts/webSocketUserAccountSubscriber.js +62 -0
  16. package/src/addresses/marketAddresses.js +26 -0
  17. package/src/addresses/pda.js +104 -0
  18. package/src/assert/assert.js +9 -0
  19. package/src/clearingHouse.ts +43 -27
  20. package/src/constants/banks.ts +9 -1
  21. package/src/events/eventList.js +77 -0
  22. package/src/events/eventSubscriber.js +139 -0
  23. package/src/events/fetchLogs.js +50 -0
  24. package/src/events/pollingLogProvider.js +64 -0
  25. package/src/events/sort.js +44 -0
  26. package/src/events/txEventCache.js +71 -0
  27. package/src/events/types.js +20 -0
  28. package/src/events/webSocketLogProvider.js +41 -0
  29. package/src/examples/makeTradeExample.js +80 -0
  30. package/src/factory/bigNum.js +364 -0
  31. package/src/factory/oracleClient.js +20 -0
  32. package/src/index.js +69 -0
  33. package/src/math/amm.js +369 -0
  34. package/src/math/auction.js +42 -0
  35. package/src/math/bankBalance.js +75 -0
  36. package/src/math/conversion.js +11 -0
  37. package/src/math/funding.js +248 -0
  38. package/src/math/market.js +57 -0
  39. package/src/math/oracles.js +26 -0
  40. package/src/math/orders.js +110 -0
  41. package/src/math/position.js +140 -0
  42. package/src/math/repeg.js +128 -0
  43. package/src/math/state.js +15 -0
  44. package/src/math/trade.js +253 -0
  45. package/src/math/utils.js +0 -1
  46. package/src/mockUSDCFaucet.js +171 -0
  47. package/src/oracles/oracleClientCache.js +19 -0
  48. package/src/oracles/pythClient.js +46 -0
  49. package/src/oracles/quoteAssetOracleClient.js +32 -0
  50. package/src/oracles/switchboardClient.js +69 -0
  51. package/src/oracles/types.js +2 -0
  52. package/src/orderParams.js +20 -0
  53. package/src/orders.js +134 -0
  54. package/src/slot/SlotSubscriber.js +39 -0
  55. package/src/token/index.js +38 -0
  56. package/src/tx/retryTxSender.js +188 -0
  57. package/src/tx/types.js +2 -0
  58. package/src/tx/utils.js +17 -0
  59. package/src/types.js +114 -0
  60. package/src/userName.js +20 -0
  61. package/src/util/promiseTimeout.js +14 -0
  62. package/src/util/tps.js +27 -0
  63. package/src/wallet.js +35 -0
  64. package/src/util/computeUnits.js +0 -17
  65. package/src/util/computeUnits.js.map +0 -1
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.estimateTps = void 0;
13
+ function estimateTps(programId, connection, failed) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ let signatures = yield connection.getSignaturesForAddress(programId, undefined, 'finalized');
16
+ if (failed) {
17
+ signatures = signatures.filter((signature) => signature.err);
18
+ }
19
+ const numberOfSignatures = signatures.length;
20
+ if (numberOfSignatures === 0) {
21
+ return 0;
22
+ }
23
+ return (numberOfSignatures /
24
+ (signatures[0].blockTime - signatures[numberOfSignatures - 1].blockTime));
25
+ });
26
+ }
27
+ exports.estimateTps = estimateTps;
package/src/wallet.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Wallet = void 0;
13
+ class Wallet {
14
+ constructor(payer) {
15
+ this.payer = payer;
16
+ }
17
+ signTransaction(tx) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ tx.partialSign(this.payer);
20
+ return tx;
21
+ });
22
+ }
23
+ signAllTransactions(txs) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ return txs.map((t) => {
26
+ t.partialSign(this.payer);
27
+ return t;
28
+ });
29
+ });
30
+ }
31
+ get publicKey() {
32
+ return this.payer.publicKey;
33
+ }
34
+ }
35
+ exports.Wallet = Wallet;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findComputeUnitConsumption = void 0;
4
- async function findComputeUnitConsumption(programId, connection, txSignature, commitment = 'confirmed') {
5
- const tx = await connection.getTransaction(txSignature, { commitment });
6
- const computeUnits = [];
7
- const regex = new RegExp(`Program ${programId.toString()} consumed ([0-9]{0,6}) of 200000 compute units`);
8
- tx.meta.logMessages.forEach((logMessage) => {
9
- const match = logMessage.match(regex);
10
- if (match && match[1]) {
11
- computeUnits.push(match[1]);
12
- }
13
- });
14
- return computeUnits;
15
- }
16
- exports.findComputeUnitConsumption = findComputeUnitConsumption;
17
- //# sourceMappingURL=computeUnits.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"computeUnits.js","sourceRoot":"","sources":["computeUnits.ts"],"names":[],"mappings":";;;AAEO,KAAK,UAAU,0BAA0B,CAC/C,SAAoB,EACpB,UAAsB,EACtB,WAAmB,EACnB,aAAuB,WAAW;IAElC,MAAM,EAAE,GAAG,MAAM,UAAU,CAAC,cAAc,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IACxE,MAAM,YAAY,GAAG,EAAE,CAAC;IACxB,MAAM,KAAK,GAAG,IAAI,MAAM,CACvB,WAAW,SAAS,CAAC,QAAQ,EAAE,gDAAgD,CAC/E,CAAC;IACF,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;YACtB,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SAC5B;IACF,CAAC,CAAC,CAAC;IACH,OAAO,YAAY,CAAC;AACrB,CAAC;AAlBD,gEAkBC"}