@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 +2 -2
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/util/tps.d.ts +3 -0
- package/lib/util/tps.d.ts.map +1 -0
- package/lib/util/tps.js +27 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/util/tps.ts +27 -0
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,
|
|
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
package/lib/index.d.ts.map
CHANGED
|
@@ -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,CA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,"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"}
|
package/lib/util/tps.js
ADDED
|
@@ -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
package/src/index.ts
CHANGED
package/src/util/tps.ts
ADDED
|
@@ -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
|
+
}
|