@drift-labs/sdk 0.2.0-master.26 → 0.2.0-master.27
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/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +1 -0
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +3 -0
- package/lib/accounts/types.d.ts +1 -0
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +1 -0
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +3 -0
- package/lib/admin.d.ts +5 -2
- package/lib/admin.js +30 -4
- package/lib/clearingHouse.d.ts +2 -0
- package/lib/clearingHouse.js +14 -1
- package/lib/clearingHouseUser.d.ts +11 -9
- package/lib/clearingHouseUser.js +182 -106
- package/lib/config.js +1 -1
- package/lib/dlob/DLOB.d.ts +73 -0
- package/lib/dlob/DLOB.js +557 -0
- package/lib/dlob/DLOBNode.d.ts +52 -0
- package/lib/dlob/DLOBNode.js +82 -0
- package/lib/dlob/NodeList.d.ts +26 -0
- package/lib/dlob/NodeList.js +138 -0
- package/lib/idl/clearing_house.json +122 -202
- package/lib/index.d.ts +5 -0
- package/lib/index.js +5 -0
- package/lib/math/market.d.ts +1 -1
- package/lib/math/market.js +1 -1
- package/lib/math/orders.d.ts +3 -3
- package/lib/math/orders.js +31 -16
- package/lib/math/spotBalance.d.ts +3 -0
- package/lib/math/spotBalance.js +18 -1
- package/lib/math/spotPosition.d.ts +5 -1
- package/lib/math/spotPosition.js +16 -1
- package/lib/types.d.ts +24 -23
- package/lib/types.js +9 -3
- package/lib/userMap/userMap.d.ts +25 -0
- package/lib/userMap/userMap.js +73 -0
- package/lib/userMap/userStatsMap.d.ts +19 -0
- package/lib/userMap/userStatsMap.js +68 -0
- package/package.json +6 -3
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +4 -0
- package/src/accounts/types.ts +1 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +6 -0
- package/src/addresses/marketAddresses.js +26 -0
- package/src/admin.ts +50 -8
- package/src/assert/assert.js +1 -1
- package/src/clearingHouse.ts +23 -1
- package/src/clearingHouseUser.ts +364 -165
- package/src/config.ts +1 -1
- package/src/constants/banks.js +42 -0
- package/src/constants/{perpMarkets.js → markets.js} +11 -11
- package/src/dlob/DLOB.ts +884 -0
- package/src/dlob/DLOBNode.ts +163 -0
- package/src/dlob/NodeList.ts +185 -0
- package/src/events/eventList.js +23 -66
- package/src/events/txEventCache.js +19 -22
- package/src/examples/makeTradeExample.js +157 -0
- package/src/factory/bigNum.js +180 -183
- package/src/factory/oracleClient.js +9 -9
- package/src/idl/clearing_house.json +122 -202
- package/src/index.ts +5 -0
- package/src/math/auction.js +10 -10
- package/src/math/conversion.js +3 -4
- package/src/math/funding.js +175 -223
- package/src/math/market.ts +1 -1
- package/src/math/orders.ts +29 -21
- package/src/math/repeg.js +40 -40
- package/src/math/spotBalance.ts +26 -0
- package/src/math/spotPosition.ts +42 -1
- package/src/math/trade.js +74 -81
- package/src/math/utils.js +7 -8
- package/src/math/utils.js.map +1 -0
- package/src/oracles/oracleClientCache.js +9 -10
- package/src/oracles/pythClient.js +17 -52
- package/src/oracles/quoteAssetOracleClient.js +13 -44
- package/src/oracles/switchboardClient.js +37 -69
- package/src/oracles/types.js +1 -1
- package/src/token/index.js +4 -4
- package/src/tx/types.js +1 -1
- package/src/tx/utils.js +6 -7
- package/src/types.ts +25 -23
- package/src/userMap/userMap.ts +100 -0
- package/src/userMap/userStatsMap.ts +110 -0
- package/src/userName.js +5 -5
- package/src/util/computeUnits.js +11 -46
- package/src/util/getTokenAddress.js +9 -0
- package/src/util/promiseTimeout.js +5 -5
- package/src/util/tps.js +12 -46
- package/src/wallet.js +18 -55
- package/tests/bn/test.ts +2 -3
- package/tests/dlob/helpers.ts +322 -0
- package/tests/dlob/test.ts +2865 -0
- package/my-script/.env +0 -7
- package/my-script/getUserStats.ts +0 -106
- package/my-script/multiConnections.ts +0 -119
- package/my-script/test-regex.ts +0 -11
- package/my-script/utils.ts +0 -52
- package/src/accounts/bulkAccountLoader.js +0 -249
- package/src/accounts/bulkUserStatsSubscription.js +0 -75
- package/src/accounts/bulkUserSubscription.js +0 -75
- package/src/accounts/fetch.js +0 -92
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -465
- package/src/accounts/pollingOracleSubscriber.js +0 -156
- package/src/accounts/pollingTokenAccountSubscriber.js +0 -141
- package/src/accounts/pollingUserAccountSubscriber.js +0 -208
- package/src/accounts/pollingUserStatsAccountSubscriber.js +0 -208
- package/src/accounts/types.js +0 -28
- package/src/accounts/utils.js +0 -7
- package/src/accounts/webSocketAccountSubscriber.js +0 -138
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -433
- package/src/accounts/webSocketUserAccountSubscriber.js +0 -113
- package/src/accounts/webSocketUserStatsAccountSubsriber.js +0 -113
- package/src/addresses/pda.js +0 -186
- package/src/admin.js +0 -1284
- package/src/clearingHouse.js +0 -3433
- package/src/clearingHouseConfig.js +0 -2
- package/src/clearingHouseUser.js +0 -874
- package/src/clearingHouseUserConfig.js +0 -2
- package/src/clearingHouseUserStats.js +0 -115
- package/src/clearingHouseUserStatsConfig.js +0 -2
- package/src/config.js +0 -80
- package/src/constants/numericConstants.js +0 -48
- package/src/constants/spotMarkets.js +0 -51
- package/src/events/eventSubscriber.js +0 -202
- package/src/events/fetchLogs.js +0 -117
- package/src/events/pollingLogProvider.js +0 -113
- package/src/events/sort.js +0 -41
- package/src/events/types.js +0 -25
- package/src/events/webSocketLogProvider.js +0 -76
- package/src/index.js +0 -75
- package/src/math/amm.js +0 -422
- package/src/math/insurance.js +0 -27
- package/src/math/margin.js +0 -77
- package/src/math/market.js +0 -105
- package/src/math/oracles.js +0 -56
- package/src/math/orders.js +0 -153
- package/src/math/position.js +0 -172
- package/src/math/spotBalance.js +0 -176
- package/src/math/spotMarket.js +0 -8
- package/src/math/spotPosition.js +0 -8
- package/src/orderParams.js +0 -28
- package/src/serum/serumSubscriber.js +0 -102
- package/src/serum/types.js +0 -2
- package/src/slot/SlotSubscriber.js +0 -86
- package/src/tokenFaucet.js +0 -323
- package/src/tx/retryTxSender.js +0 -280
- package/src/types.js +0 -216
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClearingHouse,
|
|
3
|
+
getUserStatsAccountPublicKey,
|
|
4
|
+
OrderRecord,
|
|
5
|
+
UserStatsAccount,
|
|
6
|
+
ClearingHouseUserStats,
|
|
7
|
+
ClearingHouseUserStatsAccountSubscriptionConfig,
|
|
8
|
+
bulkPollingUserStatsSubscribe,
|
|
9
|
+
} from '..';
|
|
10
|
+
import { ProgramAccount } from '@project-serum/anchor';
|
|
11
|
+
import { PublicKey } from '@solana/web3.js';
|
|
12
|
+
|
|
13
|
+
import { UserMap } from './userMap';
|
|
14
|
+
|
|
15
|
+
export class UserStatsMap {
|
|
16
|
+
/**
|
|
17
|
+
* map from authority pubkey to ClearingHouseUserStats
|
|
18
|
+
*/
|
|
19
|
+
private userStatsMap = new Map<string, ClearingHouseUserStats>();
|
|
20
|
+
private clearingHouse: ClearingHouse;
|
|
21
|
+
private accountSubscription: ClearingHouseUserStatsAccountSubscriptionConfig;
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
clearingHouse: ClearingHouse,
|
|
25
|
+
accountSubscription: ClearingHouseUserStatsAccountSubscriptionConfig
|
|
26
|
+
) {
|
|
27
|
+
this.clearingHouse = clearingHouse;
|
|
28
|
+
this.accountSubscription = accountSubscription;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public async fetchAllUserStats() {
|
|
32
|
+
const userStatArray: ClearingHouseUserStats[] = [];
|
|
33
|
+
|
|
34
|
+
const programUserAccounts =
|
|
35
|
+
(await this.clearingHouse.program.account.userStats.all()) as ProgramAccount<UserStatsAccount>[];
|
|
36
|
+
|
|
37
|
+
for (const programUserAccount of programUserAccounts) {
|
|
38
|
+
const userStat: UserStatsAccount = programUserAccount.account;
|
|
39
|
+
if (this.userStatsMap.has(userStat.authority.toString())) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const chUserStat = new ClearingHouseUserStats({
|
|
44
|
+
clearingHouse: this.clearingHouse,
|
|
45
|
+
userStatsAccountPublicKey: getUserStatsAccountPublicKey(
|
|
46
|
+
this.clearingHouse.program.programId,
|
|
47
|
+
userStat.authority
|
|
48
|
+
),
|
|
49
|
+
accountSubscription: this.accountSubscription,
|
|
50
|
+
});
|
|
51
|
+
userStatArray.push(chUserStat);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (this.accountSubscription.type === 'polling') {
|
|
55
|
+
await bulkPollingUserStatsSubscribe(
|
|
56
|
+
userStatArray,
|
|
57
|
+
this.accountSubscription.accountLoader
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
for (const userStat of userStatArray) {
|
|
62
|
+
this.userStatsMap.set(
|
|
63
|
+
userStat.getAccount().authority.toString(),
|
|
64
|
+
userStat
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public async addUserStat(authority: PublicKey) {
|
|
70
|
+
const userStat = new ClearingHouseUserStats({
|
|
71
|
+
clearingHouse: this.clearingHouse,
|
|
72
|
+
userStatsAccountPublicKey: getUserStatsAccountPublicKey(
|
|
73
|
+
this.clearingHouse.program.programId,
|
|
74
|
+
authority
|
|
75
|
+
),
|
|
76
|
+
accountSubscription: this.accountSubscription,
|
|
77
|
+
});
|
|
78
|
+
await userStat.subscribe();
|
|
79
|
+
|
|
80
|
+
this.userStatsMap.set(authority.toString(), userStat);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public async updateWithOrderRecord(record: OrderRecord, userMap: UserMap) {
|
|
84
|
+
if (!this.has(record.user.toString())) {
|
|
85
|
+
const takerUserAccount = await userMap.mustGet(record.user.toString());
|
|
86
|
+
this.addUserStat(takerUserAccount.getUserAccount().authority);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public has(authorityPublicKey: string): boolean {
|
|
91
|
+
return this.userStatsMap.has(authorityPublicKey);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public get(authorityPublicKey: string): ClearingHouseUserStats {
|
|
95
|
+
return this.userStatsMap.get(authorityPublicKey);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public async mustGet(
|
|
99
|
+
authorityPublicKey: string
|
|
100
|
+
): Promise<ClearingHouseUserStats> {
|
|
101
|
+
if (!this.has(authorityPublicKey)) {
|
|
102
|
+
await this.addUserStat(new PublicKey(authorityPublicKey));
|
|
103
|
+
}
|
|
104
|
+
return this.get(authorityPublicKey);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public values(): IterableIterator<ClearingHouseUserStats> {
|
|
108
|
+
return this.userStatsMap.values();
|
|
109
|
+
}
|
|
110
|
+
}
|
package/src/userName.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.decodeName = exports.encodeName = exports.DEFAULT_USER_NAME = exports.MAX_NAME_LENGTH = void 0;
|
|
4
4
|
exports.MAX_NAME_LENGTH = 32;
|
|
5
5
|
exports.DEFAULT_USER_NAME = 'Main Account';
|
|
6
6
|
function encodeName(name) {
|
|
7
7
|
if (name.length > exports.MAX_NAME_LENGTH) {
|
|
8
|
-
throw Error(
|
|
8
|
+
throw Error(`User name (${name}) longer than 32 characters`);
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
const buffer = Buffer.alloc(32);
|
|
11
11
|
buffer.fill(name);
|
|
12
12
|
buffer.fill(' ', name.length);
|
|
13
|
-
return Array
|
|
13
|
+
return Array(...buffer);
|
|
14
14
|
}
|
|
15
15
|
exports.encodeName = encodeName;
|
|
16
16
|
function decodeName(bytes) {
|
|
17
|
-
|
|
17
|
+
const buffer = Buffer.from(bytes);
|
|
18
18
|
return buffer.toString('utf8').trim();
|
|
19
19
|
}
|
|
20
20
|
exports.decodeName = decodeName;
|
package/src/util/computeUnits.js
CHANGED
|
@@ -8,55 +8,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
exports.__esModule = true;
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
12
|
exports.findComputeUnitConsumption = void 0;
|
|
40
|
-
function findComputeUnitConsumption(programId, connection, txSignature, commitment) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
computeUnits = [];
|
|
50
|
-
regex = new RegExp("Program ".concat(programId.toString(), " consumed ([0-9]{0,6}) of ([0-9]{0,7}) compute units"));
|
|
51
|
-
tx.meta.logMessages.forEach(function (logMessage) {
|
|
52
|
-
var match = logMessage.match(regex);
|
|
53
|
-
if (match && match[1]) {
|
|
54
|
-
computeUnits.push(match[1]);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
return [2 /*return*/, computeUnits];
|
|
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]);
|
|
58
22
|
}
|
|
59
23
|
});
|
|
24
|
+
return computeUnits;
|
|
60
25
|
});
|
|
61
26
|
}
|
|
62
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;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.promiseTimeout = void 0;
|
|
4
4
|
function promiseTimeout(promise, timeoutMs) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
timeoutId = setTimeout(
|
|
5
|
+
let timeoutId;
|
|
6
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
7
|
+
timeoutId = setTimeout(() => resolve(null), timeoutMs);
|
|
8
8
|
});
|
|
9
|
-
return Promise.race([promise, timeoutPromise]).then(
|
|
9
|
+
return Promise.race([promise, timeoutPromise]).then((result) => {
|
|
10
10
|
clearTimeout(timeoutId);
|
|
11
11
|
return result;
|
|
12
12
|
});
|
package/src/util/tps.js
CHANGED
|
@@ -8,54 +8,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
exports.__esModule = true;
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
12
|
exports.estimateTps = void 0;
|
|
40
13
|
function estimateTps(programId, connection, failed) {
|
|
41
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (numberOfSignatures === 0) {
|
|
53
|
-
return [2 /*return*/, 0];
|
|
54
|
-
}
|
|
55
|
-
return [2 /*return*/, (numberOfSignatures /
|
|
56
|
-
(signatures[0].blockTime - signatures[numberOfSignatures - 1].blockTime))];
|
|
57
|
-
}
|
|
58
|
-
});
|
|
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));
|
|
59
25
|
});
|
|
60
26
|
}
|
|
61
27
|
exports.estimateTps = estimateTps;
|
package/src/wallet.js
CHANGED
|
@@ -8,65 +8,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
exports.__esModule = true;
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
12
|
exports.Wallet = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
13
|
+
class Wallet {
|
|
14
|
+
constructor(payer) {
|
|
42
15
|
this.payer = payer;
|
|
43
16
|
}
|
|
44
|
-
|
|
45
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return [2 /*return*/, tx];
|
|
49
|
-
});
|
|
17
|
+
signTransaction(tx) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
tx.partialSign(this.payer);
|
|
20
|
+
return tx;
|
|
50
21
|
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return
|
|
57
|
-
t.partialSign(_this.payer);
|
|
58
|
-
return t;
|
|
59
|
-
})];
|
|
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;
|
|
60
28
|
});
|
|
61
29
|
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
enumerable: false,
|
|
68
|
-
configurable: true
|
|
69
|
-
});
|
|
70
|
-
return Wallet;
|
|
71
|
-
}());
|
|
30
|
+
}
|
|
31
|
+
get publicKey() {
|
|
32
|
+
return this.payer.publicKey;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
72
35
|
exports.Wallet = Wallet;
|
package/tests/bn/test.ts
CHANGED
|
@@ -70,8 +70,7 @@ describe('BigNum Tests', () => {
|
|
|
70
70
|
|
|
71
71
|
expect(val.print()).to.equal('1234.56789');
|
|
72
72
|
|
|
73
|
-
expect(val.toFixed(3)).to.equal('1234.
|
|
74
|
-
|
|
73
|
+
expect(val.toNum().toFixed(3)).to.equal('1234.568');
|
|
75
74
|
expect(val.toPrecision(1)).to.equal('1e3');
|
|
76
75
|
expect(val.toPrecision(3)).to.equal('123e1');
|
|
77
76
|
expect(val.toPrecision(4)).to.equal('1234');
|
|
@@ -102,7 +101,7 @@ describe('BigNum Tests', () => {
|
|
|
102
101
|
|
|
103
102
|
expect(val4.toString()).to.equal('250000000000');
|
|
104
103
|
expect(val4.print()).to.equal('0.0250000000000');
|
|
105
|
-
expect(val4.toFixed(3)).to.equal('0.025');
|
|
104
|
+
expect(val4.toNum().toFixed(3)).to.equal('0.025');
|
|
106
105
|
expect(val4.toPrecision(4)).to.equal('0.025');
|
|
107
106
|
|
|
108
107
|
// Case 5
|