@drift-labs/sdk 0.1.14 → 0.1.15

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.
package/README.md CHANGED
@@ -98,7 +98,7 @@ import {
98
98
  calculateTradeSlippage,
99
99
  MARK_PRICE_PRECISION,
100
100
  QUOTE_PRECISION,
101
- } from '@drift/sdk';
101
+ } from '@drift-labs/sdk';
102
102
 
103
103
  export const getTokenAddress = (
104
104
  mintAddress: string,
@@ -180,7 +180,7 @@ const main = async () => {
180
180
  clearingHouse.getMarket(solMarketInfo.marketIndex)
181
181
  );
182
182
 
183
- const formattedPrice = convertToNumber(currentMarketPrice, QUOTE_PRECISION);
183
+ const formattedPrice = convertToNumber(currentMarketPrice, MARK_PRICE_PRECISION);
184
184
 
185
185
  console.log(`Current Market Price is $${formattedPrice}`);
186
186
 
package/lib/index.d.ts CHANGED
@@ -22,5 +22,6 @@ export * from './math/utils';
22
22
  export * from './config';
23
23
  export * from './constants/numericConstants';
24
24
  export * from './util/computeUnits';
25
+ export * from './util/tps';
25
26
  export { BN };
26
27
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAE3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC;AACpC,cAAc,kDAAkD,CAAC;AACjE,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AAEpC,OAAO,EAAE,EAAE,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAE3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC;AACpC,cAAc,kDAAkD,CAAC;AACjE,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,EAAE,EAAE,CAAC"}
package/lib/index.js CHANGED
@@ -36,3 +36,4 @@ __exportStar(require("./math/utils"), exports);
36
36
  __exportStar(require("./config"), exports);
37
37
  __exportStar(require("./constants/numericConstants"), exports);
38
38
  __exportStar(require("./util/computeUnits"), exports);
39
+ __exportStar(require("./util/tps"), exports);
@@ -0,0 +1,3 @@
1
+ import { Connection, PublicKey } from '@solana/web3.js';
2
+ export declare function estimateTps(programId: PublicKey, connection: Connection, failed: boolean): Promise<number>;
3
+ //# sourceMappingURL=tps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tps.d.ts","sourceRoot":"","sources":["../../src/util/tps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,wBAAsB,WAAW,CAChC,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,OAAO,GACb,OAAO,CAAC,MAAM,CAAC,CAoBjB"}
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
package/src/index.ts CHANGED
@@ -23,5 +23,6 @@ export * from './math/utils';
23
23
  export * from './config';
24
24
  export * from './constants/numericConstants';
25
25
  export * from './util/computeUnits';
26
+ export * from './util/tps';
26
27
 
27
28
  export { BN };
@@ -0,0 +1,27 @@
1
+ import { Connection, PublicKey } from '@solana/web3.js';
2
+
3
+ export async function estimateTps(
4
+ programId: PublicKey,
5
+ connection: Connection,
6
+ failed: boolean
7
+ ): Promise<number> {
8
+ let signatures = await connection.getSignaturesForAddress(
9
+ programId,
10
+ undefined,
11
+ 'finalized'
12
+ );
13
+ if (failed) {
14
+ signatures = signatures.filter((signature) => signature.err);
15
+ }
16
+
17
+ const numberOfSignatures = signatures.length;
18
+
19
+ if (numberOfSignatures === 0) {
20
+ return 0;
21
+ }
22
+
23
+ return (
24
+ numberOfSignatures /
25
+ (signatures[0].blockTime - signatures[numberOfSignatures - 1].blockTime)
26
+ );
27
+ }