@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.
Files changed (143) hide show
  1. package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +1 -0
  2. package/lib/accounts/pollingClearingHouseAccountSubscriber.js +3 -0
  3. package/lib/accounts/types.d.ts +1 -0
  4. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +1 -0
  5. package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +3 -0
  6. package/lib/admin.d.ts +5 -2
  7. package/lib/admin.js +30 -4
  8. package/lib/clearingHouse.d.ts +2 -0
  9. package/lib/clearingHouse.js +14 -1
  10. package/lib/clearingHouseUser.d.ts +11 -9
  11. package/lib/clearingHouseUser.js +182 -106
  12. package/lib/config.js +1 -1
  13. package/lib/dlob/DLOB.d.ts +73 -0
  14. package/lib/dlob/DLOB.js +557 -0
  15. package/lib/dlob/DLOBNode.d.ts +52 -0
  16. package/lib/dlob/DLOBNode.js +82 -0
  17. package/lib/dlob/NodeList.d.ts +26 -0
  18. package/lib/dlob/NodeList.js +138 -0
  19. package/lib/idl/clearing_house.json +122 -202
  20. package/lib/index.d.ts +5 -0
  21. package/lib/index.js +5 -0
  22. package/lib/math/market.d.ts +1 -1
  23. package/lib/math/market.js +1 -1
  24. package/lib/math/orders.d.ts +3 -3
  25. package/lib/math/orders.js +31 -16
  26. package/lib/math/spotBalance.d.ts +3 -0
  27. package/lib/math/spotBalance.js +18 -1
  28. package/lib/math/spotPosition.d.ts +5 -1
  29. package/lib/math/spotPosition.js +16 -1
  30. package/lib/types.d.ts +24 -23
  31. package/lib/types.js +9 -3
  32. package/lib/userMap/userMap.d.ts +25 -0
  33. package/lib/userMap/userMap.js +73 -0
  34. package/lib/userMap/userStatsMap.d.ts +19 -0
  35. package/lib/userMap/userStatsMap.js +68 -0
  36. package/package.json +6 -3
  37. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +4 -0
  38. package/src/accounts/types.ts +1 -0
  39. package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +6 -0
  40. package/src/addresses/marketAddresses.js +26 -0
  41. package/src/admin.ts +50 -8
  42. package/src/assert/assert.js +1 -1
  43. package/src/clearingHouse.ts +23 -1
  44. package/src/clearingHouseUser.ts +364 -165
  45. package/src/config.ts +1 -1
  46. package/src/constants/banks.js +42 -0
  47. package/src/constants/{perpMarkets.js → markets.js} +11 -11
  48. package/src/dlob/DLOB.ts +884 -0
  49. package/src/dlob/DLOBNode.ts +163 -0
  50. package/src/dlob/NodeList.ts +185 -0
  51. package/src/events/eventList.js +23 -66
  52. package/src/events/txEventCache.js +19 -22
  53. package/src/examples/makeTradeExample.js +157 -0
  54. package/src/factory/bigNum.js +180 -183
  55. package/src/factory/oracleClient.js +9 -9
  56. package/src/idl/clearing_house.json +122 -202
  57. package/src/index.ts +5 -0
  58. package/src/math/auction.js +10 -10
  59. package/src/math/conversion.js +3 -4
  60. package/src/math/funding.js +175 -223
  61. package/src/math/market.ts +1 -1
  62. package/src/math/orders.ts +29 -21
  63. package/src/math/repeg.js +40 -40
  64. package/src/math/spotBalance.ts +26 -0
  65. package/src/math/spotPosition.ts +42 -1
  66. package/src/math/trade.js +74 -81
  67. package/src/math/utils.js +7 -8
  68. package/src/math/utils.js.map +1 -0
  69. package/src/oracles/oracleClientCache.js +9 -10
  70. package/src/oracles/pythClient.js +17 -52
  71. package/src/oracles/quoteAssetOracleClient.js +13 -44
  72. package/src/oracles/switchboardClient.js +37 -69
  73. package/src/oracles/types.js +1 -1
  74. package/src/token/index.js +4 -4
  75. package/src/tx/types.js +1 -1
  76. package/src/tx/utils.js +6 -7
  77. package/src/types.ts +25 -23
  78. package/src/userMap/userMap.ts +100 -0
  79. package/src/userMap/userStatsMap.ts +110 -0
  80. package/src/userName.js +5 -5
  81. package/src/util/computeUnits.js +11 -46
  82. package/src/util/getTokenAddress.js +9 -0
  83. package/src/util/promiseTimeout.js +5 -5
  84. package/src/util/tps.js +12 -46
  85. package/src/wallet.js +18 -55
  86. package/tests/bn/test.ts +2 -3
  87. package/tests/dlob/helpers.ts +322 -0
  88. package/tests/dlob/test.ts +2865 -0
  89. package/my-script/.env +0 -7
  90. package/my-script/getUserStats.ts +0 -106
  91. package/my-script/multiConnections.ts +0 -119
  92. package/my-script/test-regex.ts +0 -11
  93. package/my-script/utils.ts +0 -52
  94. package/src/accounts/bulkAccountLoader.js +0 -249
  95. package/src/accounts/bulkUserStatsSubscription.js +0 -75
  96. package/src/accounts/bulkUserSubscription.js +0 -75
  97. package/src/accounts/fetch.js +0 -92
  98. package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -465
  99. package/src/accounts/pollingOracleSubscriber.js +0 -156
  100. package/src/accounts/pollingTokenAccountSubscriber.js +0 -141
  101. package/src/accounts/pollingUserAccountSubscriber.js +0 -208
  102. package/src/accounts/pollingUserStatsAccountSubscriber.js +0 -208
  103. package/src/accounts/types.js +0 -28
  104. package/src/accounts/utils.js +0 -7
  105. package/src/accounts/webSocketAccountSubscriber.js +0 -138
  106. package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -433
  107. package/src/accounts/webSocketUserAccountSubscriber.js +0 -113
  108. package/src/accounts/webSocketUserStatsAccountSubsriber.js +0 -113
  109. package/src/addresses/pda.js +0 -186
  110. package/src/admin.js +0 -1284
  111. package/src/clearingHouse.js +0 -3433
  112. package/src/clearingHouseConfig.js +0 -2
  113. package/src/clearingHouseUser.js +0 -874
  114. package/src/clearingHouseUserConfig.js +0 -2
  115. package/src/clearingHouseUserStats.js +0 -115
  116. package/src/clearingHouseUserStatsConfig.js +0 -2
  117. package/src/config.js +0 -80
  118. package/src/constants/numericConstants.js +0 -48
  119. package/src/constants/spotMarkets.js +0 -51
  120. package/src/events/eventSubscriber.js +0 -202
  121. package/src/events/fetchLogs.js +0 -117
  122. package/src/events/pollingLogProvider.js +0 -113
  123. package/src/events/sort.js +0 -41
  124. package/src/events/types.js +0 -25
  125. package/src/events/webSocketLogProvider.js +0 -76
  126. package/src/index.js +0 -75
  127. package/src/math/amm.js +0 -422
  128. package/src/math/insurance.js +0 -27
  129. package/src/math/margin.js +0 -77
  130. package/src/math/market.js +0 -105
  131. package/src/math/oracles.js +0 -56
  132. package/src/math/orders.js +0 -153
  133. package/src/math/position.js +0 -172
  134. package/src/math/spotBalance.js +0 -176
  135. package/src/math/spotMarket.js +0 -8
  136. package/src/math/spotPosition.js +0 -8
  137. package/src/orderParams.js +0 -28
  138. package/src/serum/serumSubscriber.js +0 -102
  139. package/src/serum/types.js +0 -2
  140. package/src/slot/SlotSubscriber.js +0 -86
  141. package/src/tokenFaucet.js +0 -323
  142. package/src/tx/retryTxSender.js +0 -280
  143. 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.__esModule = true;
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("User name (".concat(name, ") longer than 32 characters"));
8
+ throw Error(`User name (${name}) longer than 32 characters`);
9
9
  }
10
- var buffer = Buffer.alloc(32);
10
+ const buffer = Buffer.alloc(32);
11
11
  buffer.fill(name);
12
12
  buffer.fill(' ', name.length);
13
- return Array.apply(void 0, buffer);
13
+ return Array(...buffer);
14
14
  }
15
15
  exports.encodeName = encodeName;
16
16
  function decodeName(bytes) {
17
- var buffer = Buffer.from(bytes);
17
+ const buffer = Buffer.from(bytes);
18
18
  return buffer.toString('utf8').trim();
19
19
  }
20
20
  exports.decodeName = decodeName;
@@ -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
- var __generator = (this && this.__generator) || function (thisArg, body) {
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
- if (commitment === void 0) { commitment = 'confirmed'; }
42
- return __awaiter(this, void 0, void 0, function () {
43
- var tx, computeUnits, regex;
44
- return __generator(this, function (_a) {
45
- switch (_a.label) {
46
- case 0: return [4 /*yield*/, connection.getTransaction(txSignature, { commitment: commitment })];
47
- case 1:
48
- tx = _a.sent();
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.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.promiseTimeout = void 0;
4
4
  function promiseTimeout(promise, timeoutMs) {
5
- var timeoutId;
6
- var timeoutPromise = new Promise(function (resolve) {
7
- timeoutId = setTimeout(function () { return resolve(null); }, timeoutMs);
5
+ let timeoutId;
6
+ const timeoutPromise = new Promise((resolve) => {
7
+ timeoutId = setTimeout(() => resolve(null), timeoutMs);
8
8
  });
9
- return Promise.race([promise, timeoutPromise]).then(function (result) {
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
- var __generator = (this && this.__generator) || function (thisArg, body) {
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
- var signatures, numberOfSignatures;
43
- return __generator(this, function (_a) {
44
- switch (_a.label) {
45
- case 0: return [4 /*yield*/, connection.getSignaturesForAddress(programId, undefined, 'finalized')];
46
- case 1:
47
- signatures = _a.sent();
48
- if (failed) {
49
- signatures = signatures.filter(function (signature) { return signature.err; });
50
- }
51
- numberOfSignatures = signatures.length;
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
- var __generator = (this && this.__generator) || function (thisArg, body) {
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
- var Wallet = /** @class */ (function () {
41
- function Wallet(payer) {
13
+ class Wallet {
14
+ constructor(payer) {
42
15
  this.payer = payer;
43
16
  }
44
- Wallet.prototype.signTransaction = function (tx) {
45
- return __awaiter(this, void 0, void 0, function () {
46
- return __generator(this, function (_a) {
47
- tx.partialSign(this.payer);
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
- Wallet.prototype.signAllTransactions = function (txs) {
53
- return __awaiter(this, void 0, void 0, function () {
54
- var _this = this;
55
- return __generator(this, function (_a) {
56
- return [2 /*return*/, txs.map(function (t) {
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
- Object.defineProperty(Wallet.prototype, "publicKey", {
64
- get: function () {
65
- return this.payer.publicKey;
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.567');
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