@helium/spl-utils 0.0.1
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/LICENSE +203 -0
- package/lib/cjs/accountFetchCache/accountFetchCache.js +365 -0
- package/lib/cjs/accountFetchCache/accountFetchCache.js.map +1 -0
- package/lib/cjs/accountFetchCache/eventEmitter.js +37 -0
- package/lib/cjs/accountFetchCache/eventEmitter.js.map +1 -0
- package/lib/cjs/accountFetchCache/getMultipleAccounts.js +53 -0
- package/lib/cjs/accountFetchCache/getMultipleAccounts.js.map +1 -0
- package/lib/cjs/accountFetchCache/index.js +20 -0
- package/lib/cjs/accountFetchCache/index.js.map +1 -0
- package/lib/cjs/accountsResolver/ataResolver.js +35 -0
- package/lib/cjs/accountsResolver/ataResolver.js.map +1 -0
- package/lib/cjs/accountsResolver/combineResolvers.js +27 -0
- package/lib/cjs/accountsResolver/combineResolvers.js.map +1 -0
- package/lib/cjs/accountsResolver/individual.js +90 -0
- package/lib/cjs/accountsResolver/individual.js.map +1 -0
- package/lib/cjs/accountsResolver/utils.js +32 -0
- package/lib/cjs/accountsResolver/utils.js.map +1 -0
- package/lib/cjs/anchorError.js +265 -0
- package/lib/cjs/anchorError.js.map +1 -0
- package/lib/cjs/constants.js +8 -0
- package/lib/cjs/constants.js.map +1 -0
- package/lib/cjs/executeRemoteTxn.js +109 -0
- package/lib/cjs/executeRemoteTxn.js.map +1 -0
- package/lib/cjs/extendBorsh.js +33 -0
- package/lib/cjs/extendBorsh.js.map +1 -0
- package/lib/cjs/index.js +35 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/token.js +196 -0
- package/lib/cjs/token.js.map +1 -0
- package/lib/cjs/transaction.js +308 -0
- package/lib/cjs/transaction.js.map +1 -0
- package/lib/cjs/utils.js +58 -0
- package/lib/cjs/utils.js.map +1 -0
- package/lib/esm/src/accountFetchCache/accountFetchCache.js +338 -0
- package/lib/esm/src/accountFetchCache/accountFetchCache.js.map +1 -0
- package/lib/esm/src/accountFetchCache/eventEmitter.js +33 -0
- package/lib/esm/src/accountFetchCache/eventEmitter.js.map +1 -0
- package/lib/esm/src/accountFetchCache/getMultipleAccounts.js +32 -0
- package/lib/esm/src/accountFetchCache/getMultipleAccounts.js.map +1 -0
- package/lib/esm/src/accountFetchCache/index.js +4 -0
- package/lib/esm/src/accountFetchCache/index.js.map +1 -0
- package/lib/esm/src/accountsResolver/ataResolver.js +22 -0
- package/lib/esm/src/accountsResolver/ataResolver.js.map +1 -0
- package/lib/esm/src/accountsResolver/combineResolvers.js +14 -0
- package/lib/esm/src/accountsResolver/combineResolvers.js.map +1 -0
- package/lib/esm/src/accountsResolver/individual.js +72 -0
- package/lib/esm/src/accountsResolver/individual.js.map +1 -0
- package/lib/esm/src/accountsResolver/utils.js +27 -0
- package/lib/esm/src/accountsResolver/utils.js.map +1 -0
- package/lib/esm/src/anchorError.js +262 -0
- package/lib/esm/src/anchorError.js.map +1 -0
- package/lib/esm/src/constants.js +5 -0
- package/lib/esm/src/constants.js.map +1 -0
- package/lib/esm/src/executeRemoteTxn.js +79 -0
- package/lib/esm/src/executeRemoteTxn.js.map +1 -0
- package/lib/esm/src/extendBorsh.js +26 -0
- package/lib/esm/src/extendBorsh.js.map +1 -0
- package/lib/esm/src/index.js +13 -0
- package/lib/esm/src/index.js.map +1 -0
- package/lib/esm/src/token.js +175 -0
- package/lib/esm/src/token.js.map +1 -0
- package/lib/esm/src/transaction.js +274 -0
- package/lib/esm/src/transaction.js.map +1 -0
- package/lib/esm/src/utils.js +44 -0
- package/lib/esm/src/utils.js.map +1 -0
- package/lib/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/lib/types/src/accountFetchCache/accountFetchCache.d.ts +67 -0
- package/lib/types/src/accountFetchCache/accountFetchCache.d.ts.map +1 -0
- package/lib/types/src/accountFetchCache/eventEmitter.d.ts +19 -0
- package/lib/types/src/accountFetchCache/eventEmitter.d.ts.map +1 -0
- package/lib/types/src/accountFetchCache/getMultipleAccounts.d.ts +7 -0
- package/lib/types/src/accountFetchCache/getMultipleAccounts.d.ts.map +1 -0
- package/lib/types/src/accountFetchCache/index.d.ts +4 -0
- package/lib/types/src/accountFetchCache/index.d.ts.map +1 -0
- package/lib/types/src/accountsResolver/ataResolver.d.ts +9 -0
- package/lib/types/src/accountsResolver/ataResolver.d.ts.map +1 -0
- package/lib/types/src/accountsResolver/combineResolvers.d.ts +3 -0
- package/lib/types/src/accountsResolver/combineResolvers.d.ts.map +1 -0
- package/lib/types/src/accountsResolver/individual.d.ts +25 -0
- package/lib/types/src/accountsResolver/individual.d.ts.map +1 -0
- package/lib/types/src/accountsResolver/utils.d.ts +7 -0
- package/lib/types/src/accountsResolver/utils.d.ts.map +1 -0
- package/lib/types/src/anchorError.d.ts +9 -0
- package/lib/types/src/anchorError.d.ts.map +1 -0
- package/lib/types/src/constants.d.ts +5 -0
- package/lib/types/src/constants.d.ts.map +1 -0
- package/lib/types/src/executeRemoteTxn.d.ts +23 -0
- package/lib/types/src/executeRemoteTxn.d.ts.map +1 -0
- package/lib/types/src/extendBorsh.d.ts +3 -0
- package/lib/types/src/extendBorsh.d.ts.map +1 -0
- package/lib/types/src/index.d.ts +13 -0
- package/lib/types/src/index.d.ts.map +1 -0
- package/lib/types/src/token.d.ts +16 -0
- package/lib/types/src/token.d.ts.map +1 -0
- package/lib/types/src/transaction.d.ts +26 -0
- package/lib/types/src/transaction.d.ts.map +1 -0
- package/lib/types/src/utils.d.ts +12 -0
- package/lib/types/src/utils.d.ts.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,308 @@
|
|
|
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.sendAndConfirmWithRetry = exports.awaitTransactionSignatureConfirmation = exports.executeBig = exports.execute = exports.sendMultipleInstructions = exports.sendInstructions = void 0;
|
|
13
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
14
|
+
const anchorError_1 = require("./anchorError");
|
|
15
|
+
function sleep(ms) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function promiseAllInOrder(it) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
let ret = [];
|
|
23
|
+
for (const i of it) {
|
|
24
|
+
ret.push(yield i());
|
|
25
|
+
}
|
|
26
|
+
return ret;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function sendInstructions(provider, instructions, signers = [], payer = provider.wallet.publicKey, commitment = "confirmed", idlErrors = new Map()) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
let tx = new web3_js_1.Transaction();
|
|
32
|
+
tx.recentBlockhash = (yield provider.connection.getRecentBlockhash()).blockhash;
|
|
33
|
+
tx.feePayer = payer || provider.wallet.publicKey;
|
|
34
|
+
tx.add(...instructions);
|
|
35
|
+
if (signers.length > 0) {
|
|
36
|
+
tx.partialSign(...signers);
|
|
37
|
+
}
|
|
38
|
+
tx = yield provider.wallet.signTransaction(tx);
|
|
39
|
+
try {
|
|
40
|
+
const { txid } = yield sendAndConfirmWithRetry(provider.connection, tx.serialize(), {
|
|
41
|
+
skipPreflight: true,
|
|
42
|
+
}, commitment);
|
|
43
|
+
return txid;
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
console.error(e);
|
|
47
|
+
const wrappedE = anchorError_1.ProgramError.parse(e, idlErrors);
|
|
48
|
+
throw wrappedE == null ? e : wrappedE;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
exports.sendInstructions = sendInstructions;
|
|
53
|
+
function truthy(value) {
|
|
54
|
+
return !!value;
|
|
55
|
+
}
|
|
56
|
+
function sendMultipleInstructions(provider, instructionGroups, signerGroups, payer, finality = "confirmed", idlErrors = new Map()) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const recentBlockhash = (yield provider.connection.getRecentBlockhash("confirmed")).blockhash;
|
|
59
|
+
const ixAndSigners = instructionGroups
|
|
60
|
+
.map((instructions, i) => {
|
|
61
|
+
const signers = signerGroups[i];
|
|
62
|
+
return {
|
|
63
|
+
instructions,
|
|
64
|
+
signers,
|
|
65
|
+
};
|
|
66
|
+
})
|
|
67
|
+
.filter(({ instructions }) => instructions.length > 0);
|
|
68
|
+
const txns = ixAndSigners.map(({ instructions }) => {
|
|
69
|
+
const tx = new web3_js_1.Transaction({
|
|
70
|
+
feePayer: payer || provider.wallet.publicKey,
|
|
71
|
+
recentBlockhash,
|
|
72
|
+
});
|
|
73
|
+
tx.add(...instructions);
|
|
74
|
+
return tx;
|
|
75
|
+
});
|
|
76
|
+
const txnsSignedByWallet = yield provider.wallet.signAllTransactions(txns);
|
|
77
|
+
const txnsSigned = txnsSignedByWallet
|
|
78
|
+
.map((tx, index) => {
|
|
79
|
+
const signers = ixAndSigners[index].signers;
|
|
80
|
+
if (signers.length > 0) {
|
|
81
|
+
tx.partialSign(...signers);
|
|
82
|
+
}
|
|
83
|
+
return tx;
|
|
84
|
+
})
|
|
85
|
+
.map((tx) => tx.serialize());
|
|
86
|
+
console.log("Sending multiple transactions...");
|
|
87
|
+
try {
|
|
88
|
+
return yield promiseAllInOrder(txnsSigned.map((txn) => () => __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const { txid } = yield sendAndConfirmWithRetry(provider.connection, txn, {
|
|
90
|
+
skipPreflight: true,
|
|
91
|
+
}, finality);
|
|
92
|
+
return txid;
|
|
93
|
+
})));
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
console.error(e);
|
|
97
|
+
const wrappedE = anchorError_1.ProgramError.parse(e, idlErrors);
|
|
98
|
+
throw wrappedE == null ? e : wrappedE;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
exports.sendMultipleInstructions = sendMultipleInstructions;
|
|
103
|
+
function execute(program, provider, command, payer = provider.wallet.publicKey, commitment) {
|
|
104
|
+
var _a;
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
const { instructions, signers, output } = command;
|
|
107
|
+
const errors = (_a = program.idl.errors) === null || _a === void 0 ? void 0 : _a.reduce((acc, err) => {
|
|
108
|
+
acc.set(err.code, `${err.name}: ${err.msg}`);
|
|
109
|
+
return acc;
|
|
110
|
+
}, new Map());
|
|
111
|
+
if (instructions.length > 0) {
|
|
112
|
+
const txid = yield sendInstructions(provider, instructions, signers, payer, commitment, errors);
|
|
113
|
+
return Object.assign({ txid }, output);
|
|
114
|
+
}
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
return output;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
exports.execute = execute;
|
|
120
|
+
function executeBig(program, provider, command, payer = provider.wallet.publicKey, finality) {
|
|
121
|
+
var _a;
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
const { instructions, signers, output } = command;
|
|
124
|
+
const errors = (_a = program.idl.errors) === null || _a === void 0 ? void 0 : _a.reduce((acc, err) => {
|
|
125
|
+
acc.set(err.code, `${err.name}: ${err.msg}`);
|
|
126
|
+
return acc;
|
|
127
|
+
}, new Map());
|
|
128
|
+
if (instructions.length > 0) {
|
|
129
|
+
const txids = yield sendMultipleInstructions(provider, instructions, signers, payer || provider.wallet.publicKey, finality, errors);
|
|
130
|
+
return Object.assign(Object.assign({}, output), { txids: Array.from(txids) });
|
|
131
|
+
}
|
|
132
|
+
// @ts-ignore
|
|
133
|
+
return output;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
exports.executeBig = executeBig;
|
|
137
|
+
function getUnixTime() {
|
|
138
|
+
return new Date().valueOf() / 1000;
|
|
139
|
+
}
|
|
140
|
+
const awaitTransactionSignatureConfirmation = (txid, timeout, connection, commitment = "recent", queryStatus = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
141
|
+
let done = false;
|
|
142
|
+
let status = {
|
|
143
|
+
slot: 0,
|
|
144
|
+
confirmations: 0,
|
|
145
|
+
err: null,
|
|
146
|
+
};
|
|
147
|
+
let subId = 0;
|
|
148
|
+
status = yield new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
149
|
+
setTimeout(() => {
|
|
150
|
+
if (done) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
done = true;
|
|
154
|
+
console.log("Rejecting for timeout...");
|
|
155
|
+
reject({ timeout: true });
|
|
156
|
+
}, timeout);
|
|
157
|
+
try {
|
|
158
|
+
subId = connection.onSignature(txid, (result, context) => {
|
|
159
|
+
done = true;
|
|
160
|
+
status = {
|
|
161
|
+
err: result.err,
|
|
162
|
+
slot: context.slot,
|
|
163
|
+
confirmations: 0,
|
|
164
|
+
};
|
|
165
|
+
if (result.err) {
|
|
166
|
+
console.log("Rejected via websocket", result.err);
|
|
167
|
+
reject(status);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
resolve(status);
|
|
171
|
+
}
|
|
172
|
+
}, commitment);
|
|
173
|
+
}
|
|
174
|
+
catch (e) {
|
|
175
|
+
done = true;
|
|
176
|
+
console.error("WS error in setup", txid, e);
|
|
177
|
+
}
|
|
178
|
+
while (!done && queryStatus) {
|
|
179
|
+
// eslint-disable-next-line no-loop-func
|
|
180
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
181
|
+
try {
|
|
182
|
+
const signatureStatuses = yield connection.getSignatureStatuses([
|
|
183
|
+
txid,
|
|
184
|
+
]);
|
|
185
|
+
status = signatureStatuses && signatureStatuses.value[0];
|
|
186
|
+
if (!done) {
|
|
187
|
+
if (!status) {
|
|
188
|
+
}
|
|
189
|
+
else if (status.err) {
|
|
190
|
+
console.log("REST error for", txid, status);
|
|
191
|
+
done = true;
|
|
192
|
+
reject(status.err);
|
|
193
|
+
}
|
|
194
|
+
else if (!status.confirmations && !status.confirmationStatus) {
|
|
195
|
+
console.log("REST no confirmations for", txid, status);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
console.log("REST confirmation for", txid, status);
|
|
199
|
+
if (!status.confirmationStatus ||
|
|
200
|
+
status.confirmationStatus == commitment) {
|
|
201
|
+
done = true;
|
|
202
|
+
resolve(status);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
catch (e) {
|
|
208
|
+
if (!done) {
|
|
209
|
+
console.log("REST connection error: txid", txid, e);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}))();
|
|
213
|
+
yield sleep(2000);
|
|
214
|
+
}
|
|
215
|
+
}));
|
|
216
|
+
if (
|
|
217
|
+
//@ts-ignore
|
|
218
|
+
connection._signatureSubscriptions &&
|
|
219
|
+
//@ts-ignore
|
|
220
|
+
connection._signatureSubscriptions[subId]) {
|
|
221
|
+
connection.removeSignatureListener(subId);
|
|
222
|
+
}
|
|
223
|
+
done = true;
|
|
224
|
+
return status;
|
|
225
|
+
});
|
|
226
|
+
exports.awaitTransactionSignatureConfirmation = awaitTransactionSignatureConfirmation;
|
|
227
|
+
function simulateTransaction(connection, transaction, commitment) {
|
|
228
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
// @ts-ignore
|
|
230
|
+
transaction.recentBlockhash = yield connection._recentBlockhash(
|
|
231
|
+
// @ts-ignore
|
|
232
|
+
connection._disableBlockhashCaching);
|
|
233
|
+
const signData = transaction.serializeMessage();
|
|
234
|
+
// @ts-ignore
|
|
235
|
+
const wireTransaction = transaction._serialize(signData);
|
|
236
|
+
const encodedTransaction = wireTransaction.toString("base64");
|
|
237
|
+
const config = { encoding: "base64", commitment };
|
|
238
|
+
const args = [encodedTransaction, config];
|
|
239
|
+
// @ts-ignore
|
|
240
|
+
const res = yield connection._rpcRequest("simulateTransaction", args);
|
|
241
|
+
if (res.error) {
|
|
242
|
+
throw new Error("failed to simulate transaction: " + res.error.message);
|
|
243
|
+
}
|
|
244
|
+
return res.result;
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
const DEFAULT_TIMEOUT = 3 * 60 * 1000; // 3 minutes
|
|
248
|
+
/*
|
|
249
|
+
A validator has up to 120s to accept the transaction and send it into a block.
|
|
250
|
+
If it doesn’t happen within that timeframe, your transaction is dropped and you’ll need
|
|
251
|
+
to send the transaction again. You can get the transaction signature and periodically
|
|
252
|
+
Ping the network for that transaction signature. If you never get anything back,
|
|
253
|
+
that means it’s definitely been dropped. If you do get a response back, you can keep pingindg
|
|
254
|
+
that means it’s definitely been dropped. If you do get a response back, you can keep pingindg
|
|
255
|
+
until it’s gone to a confirmed status to move on.
|
|
256
|
+
*/
|
|
257
|
+
function sendAndConfirmWithRetry(connection, txn, sendOptions, commitment, timeout = DEFAULT_TIMEOUT) {
|
|
258
|
+
var _a, _b;
|
|
259
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
260
|
+
let done = false;
|
|
261
|
+
let slot = 0;
|
|
262
|
+
const txid = yield connection.sendRawTransaction(txn, sendOptions);
|
|
263
|
+
const startTime = getUnixTime();
|
|
264
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
265
|
+
while (!done && getUnixTime() - startTime < timeout) {
|
|
266
|
+
yield connection.sendRawTransaction(txn, sendOptions);
|
|
267
|
+
yield sleep(500);
|
|
268
|
+
}
|
|
269
|
+
}))();
|
|
270
|
+
try {
|
|
271
|
+
const confirmation = yield (0, exports.awaitTransactionSignatureConfirmation)(txid, timeout, connection, commitment, true);
|
|
272
|
+
if (!confirmation)
|
|
273
|
+
throw new Error("Timed out awaiting confirmation on transaction");
|
|
274
|
+
if (confirmation.err) {
|
|
275
|
+
const tx = yield connection.getTransaction(txid, {
|
|
276
|
+
commitment: "confirmed",
|
|
277
|
+
});
|
|
278
|
+
console.error((_b = (_a = tx === null || tx === void 0 ? void 0 : tx.meta) === null || _a === void 0 ? void 0 : _a.logMessages) === null || _b === void 0 ? void 0 : _b.join("\n"));
|
|
279
|
+
console.error(confirmation.err);
|
|
280
|
+
throw new Error("Transaction failed: Custom instruction error");
|
|
281
|
+
}
|
|
282
|
+
slot = (confirmation === null || confirmation === void 0 ? void 0 : confirmation.slot) || 0;
|
|
283
|
+
}
|
|
284
|
+
catch (err) {
|
|
285
|
+
console.error("Error caught", err);
|
|
286
|
+
if (err.timeout) {
|
|
287
|
+
throw new Error("Timed out awaiting confirmation on transaction");
|
|
288
|
+
}
|
|
289
|
+
const tx = yield connection.getTransaction(txid, {
|
|
290
|
+
commitment: "confirmed",
|
|
291
|
+
});
|
|
292
|
+
if (tx && tx.meta && tx.meta.logMessages) {
|
|
293
|
+
console.error(tx.meta.logMessages.join("\n"));
|
|
294
|
+
}
|
|
295
|
+
if (err.err) {
|
|
296
|
+
throw err.err;
|
|
297
|
+
}
|
|
298
|
+
throw err;
|
|
299
|
+
}
|
|
300
|
+
finally {
|
|
301
|
+
done = true;
|
|
302
|
+
}
|
|
303
|
+
console.log("Latency", txid, getUnixTime() - startTime);
|
|
304
|
+
return { txid };
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
exports.sendAndConfirmWithRetry = sendAndConfirmWithRetry;
|
|
308
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../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58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.humanReadable = exports.roundToDecimals = exports.numberWithCommas = exports.supplyAsNum = exports.toBN = exports.amountAsNum = exports.toNumber = exports.truthy = void 0;
|
|
7
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
8
|
+
const truthy = (value) => !!value;
|
|
9
|
+
exports.truthy = truthy;
|
|
10
|
+
function toNumber(numberOrBn, mintOrDecimals) {
|
|
11
|
+
if (bn_js_1.default.isBN(numberOrBn)) {
|
|
12
|
+
return amountAsNum(numberOrBn, mintOrDecimals);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return numberOrBn;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.toNumber = toNumber;
|
|
19
|
+
function amountAsNum(amount, mintOrDecimals) {
|
|
20
|
+
const decimals = typeof mintOrDecimals === "number"
|
|
21
|
+
? mintOrDecimals
|
|
22
|
+
: mintOrDecimals.decimals;
|
|
23
|
+
const factor = new bn_js_1.default(Math.pow(10, decimals).toString());
|
|
24
|
+
const decimal = amount.mod(factor).toNumber() / factor.toNumber();
|
|
25
|
+
return amount.div(factor).toNumber() + decimal;
|
|
26
|
+
}
|
|
27
|
+
exports.amountAsNum = amountAsNum;
|
|
28
|
+
function toBN(numberOrBn, mintOrDecimals) {
|
|
29
|
+
const decimals = typeof mintOrDecimals === "number"
|
|
30
|
+
? mintOrDecimals
|
|
31
|
+
: mintOrDecimals.decimals;
|
|
32
|
+
if (bn_js_1.default.isBN(numberOrBn)) {
|
|
33
|
+
return numberOrBn;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return new bn_js_1.default(Math.ceil(Number(numberOrBn) * Math.pow(10, decimals)).toLocaleString("fullwide", { useGrouping: false }));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.toBN = toBN;
|
|
40
|
+
function supplyAsNum(mint) {
|
|
41
|
+
return amountAsNum(new bn_js_1.default(mint.supply.toString()), mint);
|
|
42
|
+
}
|
|
43
|
+
exports.supplyAsNum = supplyAsNum;
|
|
44
|
+
function numberWithCommas(x, decimals = 4) {
|
|
45
|
+
return roundToDecimals(x, decimals).toLocaleString("en-US", {
|
|
46
|
+
maximumFractionDigits: decimals,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.numberWithCommas = numberWithCommas;
|
|
50
|
+
function roundToDecimals(num, decimals) {
|
|
51
|
+
return Math.trunc(num * Math.pow(10, decimals)) / Math.pow(10, decimals);
|
|
52
|
+
}
|
|
53
|
+
exports.roundToDecimals = roundToDecimals;
|
|
54
|
+
function humanReadable(bn, mint) {
|
|
55
|
+
return numberWithCommas(roundToDecimals(toNumber(bn, mint), mint.decimals));
|
|
56
|
+
}
|
|
57
|
+
exports.humanReadable = humanReadable;
|
|
58
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAuB;AAKhB,MAAM,MAAM,GAAG,CAAI,KAAQ,EAAsB,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;AAAtD,QAAA,MAAM,UAAgD;AAEnE,SAAgB,QAAQ,CAAC,UAAuB,EAAE,cAA6B;IAC7E,IAAI,eAAE,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;QACvB,OAAO,WAAW,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;KAChD;SAAM;QACL,OAAO,UAAU,CAAC;KACnB;AACH,CAAC;AAND,4BAMC;AAED,SAAgB,WAAW,CAAC,MAAU,EAAE,cAA6B;IACnE,MAAM,QAAQ,GACZ,OAAO,cAAc,KAAK,QAAQ;QAChC,CAAC,CAAC,cAAc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