@drift-labs/sdk 0.2.0-master.15 → 0.2.0-master.18

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 (58) hide show
  1. package/lib/accounts/types.d.ts +1 -0
  2. package/lib/constants/numericConstants.d.ts +2 -0
  3. package/lib/constants/numericConstants.js +5 -3
  4. package/lib/events/types.js +1 -0
  5. package/lib/index.d.ts +5 -0
  6. package/lib/index.js +5 -0
  7. package/lib/math/position.js +1 -1
  8. package/lib/types.d.ts +2 -0
  9. package/package.json +1 -1
  10. package/src/addresses/marketAddresses.js +26 -0
  11. package/src/assert/assert.js +9 -0
  12. package/src/constants/banks.js +42 -0
  13. package/src/constants/markets.js +42 -0
  14. package/src/constants/numericConstants.js +41 -0
  15. package/src/constants/numericConstants.ts +10 -2
  16. package/src/events/eventList.js +77 -0
  17. package/src/events/eventSubscriber.js +139 -0
  18. package/src/events/fetchLogs.js +50 -0
  19. package/src/events/pollingLogProvider.js +64 -0
  20. package/src/events/sort.js +44 -0
  21. package/src/events/txEventCache.js +71 -0
  22. package/src/events/types.js +20 -0
  23. package/src/events/types.ts +1 -0
  24. package/src/events/webSocketLogProvider.js +41 -0
  25. package/src/examples/makeTradeExample.js +80 -0
  26. package/src/factory/bigNum.js +390 -0
  27. package/src/factory/oracleClient.js +20 -0
  28. package/src/index.ts +5 -0
  29. package/src/math/amm.js +369 -0
  30. package/src/math/auction.js +42 -0
  31. package/src/math/conversion.js +11 -0
  32. package/src/math/funding.js +248 -0
  33. package/src/math/oracles.js +26 -0
  34. package/src/math/position.ts +1 -1
  35. package/src/math/repeg.js +128 -0
  36. package/src/math/state.js +15 -0
  37. package/src/math/trade.js +253 -0
  38. package/src/math/utils.js +26 -0
  39. package/src/math/utils.js.map +1 -0
  40. package/src/oracles/oracleClientCache.js +19 -0
  41. package/src/oracles/pythClient.js +46 -0
  42. package/src/oracles/quoteAssetOracleClient.js +32 -0
  43. package/src/oracles/switchboardClient.js +69 -0
  44. package/src/oracles/types.js +2 -0
  45. package/src/orderParams.js +20 -0
  46. package/src/slot/SlotSubscriber.js +39 -0
  47. package/src/token/index.js +38 -0
  48. package/src/tokenFaucet.js +189 -0
  49. package/src/tx/types.js +2 -0
  50. package/src/tx/utils.js +17 -0
  51. package/src/types.js +125 -0
  52. package/src/types.ts +2 -0
  53. package/src/userName.js +20 -0
  54. package/src/util/computeUnits.js +27 -0
  55. package/src/util/getTokenAddress.js +9 -0
  56. package/src/util/promiseTimeout.js +14 -0
  57. package/src/util/tps.js +27 -0
  58. package/src/wallet.js +35 -0
@@ -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.findComputeUnitConsumption = void 0;
13
+ function findComputeUnitConsumption(programId, connection, txSignature, commitment = 'confirmed') {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const tx = yield connection.getTransaction(txSignature, { commitment });
16
+ const computeUnits = [];
17
+ const regex = new RegExp(`Program ${programId.toString()} consumed ([0-9]{0,6}) of ([0-9]{0,7}) compute units`);
18
+ tx.meta.logMessages.forEach((logMessage) => {
19
+ const match = logMessage.match(regex);
20
+ if (match && match[1]) {
21
+ computeUnits.push(match[1]);
22
+ }
23
+ });
24
+ return computeUnits;
25
+ });
26
+ }
27
+ exports.findComputeUnitConsumption = findComputeUnitConsumption;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTokenAddress = void 0;
4
+ const spl_token_1 = require("@solana/spl-token");
5
+ const web3_js_1 = require("@solana/web3.js");
6
+ const getTokenAddress = (mintAddress, userPubKey) => {
7
+ return spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, new web3_js_1.PublicKey(mintAddress), new web3_js_1.PublicKey(userPubKey));
8
+ };
9
+ exports.getTokenAddress = getTokenAddress;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.promiseTimeout = void 0;
4
+ function promiseTimeout(promise, timeoutMs) {
5
+ let timeoutId;
6
+ const timeoutPromise = new Promise((resolve) => {
7
+ timeoutId = setTimeout(() => resolve(null), timeoutMs);
8
+ });
9
+ return Promise.race([promise, timeoutPromise]).then((result) => {
10
+ clearTimeout(timeoutId);
11
+ return result;
12
+ });
13
+ }
14
+ exports.promiseTimeout = promiseTimeout;
@@ -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;