@0dotxyz/p0-ts-sdk 1.1.0-alpha.2 → 1.1.0-alpha.3
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/dist/vendor.cjs +12 -2537
- package/dist/vendor.cjs.map +1 -1
- package/dist/vendor.js +12 -2537
- package/dist/vendor.js.map +1 -1
- package/package.json +1 -1
package/dist/vendor.js
CHANGED
|
@@ -10,2504 +10,6 @@ import * as borsh from '@coral-xyz/borsh';
|
|
|
10
10
|
import { struct as struct$1, bool as bool$1, publicKey as publicKey$1, array, u64 as u64$1, u8 as u8$1, u32 as u32$1, u128 } from '@coral-xyz/borsh';
|
|
11
11
|
import Decimal3 from 'decimal.js';
|
|
12
12
|
|
|
13
|
-
var __create = Object.create;
|
|
14
|
-
var __defProp = Object.defineProperty;
|
|
15
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
16
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
17
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
18
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
19
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
20
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
21
|
-
}) : x)(function(x) {
|
|
22
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
23
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
24
|
-
});
|
|
25
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
26
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
27
|
-
};
|
|
28
|
-
var __copyProps = (to, from, except, desc) => {
|
|
29
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
-
for (let key of __getOwnPropNames(from))
|
|
31
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
-
}
|
|
34
|
-
return to;
|
|
35
|
-
};
|
|
36
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
38
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
39
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
40
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
41
|
-
__defProp(target, "default", { value: mod, enumerable: true }) ,
|
|
42
|
-
mod
|
|
43
|
-
));
|
|
44
|
-
|
|
45
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/nodeWallet.js
|
|
46
|
-
var require_nodeWallet = __commonJS({
|
|
47
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/nodeWallet.js"(exports$1) {
|
|
48
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
49
|
-
exports$1.NodeWallet = void 0;
|
|
50
|
-
var web3_js_1 = __require("@solana/web3.js");
|
|
51
|
-
var NodeWallet = class _NodeWallet {
|
|
52
|
-
/**
|
|
53
|
-
* @param payer Keypair of the associated payer
|
|
54
|
-
*/
|
|
55
|
-
constructor(payer) {
|
|
56
|
-
this.payer = payer;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Factory for the local wallet.
|
|
60
|
-
* Makes use of the `MARGINFI_WALLET` env var, with fallback to `$HOME/.config/solana/id.json`.
|
|
61
|
-
*/
|
|
62
|
-
static local() {
|
|
63
|
-
const process = __require("process");
|
|
64
|
-
const payer = web3_js_1.Keypair.fromSecretKey(Buffer.from(JSON.parse(__require("fs").readFileSync(process.env.MARGINFI_WALLET || __require("path").join(__require("os").homedir(), ".config/solana/id.json"), {
|
|
65
|
-
encoding: "utf-8"
|
|
66
|
-
}))));
|
|
67
|
-
return new _NodeWallet(payer);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Factory for the Anchor local wallet.
|
|
71
|
-
*/
|
|
72
|
-
static anchor() {
|
|
73
|
-
const process = __require("process");
|
|
74
|
-
if (!process.env.ANCHOR_WALLET || process.env.ANCHOR_WALLET === "") {
|
|
75
|
-
throw new Error("expected environment variable `ANCHOR_WALLET` is not set.");
|
|
76
|
-
}
|
|
77
|
-
const payer = web3_js_1.Keypair.fromSecretKey(Buffer.from(JSON.parse(__require("fs").readFileSync(process.env.ANCHOR_WALLET, {
|
|
78
|
-
encoding: "utf-8"
|
|
79
|
-
}))));
|
|
80
|
-
return new _NodeWallet(payer);
|
|
81
|
-
}
|
|
82
|
-
async signTransaction(tx) {
|
|
83
|
-
if ("version" in tx) {
|
|
84
|
-
tx.sign([this.payer]);
|
|
85
|
-
} else {
|
|
86
|
-
tx.partialSign(this.payer);
|
|
87
|
-
}
|
|
88
|
-
return tx;
|
|
89
|
-
}
|
|
90
|
-
async signAllTransactions(txs) {
|
|
91
|
-
return txs.map((tx) => {
|
|
92
|
-
if ("version" in tx) {
|
|
93
|
-
tx.sign([this.payer]);
|
|
94
|
-
return tx;
|
|
95
|
-
} else {
|
|
96
|
-
tx.partialSign(this.payer);
|
|
97
|
-
return tx;
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
get publicKey() {
|
|
102
|
-
return this.payer.publicKey;
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
exports$1.NodeWallet = NodeWallet;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/cache.js
|
|
110
|
-
var require_cache = __commonJS({
|
|
111
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/cache.js"(exports$1) {
|
|
112
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
113
|
-
exports$1.loadTokenMetadatas = loadTokenMetadatas;
|
|
114
|
-
exports$1.loadBankMetadatas = loadBankMetadatas;
|
|
115
|
-
exports$1.loadStakedBankMetadatas = loadStakedBankMetadatas;
|
|
116
|
-
var superstruct_1 = __require("superstruct");
|
|
117
|
-
var TokenMetadataRaw = (0, superstruct_1.object)({
|
|
118
|
-
address: (0, superstruct_1.string)(),
|
|
119
|
-
chainId: (0, superstruct_1.number)(),
|
|
120
|
-
decimals: (0, superstruct_1.number)(),
|
|
121
|
-
name: (0, superstruct_1.string)(),
|
|
122
|
-
symbol: (0, superstruct_1.string)(),
|
|
123
|
-
logoURI: (0, superstruct_1.string)(),
|
|
124
|
-
extensions: (0, superstruct_1.object)()
|
|
125
|
-
});
|
|
126
|
-
(0, superstruct_1.array)(TokenMetadataRaw);
|
|
127
|
-
function parseTokenMetadata(tokenMetadataRaw) {
|
|
128
|
-
return {
|
|
129
|
-
address: tokenMetadataRaw.address,
|
|
130
|
-
icon: tokenMetadataRaw.logoURI,
|
|
131
|
-
name: tokenMetadataRaw.name,
|
|
132
|
-
symbol: tokenMetadataRaw.symbol,
|
|
133
|
-
decimals: tokenMetadataRaw.decimals
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
function parseTokenMetadatas(tokenMetadataListRaw) {
|
|
137
|
-
return tokenMetadataListRaw.reduce((config, current, _) => ({
|
|
138
|
-
[current.symbol]: parseTokenMetadata(current),
|
|
139
|
-
...config
|
|
140
|
-
}), {});
|
|
141
|
-
}
|
|
142
|
-
async function loadTokenMetadatas(cacheUrl = "https://storage.googleapis.com/mrgn-public/mrgn-token-metadata-cache.json") {
|
|
143
|
-
const response = await fetch(cacheUrl, {
|
|
144
|
-
headers: {
|
|
145
|
-
Accept: "application/json"
|
|
146
|
-
},
|
|
147
|
-
method: "GET"
|
|
148
|
-
});
|
|
149
|
-
if (response.status === 200) {
|
|
150
|
-
const responseData = await response.json();
|
|
151
|
-
return parseTokenMetadatas(responseData);
|
|
152
|
-
} else {
|
|
153
|
-
throw new Error("Failed to fetch token metadata cache");
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
var BankMetadataRaw = (0, superstruct_1.object)({
|
|
157
|
-
groupAddress: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
158
|
-
// optional as only present on arena cache not mrgnlend
|
|
159
|
-
validatorVoteAccount: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
160
|
-
// optional as only present on staked asset banks
|
|
161
|
-
bankAddress: (0, superstruct_1.string)(),
|
|
162
|
-
tokenAddress: (0, superstruct_1.string)(),
|
|
163
|
-
tokenName: (0, superstruct_1.string)(),
|
|
164
|
-
tokenSymbol: (0, superstruct_1.string)()
|
|
165
|
-
});
|
|
166
|
-
var BankMetadataList = (0, superstruct_1.array)(BankMetadataRaw);
|
|
167
|
-
function parseBankMetadata(bankMetadataRaw) {
|
|
168
|
-
return {
|
|
169
|
-
tokenAddress: bankMetadataRaw.tokenAddress,
|
|
170
|
-
tokenName: bankMetadataRaw.tokenName,
|
|
171
|
-
tokenSymbol: bankMetadataRaw.tokenSymbol,
|
|
172
|
-
validatorVoteAccount: bankMetadataRaw.validatorVoteAccount ?? void 0
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function parseBankMetadatas(bankMetadataListRaw) {
|
|
176
|
-
return bankMetadataListRaw.reduce((config, current, _) => ({
|
|
177
|
-
[current.bankAddress]: parseBankMetadata(current),
|
|
178
|
-
...config
|
|
179
|
-
}), {});
|
|
180
|
-
}
|
|
181
|
-
async function loadStakedBankMetadatas(cacheUrl = "https://storage.googleapis.com/mrgn-public/mrgn-staked-bank-metadata-cache.json") {
|
|
182
|
-
return loadBankMetadatas(cacheUrl);
|
|
183
|
-
}
|
|
184
|
-
async function loadBankMetadatas(cacheUrl = "https://storage.googleapis.com/mrgn-public/mrgn-bank-metadata-cache.json") {
|
|
185
|
-
const response = await fetch(cacheUrl, {
|
|
186
|
-
headers: {
|
|
187
|
-
Accept: "application/json"
|
|
188
|
-
},
|
|
189
|
-
method: "GET"
|
|
190
|
-
});
|
|
191
|
-
if (response.status === 200) {
|
|
192
|
-
const responseData = await response.json();
|
|
193
|
-
(0, superstruct_1.assert)(responseData, BankMetadataList);
|
|
194
|
-
return parseBankMetadatas(responseData);
|
|
195
|
-
} else {
|
|
196
|
-
throw new Error("Failed to fetch bank metadata cache");
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/types.js
|
|
203
|
-
var require_types = __commonJS({
|
|
204
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/types.js"(exports$1) {
|
|
205
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/misc.js
|
|
210
|
-
var require_misc = __commonJS({
|
|
211
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/misc.js"(exports$1) {
|
|
212
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
213
|
-
exports$1.loadKeypair = loadKeypair;
|
|
214
|
-
exports$1.getValueInsensitive = getValueInsensitive;
|
|
215
|
-
exports$1.sleep = sleep;
|
|
216
|
-
exports$1.chunks = chunks;
|
|
217
|
-
exports$1.setTimeoutPromise = setTimeoutPromise;
|
|
218
|
-
exports$1.chunkedGetRawMultipleAccountInfos = chunkedGetRawMultipleAccountInfos;
|
|
219
|
-
exports$1.chunkedGetRawMultipleAccountInfoOrderedWithNulls = chunkedGetRawMultipleAccountInfoOrderedWithNulls;
|
|
220
|
-
exports$1.chunkedGetRawMultipleAccountInfoOrdered = chunkedGetRawMultipleAccountInfoOrdered;
|
|
221
|
-
var web3_js_1 = __require("@solana/web3.js");
|
|
222
|
-
function loadKeypair(keypairPath) {
|
|
223
|
-
const path = __require("path");
|
|
224
|
-
if (!keypairPath || keypairPath == "") {
|
|
225
|
-
throw new Error("Keypair is required!");
|
|
226
|
-
}
|
|
227
|
-
if (keypairPath[0] === "~") {
|
|
228
|
-
keypairPath = path.join(__require("os").homedir(), keypairPath.slice(1));
|
|
229
|
-
}
|
|
230
|
-
const keyPath = path.normalize(keypairPath);
|
|
231
|
-
return web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(__require("fs").readFileSync(keyPath).toString())));
|
|
232
|
-
}
|
|
233
|
-
function getValueInsensitive(map, key) {
|
|
234
|
-
const lowerCaseLabel = key.toLowerCase();
|
|
235
|
-
for (let key2 in map) {
|
|
236
|
-
if (key2.toLowerCase() === lowerCaseLabel) {
|
|
237
|
-
return map[key2];
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
throw new Error(`Token metadata not found for ${key}`);
|
|
241
|
-
}
|
|
242
|
-
function sleep(ms) {
|
|
243
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
244
|
-
}
|
|
245
|
-
function chunks(array3, size) {
|
|
246
|
-
return Array.apply(0, new Array(Math.ceil(array3.length / size))).map((_, index) => array3.slice(index * size, (index + 1) * size));
|
|
247
|
-
}
|
|
248
|
-
function setTimeoutPromise(duration, message) {
|
|
249
|
-
return new Promise((_, reject) => setTimeout(() => reject(new Error(message)), duration));
|
|
250
|
-
}
|
|
251
|
-
async function chunkedGetRawMultipleAccountInfos(connection, pks, batchChunkSize = 1e3, maxAccountsChunkSize = 100) {
|
|
252
|
-
const accountInfoMap = /* @__PURE__ */ new Map();
|
|
253
|
-
let contextSlot = 0;
|
|
254
|
-
const batches = chunkArray(pks, batchChunkSize);
|
|
255
|
-
for (let i = 0; i < batches.length; i++) {
|
|
256
|
-
const batch = batches[i];
|
|
257
|
-
const batchRequest = chunkArray(batch, maxAccountsChunkSize).map((pubkeys) => ({
|
|
258
|
-
methodName: "getMultipleAccounts",
|
|
259
|
-
args: connection._buildArgs([pubkeys], "confirmed", "base64")
|
|
260
|
-
}));
|
|
261
|
-
let accountInfos = [];
|
|
262
|
-
let retries = 0;
|
|
263
|
-
const maxRetries = 3;
|
|
264
|
-
while (retries < maxRetries && accountInfos.length === 0) {
|
|
265
|
-
try {
|
|
266
|
-
accountInfos = await connection._rpcBatchRequest(batchRequest).then((batchResults) => {
|
|
267
|
-
contextSlot = Math.max(...batchResults.map((res) => res.result.context.slot));
|
|
268
|
-
const accounts = batchResults.reduce((acc, res) => {
|
|
269
|
-
acc.push(...res.result.value);
|
|
270
|
-
return acc;
|
|
271
|
-
}, []);
|
|
272
|
-
return accounts;
|
|
273
|
-
});
|
|
274
|
-
} catch (error) {
|
|
275
|
-
retries++;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
if (accountInfos.length === 0) {
|
|
279
|
-
throw new Error(`Failed to fetch account infos after ${maxRetries} retries`);
|
|
280
|
-
}
|
|
281
|
-
accountInfos.forEach((item, index) => {
|
|
282
|
-
const publicKey6 = batch[index];
|
|
283
|
-
if (item) {
|
|
284
|
-
accountInfoMap.set(publicKey6, {
|
|
285
|
-
...item,
|
|
286
|
-
owner: new web3_js_1.PublicKey(item.owner),
|
|
287
|
-
data: Buffer.from(item.data[0], "base64")
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
return [contextSlot, accountInfoMap];
|
|
293
|
-
}
|
|
294
|
-
async function chunkedGetRawMultipleAccountInfoOrderedWithNulls(connection, pks, batchChunkSize = 1e3, maxAccountsChunkSize = 100) {
|
|
295
|
-
const allAccountInfos = [];
|
|
296
|
-
const batches = chunkArray(pks, batchChunkSize);
|
|
297
|
-
for (let i = 0; i < batches.length; i++) {
|
|
298
|
-
const batch = batches[i];
|
|
299
|
-
const batchRequest = chunkArray(batch, maxAccountsChunkSize).map((pubkeys) => ({
|
|
300
|
-
methodName: "getMultipleAccounts",
|
|
301
|
-
args: connection._buildArgs([pubkeys], "confirmed", "base64")
|
|
302
|
-
}));
|
|
303
|
-
let accountInfos = [];
|
|
304
|
-
let retries = 0;
|
|
305
|
-
const maxRetries = 3;
|
|
306
|
-
while (retries < maxRetries && accountInfos.length === 0) {
|
|
307
|
-
try {
|
|
308
|
-
accountInfos = await connection._rpcBatchRequest(batchRequest).then((batchResults) => {
|
|
309
|
-
const accounts = batchResults.reduce((acc, res) => {
|
|
310
|
-
acc.push(...res.result.value);
|
|
311
|
-
return acc;
|
|
312
|
-
}, []);
|
|
313
|
-
return accounts;
|
|
314
|
-
});
|
|
315
|
-
} catch (error) {
|
|
316
|
-
retries++;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
if (accountInfos.length === 0) {
|
|
320
|
-
throw new Error(`Failed to fetch account infos after ${maxRetries} retries`);
|
|
321
|
-
}
|
|
322
|
-
accountInfos.forEach((item) => {
|
|
323
|
-
if (item) {
|
|
324
|
-
allAccountInfos.push({
|
|
325
|
-
...item,
|
|
326
|
-
owner: new web3_js_1.PublicKey(item.owner),
|
|
327
|
-
data: Buffer.from(item.data[0], "base64")
|
|
328
|
-
});
|
|
329
|
-
} else {
|
|
330
|
-
allAccountInfos.push(null);
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
return allAccountInfos;
|
|
335
|
-
}
|
|
336
|
-
async function chunkedGetRawMultipleAccountInfoOrdered(connection, pks, batchChunkSize = 1e3, maxAccountsChunkSize = 100) {
|
|
337
|
-
const allAccountInfos = [];
|
|
338
|
-
const batches = chunkArray(pks, batchChunkSize);
|
|
339
|
-
for (let i = 0; i < batches.length; i++) {
|
|
340
|
-
const batch = batches[i];
|
|
341
|
-
const batchRequest = chunkArray(batch, maxAccountsChunkSize).map((pubkeys) => ({
|
|
342
|
-
methodName: "getMultipleAccounts",
|
|
343
|
-
args: connection._buildArgs([pubkeys], "confirmed", "base64")
|
|
344
|
-
}));
|
|
345
|
-
let accountInfos = [];
|
|
346
|
-
let retries = 0;
|
|
347
|
-
const maxRetries = 3;
|
|
348
|
-
while (retries < maxRetries && accountInfos.length === 0) {
|
|
349
|
-
try {
|
|
350
|
-
accountInfos = await connection._rpcBatchRequest(batchRequest).then((batchResults) => {
|
|
351
|
-
const accounts = batchResults.reduce((acc, res) => {
|
|
352
|
-
acc.push(...res.result.value);
|
|
353
|
-
return acc;
|
|
354
|
-
}, []);
|
|
355
|
-
return accounts;
|
|
356
|
-
});
|
|
357
|
-
} catch (error) {
|
|
358
|
-
retries++;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
if (accountInfos.length === 0) {
|
|
362
|
-
throw new Error(`Failed to fetch account infos after ${maxRetries} retries`);
|
|
363
|
-
}
|
|
364
|
-
accountInfos.forEach((item) => {
|
|
365
|
-
if (item) {
|
|
366
|
-
allAccountInfos.push({
|
|
367
|
-
...item,
|
|
368
|
-
owner: new web3_js_1.PublicKey(item.owner),
|
|
369
|
-
data: Buffer.from(item.data[0], "base64")
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
return allAccountInfos;
|
|
375
|
-
}
|
|
376
|
-
function chunkArray(array3, chunkSize) {
|
|
377
|
-
const chunks2 = [];
|
|
378
|
-
for (let i = 0; i < array3.length; i += chunkSize) {
|
|
379
|
-
chunks2.push(array3.slice(i, i + chunkSize));
|
|
380
|
-
}
|
|
381
|
-
return chunks2;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/math.js
|
|
387
|
-
var require_math = __commonJS({
|
|
388
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/math.js"(exports$1) {
|
|
389
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
390
|
-
exports$1.ceil = ceil;
|
|
391
|
-
exports$1.floor = floor;
|
|
392
|
-
exports$1.median = median;
|
|
393
|
-
function floor(value, decimals) {
|
|
394
|
-
return Math.floor(value * 10 ** decimals) / 10 ** decimals;
|
|
395
|
-
}
|
|
396
|
-
function ceil(value, decimals) {
|
|
397
|
-
return Math.ceil(value * 10 ** decimals) / 10 ** decimals;
|
|
398
|
-
}
|
|
399
|
-
function median(values) {
|
|
400
|
-
if (values.length === 0) {
|
|
401
|
-
throw new Error("Input array is empty");
|
|
402
|
-
}
|
|
403
|
-
values = [...values].sort((a, b) => a - b);
|
|
404
|
-
const half = Math.floor(values.length / 2);
|
|
405
|
-
return values.length % 2 ? values[half] : (values[half - 1] + values[half]) / 2;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
|
|
410
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/constants/misc.consts.js
|
|
411
|
-
var require_misc_consts = __commonJS({
|
|
412
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/constants/misc.consts.js"(exports$1) {
|
|
413
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
414
|
-
exports$1.MAX_U64 = exports$1.HOURS_PER_YEAR = void 0;
|
|
415
|
-
exports$1.HOURS_PER_YEAR = 365.25 * 24;
|
|
416
|
-
exports$1.MAX_U64 = BigInt("18446744073709551615").toString();
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/constants/program.consts.js
|
|
421
|
-
var require_program_consts = __commonJS({
|
|
422
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/constants/program.consts.js"(exports$1) {
|
|
423
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
424
|
-
exports$1.STAKE_CONFIG_ID = exports$1.SYSVAR_STAKE_HISTORY_ID = exports$1.SYSVAR_CLOCK_ID = exports$1.SYSVAR_RENT_ID = exports$1.SYSTEM_PROGRAM_ID = exports$1.MPL_METADATA_PROGRAM_ID = exports$1.STAKE_PROGRAM_ID = exports$1.SINGLE_POOL_PROGRAM_ID = exports$1.MARGINFI_PROGRAM = exports$1.JUPITER_V6_PROGRAM = exports$1.LUT_PROGRAM_AUTHORITY_INDEX = void 0;
|
|
425
|
-
var web3_js_1 = __require("@solana/web3.js");
|
|
426
|
-
exports$1.LUT_PROGRAM_AUTHORITY_INDEX = 5;
|
|
427
|
-
exports$1.JUPITER_V6_PROGRAM = new web3_js_1.PublicKey("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4");
|
|
428
|
-
exports$1.MARGINFI_PROGRAM = new web3_js_1.PublicKey("MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA");
|
|
429
|
-
exports$1.SINGLE_POOL_PROGRAM_ID = new web3_js_1.PublicKey("SVSPxpvHdN29nkVg9rPapPNDddN5DipNLRUFhyjFThE");
|
|
430
|
-
exports$1.STAKE_PROGRAM_ID = new web3_js_1.PublicKey("Stake11111111111111111111111111111111111111");
|
|
431
|
-
exports$1.MPL_METADATA_PROGRAM_ID = new web3_js_1.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
|
|
432
|
-
exports$1.SYSTEM_PROGRAM_ID = new web3_js_1.PublicKey("11111111111111111111111111111111");
|
|
433
|
-
exports$1.SYSVAR_RENT_ID = new web3_js_1.PublicKey("SysvarRent111111111111111111111111111111111");
|
|
434
|
-
exports$1.SYSVAR_CLOCK_ID = new web3_js_1.PublicKey("SysvarC1ock11111111111111111111111111111111");
|
|
435
|
-
exports$1.SYSVAR_STAKE_HISTORY_ID = new web3_js_1.PublicKey("SysvarStakeHistory1111111111111111111111111");
|
|
436
|
-
exports$1.STAKE_CONFIG_ID = new web3_js_1.PublicKey("StakeConfig11111111111111111111111111111111");
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/constants/token.consts.js
|
|
441
|
-
var require_token_consts = __commonJS({
|
|
442
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/constants/token.consts.js"(exports$1) {
|
|
443
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
444
|
-
exports$1.USDC_DECIMALS = exports$1.USDC_MINT = exports$1.LST_MINT = exports$1.WSOL_MINT = void 0;
|
|
445
|
-
var web3_js_1 = __require("@solana/web3.js");
|
|
446
|
-
exports$1.WSOL_MINT = new web3_js_1.PublicKey("So11111111111111111111111111111111111111112");
|
|
447
|
-
exports$1.LST_MINT = new web3_js_1.PublicKey("LSTxxxnJzKDFSLr4dUkPcmCf5VyryEqzPLz5j4bpxFp");
|
|
448
|
-
exports$1.USDC_MINT = new web3_js_1.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
|
|
449
|
-
exports$1.USDC_DECIMALS = 6;
|
|
450
|
-
}
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/constants/transaction.consts.js
|
|
454
|
-
var require_transaction_consts = __commonJS({
|
|
455
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/constants/transaction.consts.js"(exports$1) {
|
|
456
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
457
|
-
exports$1.SKIP_SIMULATION = exports$1.PRIORITY_TX_SIZE = exports$1.BUNDLE_TX_SIZE = exports$1.MAX_TX_SIZE = exports$1.DEFAULT_CONFIRM_OPTS = exports$1.DEFAULT_SEND_OPTS = exports$1.DEFAULT_COMMITMENT = void 0;
|
|
458
|
-
exports$1.DEFAULT_COMMITMENT = "processed";
|
|
459
|
-
exports$1.DEFAULT_SEND_OPTS = {
|
|
460
|
-
skipPreflight: false,
|
|
461
|
-
preflightCommitment: exports$1.DEFAULT_COMMITMENT
|
|
462
|
-
};
|
|
463
|
-
exports$1.DEFAULT_CONFIRM_OPTS = {
|
|
464
|
-
commitment: exports$1.DEFAULT_COMMITMENT,
|
|
465
|
-
...exports$1.DEFAULT_SEND_OPTS
|
|
466
|
-
};
|
|
467
|
-
exports$1.MAX_TX_SIZE = 1232;
|
|
468
|
-
exports$1.BUNDLE_TX_SIZE = 81;
|
|
469
|
-
exports$1.PRIORITY_TX_SIZE = 44;
|
|
470
|
-
exports$1.SKIP_SIMULATION = false;
|
|
471
|
-
}
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/constants/index.js
|
|
475
|
-
var require_constants = __commonJS({
|
|
476
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/constants/index.js"(exports$1) {
|
|
477
|
-
var __createBinding = exports$1 && exports$1.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
478
|
-
if (k2 === void 0) k2 = k;
|
|
479
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
480
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
481
|
-
desc = { enumerable: true, get: function() {
|
|
482
|
-
return m[k];
|
|
483
|
-
} };
|
|
484
|
-
}
|
|
485
|
-
Object.defineProperty(o, k2, desc);
|
|
486
|
-
}) : (function(o, m, k, k2) {
|
|
487
|
-
if (k2 === void 0) k2 = k;
|
|
488
|
-
o[k2] = m[k];
|
|
489
|
-
}));
|
|
490
|
-
var __exportStar = exports$1 && exports$1.__exportStar || function(m, exports2) {
|
|
491
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
|
|
492
|
-
};
|
|
493
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
494
|
-
__exportStar(require_misc_consts(), exports$1);
|
|
495
|
-
__exportStar(require_program_consts(), exports$1);
|
|
496
|
-
__exportStar(require_token_consts(), exports$1);
|
|
497
|
-
__exportStar(require_transaction_consts(), exports$1);
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/utils/accounting.utils.js
|
|
502
|
-
var require_accounting_utils = __commonJS({
|
|
503
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/utils/accounting.utils.js"(exports$1) {
|
|
504
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
505
|
-
exports$1.aprToApy = exports$1.apyToApr = void 0;
|
|
506
|
-
exports$1.calculateInterestFromApy = calculateInterestFromApy;
|
|
507
|
-
exports$1.calculateApyFromInterest = calculateApyFromInterest;
|
|
508
|
-
var constants_1 = require_constants();
|
|
509
|
-
var apyToApr = (apy, compoundingFrequency = constants_1.HOURS_PER_YEAR) => ((1 + apy) ** (1 / compoundingFrequency) - 1) * compoundingFrequency;
|
|
510
|
-
exports$1.apyToApr = apyToApr;
|
|
511
|
-
var aprToApy2 = (apr, compoundingFrequency = constants_1.HOURS_PER_YEAR, apyCap = 3) => Math.min((1 + apr / compoundingFrequency) ** compoundingFrequency - 1, apyCap);
|
|
512
|
-
exports$1.aprToApy = aprToApy2;
|
|
513
|
-
function calculateInterestFromApy(principal, durationInYears, apy) {
|
|
514
|
-
return principal * apy * durationInYears;
|
|
515
|
-
}
|
|
516
|
-
function calculateApyFromInterest(principal, durationInYears, interest) {
|
|
517
|
-
return interest / (principal * durationInYears);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
|
|
522
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/utils/conversion.utils.js
|
|
523
|
-
var require_conversion_utils = __commonJS({
|
|
524
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/utils/conversion.utils.js"(exports$1) {
|
|
525
|
-
var __importDefault = exports$1 && exports$1.__importDefault || function(mod) {
|
|
526
|
-
return mod && mod.__esModule ? mod : { "default": mod };
|
|
527
|
-
};
|
|
528
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
529
|
-
exports$1.composeRemainingAccounts = void 0;
|
|
530
|
-
exports$1.wrappedI80F48toBigNumber = wrappedI80F48toBigNumber;
|
|
531
|
-
exports$1.bigNumberToWrappedI80F48 = bigNumberToWrappedI80F48;
|
|
532
|
-
exports$1.toNumber = toNumber;
|
|
533
|
-
exports$1.toBigNumber = toBigNumber;
|
|
534
|
-
exports$1.uiToNative = uiToNative;
|
|
535
|
-
exports$1.uiToNativeBigNumber = uiToNativeBigNumber;
|
|
536
|
-
exports$1.nativeToUi = nativeToUi;
|
|
537
|
-
exports$1.shortenAddress = shortenAddress;
|
|
538
|
-
exports$1.bpsToPercentile = bpsToPercentile;
|
|
539
|
-
var anchor_1 = __require("@coral-xyz/anchor");
|
|
540
|
-
var bignumber_js_1 = __importDefault(__require("bignumber.js"));
|
|
541
|
-
var decimal_js_1 = __require("decimal.js");
|
|
542
|
-
var I80F48_FRACTIONAL_BYTES = 6;
|
|
543
|
-
var I80F48_TOTAL_BYTES = 16;
|
|
544
|
-
var I80F48_DIVISOR = new decimal_js_1.Decimal(2).pow(8 * I80F48_FRACTIONAL_BYTES);
|
|
545
|
-
function wrappedI80F48toBigNumber(wrapped) {
|
|
546
|
-
let bytesLE = wrapped.value;
|
|
547
|
-
if (bytesLE.length !== I80F48_TOTAL_BYTES) {
|
|
548
|
-
throw new Error(`Expected a ${I80F48_TOTAL_BYTES}-byte buffer`);
|
|
549
|
-
}
|
|
550
|
-
let bytesBE = bytesLE.slice();
|
|
551
|
-
bytesBE.reverse();
|
|
552
|
-
let signChar = "";
|
|
553
|
-
const msb = bytesBE[0];
|
|
554
|
-
if (msb & 128) {
|
|
555
|
-
signChar = "-";
|
|
556
|
-
bytesBE = bytesBE.map((v) => ~v & 255);
|
|
557
|
-
}
|
|
558
|
-
let hex = signChar + "0x" + bytesBE.map((v) => v.toString(16).padStart(2, "0")).join("");
|
|
559
|
-
let decoded = new decimal_js_1.Decimal(hex).dividedBy(I80F48_DIVISOR);
|
|
560
|
-
return new bignumber_js_1.default(decoded.toString());
|
|
561
|
-
}
|
|
562
|
-
function bigNumberToWrappedI80F48(value) {
|
|
563
|
-
let decimalValue = new decimal_js_1.Decimal(value.toString());
|
|
564
|
-
const isNegative = decimalValue.isNegative();
|
|
565
|
-
decimalValue = decimalValue.times(I80F48_DIVISOR);
|
|
566
|
-
let wrappedValue = new anchor_1.BN(decimalValue.round().toFixed()).toArray();
|
|
567
|
-
if (wrappedValue.length < I80F48_TOTAL_BYTES) {
|
|
568
|
-
const padding = Array(I80F48_TOTAL_BYTES - wrappedValue.length).fill(0);
|
|
569
|
-
wrappedValue.unshift(...padding);
|
|
570
|
-
}
|
|
571
|
-
if (isNegative) {
|
|
572
|
-
wrappedValue[wrappedValue.length - 1] |= 128;
|
|
573
|
-
wrappedValue = wrappedValue.map((v) => ~v & 255);
|
|
574
|
-
}
|
|
575
|
-
wrappedValue.reverse();
|
|
576
|
-
return { value: wrappedValue };
|
|
577
|
-
}
|
|
578
|
-
function toNumber(amount) {
|
|
579
|
-
let amt;
|
|
580
|
-
if (typeof amount === "number") {
|
|
581
|
-
amt = amount;
|
|
582
|
-
} else if (typeof amount === "string") {
|
|
583
|
-
amt = Number(amount);
|
|
584
|
-
} else {
|
|
585
|
-
amt = amount.toNumber();
|
|
586
|
-
}
|
|
587
|
-
return amt;
|
|
588
|
-
}
|
|
589
|
-
function toBigNumber(amount) {
|
|
590
|
-
let amt;
|
|
591
|
-
if (amount instanceof bignumber_js_1.default) {
|
|
592
|
-
amt = amount;
|
|
593
|
-
} else {
|
|
594
|
-
amt = new bignumber_js_1.default(amount.toString());
|
|
595
|
-
}
|
|
596
|
-
return amt;
|
|
597
|
-
}
|
|
598
|
-
function uiToNative(amount, decimals) {
|
|
599
|
-
let amt = toBigNumber(amount);
|
|
600
|
-
return new anchor_1.BN(amt.times(10 ** decimals).toFixed(0, bignumber_js_1.default.ROUND_FLOOR));
|
|
601
|
-
}
|
|
602
|
-
function uiToNativeBigNumber(amount, decimals) {
|
|
603
|
-
let amt = toBigNumber(amount);
|
|
604
|
-
return amt.times(10 ** decimals);
|
|
605
|
-
}
|
|
606
|
-
function nativeToUi(amount, decimals) {
|
|
607
|
-
let amt = toBigNumber(amount);
|
|
608
|
-
return amt.div(10 ** decimals).toNumber();
|
|
609
|
-
}
|
|
610
|
-
function shortenAddress(pubkey, chars = 4) {
|
|
611
|
-
const pubkeyStr = pubkey.toString();
|
|
612
|
-
return `${pubkeyStr.slice(0, chars)}...${pubkeyStr.slice(-chars)}`;
|
|
613
|
-
}
|
|
614
|
-
function bpsToPercentile(bps) {
|
|
615
|
-
return bps / 1e4;
|
|
616
|
-
}
|
|
617
|
-
var composeRemainingAccounts = (banksAndOracles) => {
|
|
618
|
-
banksAndOracles.sort((a, b) => {
|
|
619
|
-
const A = a[0].toBytes();
|
|
620
|
-
const B = b[0].toBytes();
|
|
621
|
-
for (let i = 0; i < 32; i++) {
|
|
622
|
-
if (A[i] !== B[i]) {
|
|
623
|
-
return B[i] - A[i];
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
return 0;
|
|
627
|
-
});
|
|
628
|
-
return banksAndOracles.flat();
|
|
629
|
-
};
|
|
630
|
-
exports$1.composeRemainingAccounts = composeRemainingAccounts;
|
|
631
|
-
}
|
|
632
|
-
});
|
|
633
|
-
|
|
634
|
-
// node_modules/.pnpm/numeral@2.0.6/node_modules/numeral/numeral.js
|
|
635
|
-
var require_numeral = __commonJS({
|
|
636
|
-
"node_modules/.pnpm/numeral@2.0.6/node_modules/numeral/numeral.js"(exports$1, module) {
|
|
637
|
-
(function(global, factory) {
|
|
638
|
-
if (typeof define === "function" && define.amd) {
|
|
639
|
-
define(factory);
|
|
640
|
-
} else if (typeof module === "object" && module.exports) {
|
|
641
|
-
module.exports = factory();
|
|
642
|
-
} else {
|
|
643
|
-
global.numeral = factory();
|
|
644
|
-
}
|
|
645
|
-
})(exports$1, function() {
|
|
646
|
-
var numeral, _, VERSION = "2.0.6", formats = {}, locales = {}, defaults = {
|
|
647
|
-
currentLocale: "en",
|
|
648
|
-
zeroFormat: null,
|
|
649
|
-
nullFormat: null,
|
|
650
|
-
defaultFormat: "0,0",
|
|
651
|
-
scalePercentBy100: true
|
|
652
|
-
}, options = {
|
|
653
|
-
currentLocale: defaults.currentLocale,
|
|
654
|
-
zeroFormat: defaults.zeroFormat,
|
|
655
|
-
nullFormat: defaults.nullFormat,
|
|
656
|
-
defaultFormat: defaults.defaultFormat,
|
|
657
|
-
scalePercentBy100: defaults.scalePercentBy100
|
|
658
|
-
};
|
|
659
|
-
function Numeral(input, number) {
|
|
660
|
-
this._input = input;
|
|
661
|
-
this._value = number;
|
|
662
|
-
}
|
|
663
|
-
numeral = function(input) {
|
|
664
|
-
var value, kind, unformatFunction, regexp;
|
|
665
|
-
if (numeral.isNumeral(input)) {
|
|
666
|
-
value = input.value();
|
|
667
|
-
} else if (input === 0 || typeof input === "undefined") {
|
|
668
|
-
value = 0;
|
|
669
|
-
} else if (input === null || _.isNaN(input)) {
|
|
670
|
-
value = null;
|
|
671
|
-
} else if (typeof input === "string") {
|
|
672
|
-
if (options.zeroFormat && input === options.zeroFormat) {
|
|
673
|
-
value = 0;
|
|
674
|
-
} else if (options.nullFormat && input === options.nullFormat || !input.replace(/[^0-9]+/g, "").length) {
|
|
675
|
-
value = null;
|
|
676
|
-
} else {
|
|
677
|
-
for (kind in formats) {
|
|
678
|
-
regexp = typeof formats[kind].regexps.unformat === "function" ? formats[kind].regexps.unformat() : formats[kind].regexps.unformat;
|
|
679
|
-
if (regexp && input.match(regexp)) {
|
|
680
|
-
unformatFunction = formats[kind].unformat;
|
|
681
|
-
break;
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
unformatFunction = unformatFunction || numeral._.stringToNumber;
|
|
685
|
-
value = unformatFunction(input);
|
|
686
|
-
}
|
|
687
|
-
} else {
|
|
688
|
-
value = Number(input) || null;
|
|
689
|
-
}
|
|
690
|
-
return new Numeral(input, value);
|
|
691
|
-
};
|
|
692
|
-
numeral.version = VERSION;
|
|
693
|
-
numeral.isNumeral = function(obj) {
|
|
694
|
-
return obj instanceof Numeral;
|
|
695
|
-
};
|
|
696
|
-
numeral._ = _ = {
|
|
697
|
-
// formats numbers separators, decimals places, signs, abbreviations
|
|
698
|
-
numberToFormat: function(value, format, roundingFunction) {
|
|
699
|
-
var locale = locales[numeral.options.currentLocale], negP = false, optDec = false, leadingCount = 0, abbr = "", trillion = 1e12, billion = 1e9, million = 1e6, thousand = 1e3, decimal = "", neg = false, abbrForce, abs, int, precision, signed, thousands, output;
|
|
700
|
-
value = value || 0;
|
|
701
|
-
abs = Math.abs(value);
|
|
702
|
-
if (numeral._.includes(format, "(")) {
|
|
703
|
-
negP = true;
|
|
704
|
-
format = format.replace(/[\(|\)]/g, "");
|
|
705
|
-
} else if (numeral._.includes(format, "+") || numeral._.includes(format, "-")) {
|
|
706
|
-
signed = numeral._.includes(format, "+") ? format.indexOf("+") : value < 0 ? format.indexOf("-") : -1;
|
|
707
|
-
format = format.replace(/[\+|\-]/g, "");
|
|
708
|
-
}
|
|
709
|
-
if (numeral._.includes(format, "a")) {
|
|
710
|
-
abbrForce = format.match(/a(k|m|b|t)?/);
|
|
711
|
-
abbrForce = abbrForce ? abbrForce[1] : false;
|
|
712
|
-
if (numeral._.includes(format, " a")) {
|
|
713
|
-
abbr = " ";
|
|
714
|
-
}
|
|
715
|
-
format = format.replace(new RegExp(abbr + "a[kmbt]?"), "");
|
|
716
|
-
if (abs >= trillion && !abbrForce || abbrForce === "t") {
|
|
717
|
-
abbr += locale.abbreviations.trillion;
|
|
718
|
-
value = value / trillion;
|
|
719
|
-
} else if (abs < trillion && abs >= billion && !abbrForce || abbrForce === "b") {
|
|
720
|
-
abbr += locale.abbreviations.billion;
|
|
721
|
-
value = value / billion;
|
|
722
|
-
} else if (abs < billion && abs >= million && !abbrForce || abbrForce === "m") {
|
|
723
|
-
abbr += locale.abbreviations.million;
|
|
724
|
-
value = value / million;
|
|
725
|
-
} else if (abs < million && abs >= thousand && !abbrForce || abbrForce === "k") {
|
|
726
|
-
abbr += locale.abbreviations.thousand;
|
|
727
|
-
value = value / thousand;
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
if (numeral._.includes(format, "[.]")) {
|
|
731
|
-
optDec = true;
|
|
732
|
-
format = format.replace("[.]", ".");
|
|
733
|
-
}
|
|
734
|
-
int = value.toString().split(".")[0];
|
|
735
|
-
precision = format.split(".")[1];
|
|
736
|
-
thousands = format.indexOf(",");
|
|
737
|
-
leadingCount = (format.split(".")[0].split(",")[0].match(/0/g) || []).length;
|
|
738
|
-
if (precision) {
|
|
739
|
-
if (numeral._.includes(precision, "[")) {
|
|
740
|
-
precision = precision.replace("]", "");
|
|
741
|
-
precision = precision.split("[");
|
|
742
|
-
decimal = numeral._.toFixed(value, precision[0].length + precision[1].length, roundingFunction, precision[1].length);
|
|
743
|
-
} else {
|
|
744
|
-
decimal = numeral._.toFixed(value, precision.length, roundingFunction);
|
|
745
|
-
}
|
|
746
|
-
int = decimal.split(".")[0];
|
|
747
|
-
if (numeral._.includes(decimal, ".")) {
|
|
748
|
-
decimal = locale.delimiters.decimal + decimal.split(".")[1];
|
|
749
|
-
} else {
|
|
750
|
-
decimal = "";
|
|
751
|
-
}
|
|
752
|
-
if (optDec && Number(decimal.slice(1)) === 0) {
|
|
753
|
-
decimal = "";
|
|
754
|
-
}
|
|
755
|
-
} else {
|
|
756
|
-
int = numeral._.toFixed(value, 0, roundingFunction);
|
|
757
|
-
}
|
|
758
|
-
if (abbr && !abbrForce && Number(int) >= 1e3 && abbr !== locale.abbreviations.trillion) {
|
|
759
|
-
int = String(Number(int) / 1e3);
|
|
760
|
-
switch (abbr) {
|
|
761
|
-
case locale.abbreviations.thousand:
|
|
762
|
-
abbr = locale.abbreviations.million;
|
|
763
|
-
break;
|
|
764
|
-
case locale.abbreviations.million:
|
|
765
|
-
abbr = locale.abbreviations.billion;
|
|
766
|
-
break;
|
|
767
|
-
case locale.abbreviations.billion:
|
|
768
|
-
abbr = locale.abbreviations.trillion;
|
|
769
|
-
break;
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
if (numeral._.includes(int, "-")) {
|
|
773
|
-
int = int.slice(1);
|
|
774
|
-
neg = true;
|
|
775
|
-
}
|
|
776
|
-
if (int.length < leadingCount) {
|
|
777
|
-
for (var i = leadingCount - int.length; i > 0; i--) {
|
|
778
|
-
int = "0" + int;
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
if (thousands > -1) {
|
|
782
|
-
int = int.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1" + locale.delimiters.thousands);
|
|
783
|
-
}
|
|
784
|
-
if (format.indexOf(".") === 0) {
|
|
785
|
-
int = "";
|
|
786
|
-
}
|
|
787
|
-
output = int + decimal + (abbr ? abbr : "");
|
|
788
|
-
if (negP) {
|
|
789
|
-
output = (negP && neg ? "(" : "") + output + (negP && neg ? ")" : "");
|
|
790
|
-
} else {
|
|
791
|
-
if (signed >= 0) {
|
|
792
|
-
output = signed === 0 ? (neg ? "-" : "+") + output : output + (neg ? "-" : "+");
|
|
793
|
-
} else if (neg) {
|
|
794
|
-
output = "-" + output;
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
return output;
|
|
798
|
-
},
|
|
799
|
-
// unformats numbers separators, decimals places, signs, abbreviations
|
|
800
|
-
stringToNumber: function(string) {
|
|
801
|
-
var locale = locales[options.currentLocale], stringOriginal = string, abbreviations = {
|
|
802
|
-
thousand: 3,
|
|
803
|
-
million: 6,
|
|
804
|
-
billion: 9,
|
|
805
|
-
trillion: 12
|
|
806
|
-
}, abbreviation, value, regexp;
|
|
807
|
-
if (options.zeroFormat && string === options.zeroFormat) {
|
|
808
|
-
value = 0;
|
|
809
|
-
} else if (options.nullFormat && string === options.nullFormat || !string.replace(/[^0-9]+/g, "").length) {
|
|
810
|
-
value = null;
|
|
811
|
-
} else {
|
|
812
|
-
value = 1;
|
|
813
|
-
if (locale.delimiters.decimal !== ".") {
|
|
814
|
-
string = string.replace(/\./g, "").replace(locale.delimiters.decimal, ".");
|
|
815
|
-
}
|
|
816
|
-
for (abbreviation in abbreviations) {
|
|
817
|
-
regexp = new RegExp("[^a-zA-Z]" + locale.abbreviations[abbreviation] + "(?:\\)|(\\" + locale.currency.symbol + ")?(?:\\))?)?$");
|
|
818
|
-
if (stringOriginal.match(regexp)) {
|
|
819
|
-
value *= Math.pow(10, abbreviations[abbreviation]);
|
|
820
|
-
break;
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
value *= (string.split("-").length + Math.min(string.split("(").length - 1, string.split(")").length - 1)) % 2 ? 1 : -1;
|
|
824
|
-
string = string.replace(/[^0-9\.]+/g, "");
|
|
825
|
-
value *= Number(string);
|
|
826
|
-
}
|
|
827
|
-
return value;
|
|
828
|
-
},
|
|
829
|
-
isNaN: function(value) {
|
|
830
|
-
return typeof value === "number" && isNaN(value);
|
|
831
|
-
},
|
|
832
|
-
includes: function(string, search) {
|
|
833
|
-
return string.indexOf(search) !== -1;
|
|
834
|
-
},
|
|
835
|
-
insert: function(string, subString, start) {
|
|
836
|
-
return string.slice(0, start) + subString + string.slice(start);
|
|
837
|
-
},
|
|
838
|
-
reduce: function(array3, callback) {
|
|
839
|
-
if (this === null) {
|
|
840
|
-
throw new TypeError("Array.prototype.reduce called on null or undefined");
|
|
841
|
-
}
|
|
842
|
-
if (typeof callback !== "function") {
|
|
843
|
-
throw new TypeError(callback + " is not a function");
|
|
844
|
-
}
|
|
845
|
-
var t = Object(array3), len = t.length >>> 0, k = 0, value;
|
|
846
|
-
if (arguments.length === 3) {
|
|
847
|
-
value = arguments[2];
|
|
848
|
-
} else {
|
|
849
|
-
while (k < len && !(k in t)) {
|
|
850
|
-
k++;
|
|
851
|
-
}
|
|
852
|
-
if (k >= len) {
|
|
853
|
-
throw new TypeError("Reduce of empty array with no initial value");
|
|
854
|
-
}
|
|
855
|
-
value = t[k++];
|
|
856
|
-
}
|
|
857
|
-
for (; k < len; k++) {
|
|
858
|
-
if (k in t) {
|
|
859
|
-
value = callback(value, t[k], k, t);
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
return value;
|
|
863
|
-
},
|
|
864
|
-
/**
|
|
865
|
-
* Computes the multiplier necessary to make x >= 1,
|
|
866
|
-
* effectively eliminating miscalculations caused by
|
|
867
|
-
* finite precision.
|
|
868
|
-
*/
|
|
869
|
-
multiplier: function(x) {
|
|
870
|
-
var parts = x.toString().split(".");
|
|
871
|
-
return parts.length < 2 ? 1 : Math.pow(10, parts[1].length);
|
|
872
|
-
},
|
|
873
|
-
/**
|
|
874
|
-
* Given a variable number of arguments, returns the maximum
|
|
875
|
-
* multiplier that must be used to normalize an operation involving
|
|
876
|
-
* all of them.
|
|
877
|
-
*/
|
|
878
|
-
correctionFactor: function() {
|
|
879
|
-
var args = Array.prototype.slice.call(arguments);
|
|
880
|
-
return args.reduce(function(accum, next) {
|
|
881
|
-
var mn = _.multiplier(next);
|
|
882
|
-
return accum > mn ? accum : mn;
|
|
883
|
-
}, 1);
|
|
884
|
-
},
|
|
885
|
-
/**
|
|
886
|
-
* Implementation of toFixed() that treats floats more like decimals
|
|
887
|
-
*
|
|
888
|
-
* Fixes binary rounding issues (eg. (0.615).toFixed(2) === '0.61') that present
|
|
889
|
-
* problems for accounting- and finance-related software.
|
|
890
|
-
*/
|
|
891
|
-
toFixed: function(value, maxDecimals, roundingFunction, optionals) {
|
|
892
|
-
var splitValue = value.toString().split("."), minDecimals = maxDecimals - (optionals || 0), boundedPrecision, optionalsRegExp, power, output;
|
|
893
|
-
if (splitValue.length === 2) {
|
|
894
|
-
boundedPrecision = Math.min(Math.max(splitValue[1].length, minDecimals), maxDecimals);
|
|
895
|
-
} else {
|
|
896
|
-
boundedPrecision = minDecimals;
|
|
897
|
-
}
|
|
898
|
-
power = Math.pow(10, boundedPrecision);
|
|
899
|
-
output = (roundingFunction(value + "e+" + boundedPrecision) / power).toFixed(boundedPrecision);
|
|
900
|
-
if (optionals > maxDecimals - boundedPrecision) {
|
|
901
|
-
optionalsRegExp = new RegExp("\\.?0{1," + (optionals - (maxDecimals - boundedPrecision)) + "}$");
|
|
902
|
-
output = output.replace(optionalsRegExp, "");
|
|
903
|
-
}
|
|
904
|
-
return output;
|
|
905
|
-
}
|
|
906
|
-
};
|
|
907
|
-
numeral.options = options;
|
|
908
|
-
numeral.formats = formats;
|
|
909
|
-
numeral.locales = locales;
|
|
910
|
-
numeral.locale = function(key) {
|
|
911
|
-
if (key) {
|
|
912
|
-
options.currentLocale = key.toLowerCase();
|
|
913
|
-
}
|
|
914
|
-
return options.currentLocale;
|
|
915
|
-
};
|
|
916
|
-
numeral.localeData = function(key) {
|
|
917
|
-
if (!key) {
|
|
918
|
-
return locales[options.currentLocale];
|
|
919
|
-
}
|
|
920
|
-
key = key.toLowerCase();
|
|
921
|
-
if (!locales[key]) {
|
|
922
|
-
throw new Error("Unknown locale : " + key);
|
|
923
|
-
}
|
|
924
|
-
return locales[key];
|
|
925
|
-
};
|
|
926
|
-
numeral.reset = function() {
|
|
927
|
-
for (var property in defaults) {
|
|
928
|
-
options[property] = defaults[property];
|
|
929
|
-
}
|
|
930
|
-
};
|
|
931
|
-
numeral.zeroFormat = function(format) {
|
|
932
|
-
options.zeroFormat = typeof format === "string" ? format : null;
|
|
933
|
-
};
|
|
934
|
-
numeral.nullFormat = function(format) {
|
|
935
|
-
options.nullFormat = typeof format === "string" ? format : null;
|
|
936
|
-
};
|
|
937
|
-
numeral.defaultFormat = function(format) {
|
|
938
|
-
options.defaultFormat = typeof format === "string" ? format : "0.0";
|
|
939
|
-
};
|
|
940
|
-
numeral.register = function(type, name, format) {
|
|
941
|
-
name = name.toLowerCase();
|
|
942
|
-
if (this[type + "s"][name]) {
|
|
943
|
-
throw new TypeError(name + " " + type + " already registered.");
|
|
944
|
-
}
|
|
945
|
-
this[type + "s"][name] = format;
|
|
946
|
-
return format;
|
|
947
|
-
};
|
|
948
|
-
numeral.validate = function(val, culture) {
|
|
949
|
-
var _decimalSep, _thousandSep, _currSymbol, _valArray, _abbrObj, _thousandRegEx, localeData, temp;
|
|
950
|
-
if (typeof val !== "string") {
|
|
951
|
-
val += "";
|
|
952
|
-
if (console.warn) {
|
|
953
|
-
console.warn("Numeral.js: Value is not string. It has been co-erced to: ", val);
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
val = val.trim();
|
|
957
|
-
if (!!val.match(/^\d+$/)) {
|
|
958
|
-
return true;
|
|
959
|
-
}
|
|
960
|
-
if (val === "") {
|
|
961
|
-
return false;
|
|
962
|
-
}
|
|
963
|
-
try {
|
|
964
|
-
localeData = numeral.localeData(culture);
|
|
965
|
-
} catch (e) {
|
|
966
|
-
localeData = numeral.localeData(numeral.locale());
|
|
967
|
-
}
|
|
968
|
-
_currSymbol = localeData.currency.symbol;
|
|
969
|
-
_abbrObj = localeData.abbreviations;
|
|
970
|
-
_decimalSep = localeData.delimiters.decimal;
|
|
971
|
-
if (localeData.delimiters.thousands === ".") {
|
|
972
|
-
_thousandSep = "\\.";
|
|
973
|
-
} else {
|
|
974
|
-
_thousandSep = localeData.delimiters.thousands;
|
|
975
|
-
}
|
|
976
|
-
temp = val.match(/^[^\d]+/);
|
|
977
|
-
if (temp !== null) {
|
|
978
|
-
val = val.substr(1);
|
|
979
|
-
if (temp[0] !== _currSymbol) {
|
|
980
|
-
return false;
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
temp = val.match(/[^\d]+$/);
|
|
984
|
-
if (temp !== null) {
|
|
985
|
-
val = val.slice(0, -1);
|
|
986
|
-
if (temp[0] !== _abbrObj.thousand && temp[0] !== _abbrObj.million && temp[0] !== _abbrObj.billion && temp[0] !== _abbrObj.trillion) {
|
|
987
|
-
return false;
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
_thousandRegEx = new RegExp(_thousandSep + "{2}");
|
|
991
|
-
if (!val.match(/[^\d.,]/g)) {
|
|
992
|
-
_valArray = val.split(_decimalSep);
|
|
993
|
-
if (_valArray.length > 2) {
|
|
994
|
-
return false;
|
|
995
|
-
} else {
|
|
996
|
-
if (_valArray.length < 2) {
|
|
997
|
-
return !!_valArray[0].match(/^\d+.*\d$/) && !_valArray[0].match(_thousandRegEx);
|
|
998
|
-
} else {
|
|
999
|
-
if (_valArray[0].length === 1) {
|
|
1000
|
-
return !!_valArray[0].match(/^\d+$/) && !_valArray[0].match(_thousandRegEx) && !!_valArray[1].match(/^\d+$/);
|
|
1001
|
-
} else {
|
|
1002
|
-
return !!_valArray[0].match(/^\d+.*\d$/) && !_valArray[0].match(_thousandRegEx) && !!_valArray[1].match(/^\d+$/);
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
return false;
|
|
1008
|
-
};
|
|
1009
|
-
numeral.fn = Numeral.prototype = {
|
|
1010
|
-
clone: function() {
|
|
1011
|
-
return numeral(this);
|
|
1012
|
-
},
|
|
1013
|
-
format: function(inputString, roundingFunction) {
|
|
1014
|
-
var value = this._value, format = inputString || options.defaultFormat, kind, output, formatFunction;
|
|
1015
|
-
roundingFunction = roundingFunction || Math.round;
|
|
1016
|
-
if (value === 0 && options.zeroFormat !== null) {
|
|
1017
|
-
output = options.zeroFormat;
|
|
1018
|
-
} else if (value === null && options.nullFormat !== null) {
|
|
1019
|
-
output = options.nullFormat;
|
|
1020
|
-
} else {
|
|
1021
|
-
for (kind in formats) {
|
|
1022
|
-
if (format.match(formats[kind].regexps.format)) {
|
|
1023
|
-
formatFunction = formats[kind].format;
|
|
1024
|
-
break;
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
formatFunction = formatFunction || numeral._.numberToFormat;
|
|
1028
|
-
output = formatFunction(value, format, roundingFunction);
|
|
1029
|
-
}
|
|
1030
|
-
return output;
|
|
1031
|
-
},
|
|
1032
|
-
value: function() {
|
|
1033
|
-
return this._value;
|
|
1034
|
-
},
|
|
1035
|
-
input: function() {
|
|
1036
|
-
return this._input;
|
|
1037
|
-
},
|
|
1038
|
-
set: function(value) {
|
|
1039
|
-
this._value = Number(value);
|
|
1040
|
-
return this;
|
|
1041
|
-
},
|
|
1042
|
-
add: function(value) {
|
|
1043
|
-
var corrFactor = _.correctionFactor.call(null, this._value, value);
|
|
1044
|
-
function cback(accum, curr, currI, O) {
|
|
1045
|
-
return accum + Math.round(corrFactor * curr);
|
|
1046
|
-
}
|
|
1047
|
-
this._value = _.reduce([this._value, value], cback, 0) / corrFactor;
|
|
1048
|
-
return this;
|
|
1049
|
-
},
|
|
1050
|
-
subtract: function(value) {
|
|
1051
|
-
var corrFactor = _.correctionFactor.call(null, this._value, value);
|
|
1052
|
-
function cback(accum, curr, currI, O) {
|
|
1053
|
-
return accum - Math.round(corrFactor * curr);
|
|
1054
|
-
}
|
|
1055
|
-
this._value = _.reduce([value], cback, Math.round(this._value * corrFactor)) / corrFactor;
|
|
1056
|
-
return this;
|
|
1057
|
-
},
|
|
1058
|
-
multiply: function(value) {
|
|
1059
|
-
function cback(accum, curr, currI, O) {
|
|
1060
|
-
var corrFactor = _.correctionFactor(accum, curr);
|
|
1061
|
-
return Math.round(accum * corrFactor) * Math.round(curr * corrFactor) / Math.round(corrFactor * corrFactor);
|
|
1062
|
-
}
|
|
1063
|
-
this._value = _.reduce([this._value, value], cback, 1);
|
|
1064
|
-
return this;
|
|
1065
|
-
},
|
|
1066
|
-
divide: function(value) {
|
|
1067
|
-
function cback(accum, curr, currI, O) {
|
|
1068
|
-
var corrFactor = _.correctionFactor(accum, curr);
|
|
1069
|
-
return Math.round(accum * corrFactor) / Math.round(curr * corrFactor);
|
|
1070
|
-
}
|
|
1071
|
-
this._value = _.reduce([this._value, value], cback);
|
|
1072
|
-
return this;
|
|
1073
|
-
},
|
|
1074
|
-
difference: function(value) {
|
|
1075
|
-
return Math.abs(numeral(this._value).subtract(value).value());
|
|
1076
|
-
}
|
|
1077
|
-
};
|
|
1078
|
-
numeral.register("locale", "en", {
|
|
1079
|
-
delimiters: {
|
|
1080
|
-
thousands: ",",
|
|
1081
|
-
decimal: "."
|
|
1082
|
-
},
|
|
1083
|
-
abbreviations: {
|
|
1084
|
-
thousand: "k",
|
|
1085
|
-
million: "m",
|
|
1086
|
-
billion: "b",
|
|
1087
|
-
trillion: "t"
|
|
1088
|
-
},
|
|
1089
|
-
ordinal: function(number) {
|
|
1090
|
-
var b = number % 10;
|
|
1091
|
-
return ~~(number % 100 / 10) === 1 ? "th" : b === 1 ? "st" : b === 2 ? "nd" : b === 3 ? "rd" : "th";
|
|
1092
|
-
},
|
|
1093
|
-
currency: {
|
|
1094
|
-
symbol: "$"
|
|
1095
|
-
}
|
|
1096
|
-
});
|
|
1097
|
-
(function() {
|
|
1098
|
-
numeral.register("format", "bps", {
|
|
1099
|
-
regexps: {
|
|
1100
|
-
format: /(BPS)/,
|
|
1101
|
-
unformat: /(BPS)/
|
|
1102
|
-
},
|
|
1103
|
-
format: function(value, format, roundingFunction) {
|
|
1104
|
-
var space = numeral._.includes(format, " BPS") ? " " : "", output;
|
|
1105
|
-
value = value * 1e4;
|
|
1106
|
-
format = format.replace(/\s?BPS/, "");
|
|
1107
|
-
output = numeral._.numberToFormat(value, format, roundingFunction);
|
|
1108
|
-
if (numeral._.includes(output, ")")) {
|
|
1109
|
-
output = output.split("");
|
|
1110
|
-
output.splice(-1, 0, space + "BPS");
|
|
1111
|
-
output = output.join("");
|
|
1112
|
-
} else {
|
|
1113
|
-
output = output + space + "BPS";
|
|
1114
|
-
}
|
|
1115
|
-
return output;
|
|
1116
|
-
},
|
|
1117
|
-
unformat: function(string) {
|
|
1118
|
-
return +(numeral._.stringToNumber(string) * 1e-4).toFixed(15);
|
|
1119
|
-
}
|
|
1120
|
-
});
|
|
1121
|
-
})();
|
|
1122
|
-
(function() {
|
|
1123
|
-
var decimal = {
|
|
1124
|
-
base: 1e3,
|
|
1125
|
-
suffixes: ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
|
|
1126
|
-
}, binary = {
|
|
1127
|
-
base: 1024,
|
|
1128
|
-
suffixes: ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]
|
|
1129
|
-
};
|
|
1130
|
-
var allSuffixes = decimal.suffixes.concat(binary.suffixes.filter(function(item) {
|
|
1131
|
-
return decimal.suffixes.indexOf(item) < 0;
|
|
1132
|
-
}));
|
|
1133
|
-
var unformatRegex = allSuffixes.join("|");
|
|
1134
|
-
unformatRegex = "(" + unformatRegex.replace("B", "B(?!PS)") + ")";
|
|
1135
|
-
numeral.register("format", "bytes", {
|
|
1136
|
-
regexps: {
|
|
1137
|
-
format: /([0\s]i?b)/,
|
|
1138
|
-
unformat: new RegExp(unformatRegex)
|
|
1139
|
-
},
|
|
1140
|
-
format: function(value, format, roundingFunction) {
|
|
1141
|
-
var output, bytes = numeral._.includes(format, "ib") ? binary : decimal, suffix = numeral._.includes(format, " b") || numeral._.includes(format, " ib") ? " " : "", power, min, max;
|
|
1142
|
-
format = format.replace(/\s?i?b/, "");
|
|
1143
|
-
for (power = 0; power <= bytes.suffixes.length; power++) {
|
|
1144
|
-
min = Math.pow(bytes.base, power);
|
|
1145
|
-
max = Math.pow(bytes.base, power + 1);
|
|
1146
|
-
if (value === null || value === 0 || value >= min && value < max) {
|
|
1147
|
-
suffix += bytes.suffixes[power];
|
|
1148
|
-
if (min > 0) {
|
|
1149
|
-
value = value / min;
|
|
1150
|
-
}
|
|
1151
|
-
break;
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
output = numeral._.numberToFormat(value, format, roundingFunction);
|
|
1155
|
-
return output + suffix;
|
|
1156
|
-
},
|
|
1157
|
-
unformat: function(string) {
|
|
1158
|
-
var value = numeral._.stringToNumber(string), power, bytesMultiplier;
|
|
1159
|
-
if (value) {
|
|
1160
|
-
for (power = decimal.suffixes.length - 1; power >= 0; power--) {
|
|
1161
|
-
if (numeral._.includes(string, decimal.suffixes[power])) {
|
|
1162
|
-
bytesMultiplier = Math.pow(decimal.base, power);
|
|
1163
|
-
break;
|
|
1164
|
-
}
|
|
1165
|
-
if (numeral._.includes(string, binary.suffixes[power])) {
|
|
1166
|
-
bytesMultiplier = Math.pow(binary.base, power);
|
|
1167
|
-
break;
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
value *= bytesMultiplier || 1;
|
|
1171
|
-
}
|
|
1172
|
-
return value;
|
|
1173
|
-
}
|
|
1174
|
-
});
|
|
1175
|
-
})();
|
|
1176
|
-
(function() {
|
|
1177
|
-
numeral.register("format", "currency", {
|
|
1178
|
-
regexps: {
|
|
1179
|
-
format: /(\$)/
|
|
1180
|
-
},
|
|
1181
|
-
format: function(value, format, roundingFunction) {
|
|
1182
|
-
var locale = numeral.locales[numeral.options.currentLocale], symbols = {
|
|
1183
|
-
before: format.match(/^([\+|\-|\(|\s|\$]*)/)[0],
|
|
1184
|
-
after: format.match(/([\+|\-|\)|\s|\$]*)$/)[0]
|
|
1185
|
-
}, output, symbol, i;
|
|
1186
|
-
format = format.replace(/\s?\$\s?/, "");
|
|
1187
|
-
output = numeral._.numberToFormat(value, format, roundingFunction);
|
|
1188
|
-
if (value >= 0) {
|
|
1189
|
-
symbols.before = symbols.before.replace(/[\-\(]/, "");
|
|
1190
|
-
symbols.after = symbols.after.replace(/[\-\)]/, "");
|
|
1191
|
-
} else if (value < 0 && (!numeral._.includes(symbols.before, "-") && !numeral._.includes(symbols.before, "("))) {
|
|
1192
|
-
symbols.before = "-" + symbols.before;
|
|
1193
|
-
}
|
|
1194
|
-
for (i = 0; i < symbols.before.length; i++) {
|
|
1195
|
-
symbol = symbols.before[i];
|
|
1196
|
-
switch (symbol) {
|
|
1197
|
-
case "$":
|
|
1198
|
-
output = numeral._.insert(output, locale.currency.symbol, i);
|
|
1199
|
-
break;
|
|
1200
|
-
case " ":
|
|
1201
|
-
output = numeral._.insert(output, " ", i + locale.currency.symbol.length - 1);
|
|
1202
|
-
break;
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
for (i = symbols.after.length - 1; i >= 0; i--) {
|
|
1206
|
-
symbol = symbols.after[i];
|
|
1207
|
-
switch (symbol) {
|
|
1208
|
-
case "$":
|
|
1209
|
-
output = i === symbols.after.length - 1 ? output + locale.currency.symbol : numeral._.insert(output, locale.currency.symbol, -(symbols.after.length - (1 + i)));
|
|
1210
|
-
break;
|
|
1211
|
-
case " ":
|
|
1212
|
-
output = i === symbols.after.length - 1 ? output + " " : numeral._.insert(output, " ", -(symbols.after.length - (1 + i) + locale.currency.symbol.length - 1));
|
|
1213
|
-
break;
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
return output;
|
|
1217
|
-
}
|
|
1218
|
-
});
|
|
1219
|
-
})();
|
|
1220
|
-
(function() {
|
|
1221
|
-
numeral.register("format", "exponential", {
|
|
1222
|
-
regexps: {
|
|
1223
|
-
format: /(e\+|e-)/,
|
|
1224
|
-
unformat: /(e\+|e-)/
|
|
1225
|
-
},
|
|
1226
|
-
format: function(value, format, roundingFunction) {
|
|
1227
|
-
var output, exponential = typeof value === "number" && !numeral._.isNaN(value) ? value.toExponential() : "0e+0", parts = exponential.split("e");
|
|
1228
|
-
format = format.replace(/e[\+|\-]{1}0/, "");
|
|
1229
|
-
output = numeral._.numberToFormat(Number(parts[0]), format, roundingFunction);
|
|
1230
|
-
return output + "e" + parts[1];
|
|
1231
|
-
},
|
|
1232
|
-
unformat: function(string) {
|
|
1233
|
-
var parts = numeral._.includes(string, "e+") ? string.split("e+") : string.split("e-"), value = Number(parts[0]), power = Number(parts[1]);
|
|
1234
|
-
power = numeral._.includes(string, "e-") ? power *= -1 : power;
|
|
1235
|
-
function cback(accum, curr, currI, O) {
|
|
1236
|
-
var corrFactor = numeral._.correctionFactor(accum, curr), num = accum * corrFactor * (curr * corrFactor) / (corrFactor * corrFactor);
|
|
1237
|
-
return num;
|
|
1238
|
-
}
|
|
1239
|
-
return numeral._.reduce([value, Math.pow(10, power)], cback, 1);
|
|
1240
|
-
}
|
|
1241
|
-
});
|
|
1242
|
-
})();
|
|
1243
|
-
(function() {
|
|
1244
|
-
numeral.register("format", "ordinal", {
|
|
1245
|
-
regexps: {
|
|
1246
|
-
format: /(o)/
|
|
1247
|
-
},
|
|
1248
|
-
format: function(value, format, roundingFunction) {
|
|
1249
|
-
var locale = numeral.locales[numeral.options.currentLocale], output, ordinal = numeral._.includes(format, " o") ? " " : "";
|
|
1250
|
-
format = format.replace(/\s?o/, "");
|
|
1251
|
-
ordinal += locale.ordinal(value);
|
|
1252
|
-
output = numeral._.numberToFormat(value, format, roundingFunction);
|
|
1253
|
-
return output + ordinal;
|
|
1254
|
-
}
|
|
1255
|
-
});
|
|
1256
|
-
})();
|
|
1257
|
-
(function() {
|
|
1258
|
-
numeral.register("format", "percentage", {
|
|
1259
|
-
regexps: {
|
|
1260
|
-
format: /(%)/,
|
|
1261
|
-
unformat: /(%)/
|
|
1262
|
-
},
|
|
1263
|
-
format: function(value, format, roundingFunction) {
|
|
1264
|
-
var space = numeral._.includes(format, " %") ? " " : "", output;
|
|
1265
|
-
if (numeral.options.scalePercentBy100) {
|
|
1266
|
-
value = value * 100;
|
|
1267
|
-
}
|
|
1268
|
-
format = format.replace(/\s?\%/, "");
|
|
1269
|
-
output = numeral._.numberToFormat(value, format, roundingFunction);
|
|
1270
|
-
if (numeral._.includes(output, ")")) {
|
|
1271
|
-
output = output.split("");
|
|
1272
|
-
output.splice(-1, 0, space + "%");
|
|
1273
|
-
output = output.join("");
|
|
1274
|
-
} else {
|
|
1275
|
-
output = output + space + "%";
|
|
1276
|
-
}
|
|
1277
|
-
return output;
|
|
1278
|
-
},
|
|
1279
|
-
unformat: function(string) {
|
|
1280
|
-
var number = numeral._.stringToNumber(string);
|
|
1281
|
-
if (numeral.options.scalePercentBy100) {
|
|
1282
|
-
return number * 0.01;
|
|
1283
|
-
}
|
|
1284
|
-
return number;
|
|
1285
|
-
}
|
|
1286
|
-
});
|
|
1287
|
-
})();
|
|
1288
|
-
(function() {
|
|
1289
|
-
numeral.register("format", "time", {
|
|
1290
|
-
regexps: {
|
|
1291
|
-
format: /(:)/,
|
|
1292
|
-
unformat: /(:)/
|
|
1293
|
-
},
|
|
1294
|
-
format: function(value, format, roundingFunction) {
|
|
1295
|
-
var hours = Math.floor(value / 60 / 60), minutes = Math.floor((value - hours * 60 * 60) / 60), seconds = Math.round(value - hours * 60 * 60 - minutes * 60);
|
|
1296
|
-
return hours + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);
|
|
1297
|
-
},
|
|
1298
|
-
unformat: function(string) {
|
|
1299
|
-
var timeArray = string.split(":"), seconds = 0;
|
|
1300
|
-
if (timeArray.length === 3) {
|
|
1301
|
-
seconds = seconds + Number(timeArray[0]) * 60 * 60;
|
|
1302
|
-
seconds = seconds + Number(timeArray[1]) * 60;
|
|
1303
|
-
seconds = seconds + Number(timeArray[2]);
|
|
1304
|
-
} else if (timeArray.length === 2) {
|
|
1305
|
-
seconds = seconds + Number(timeArray[0]) * 60;
|
|
1306
|
-
seconds = seconds + Number(timeArray[1]);
|
|
1307
|
-
}
|
|
1308
|
-
return Number(seconds);
|
|
1309
|
-
}
|
|
1310
|
-
});
|
|
1311
|
-
})();
|
|
1312
|
-
return numeral;
|
|
1313
|
-
});
|
|
1314
|
-
}
|
|
1315
|
-
});
|
|
1316
|
-
|
|
1317
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/utils/formatters.utils.js
|
|
1318
|
-
var require_formatters_utils = __commonJS({
|
|
1319
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/utils/formatters.utils.js"(exports$1) {
|
|
1320
|
-
var __importDefault = exports$1 && exports$1.__importDefault || function(mod) {
|
|
1321
|
-
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1322
|
-
};
|
|
1323
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
1324
|
-
exports$1.tokenPriceFormatter = exports$1.usdFormatterDyn = exports$1.usdFormatter = exports$1.percentFormatterMod = exports$1.percentFormatterDyn = exports$1.percentFormatter = exports$1.clampedNumeralFormatter = exports$1.numeralFormatter = exports$1.groupedNumberFormatterDyn = exports$1.groupedNumberFormatter = exports$1.CustomNumberFormat = exports$1.dynamicNumeralFormatter = void 0;
|
|
1325
|
-
var numeral_1 = __importDefault(require_numeral());
|
|
1326
|
-
var CustomNumberFormat = class extends Intl.NumberFormat {
|
|
1327
|
-
constructor(locale, options) {
|
|
1328
|
-
super(locale, options);
|
|
1329
|
-
}
|
|
1330
|
-
format(value) {
|
|
1331
|
-
if (value === 0) {
|
|
1332
|
-
return "-";
|
|
1333
|
-
} else {
|
|
1334
|
-
return super.format(value);
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
};
|
|
1338
|
-
exports$1.CustomNumberFormat = CustomNumberFormat;
|
|
1339
|
-
var groupedNumberFormatter = new CustomNumberFormat("en-US", {
|
|
1340
|
-
useGrouping: true,
|
|
1341
|
-
minimumFractionDigits: 0,
|
|
1342
|
-
maximumFractionDigits: 2
|
|
1343
|
-
});
|
|
1344
|
-
exports$1.groupedNumberFormatter = groupedNumberFormatter;
|
|
1345
|
-
var numeralFormatter = (value) => {
|
|
1346
|
-
if (value < 0.01) {
|
|
1347
|
-
return "0";
|
|
1348
|
-
} else {
|
|
1349
|
-
return (0, numeral_1.default)(value).format("0.00a");
|
|
1350
|
-
}
|
|
1351
|
-
};
|
|
1352
|
-
exports$1.numeralFormatter = numeralFormatter;
|
|
1353
|
-
var dynamicNumeralFormatter = (value, options = {}) => {
|
|
1354
|
-
const {
|
|
1355
|
-
minDisplay = 1e-5,
|
|
1356
|
-
// Default minDisplay for backward compatibility
|
|
1357
|
-
maxDisplay = 1e4,
|
|
1358
|
-
// Default maxDisplay for backward compatibility
|
|
1359
|
-
tokenPrice,
|
|
1360
|
-
logging = false,
|
|
1361
|
-
ignoreMinDisplay = false,
|
|
1362
|
-
// New flag to control ignoring minDisplay
|
|
1363
|
-
forceDecimals
|
|
1364
|
-
} = options;
|
|
1365
|
-
if (value === 0 || isNaN(value))
|
|
1366
|
-
return "0";
|
|
1367
|
-
const absValue = Math.abs(value);
|
|
1368
|
-
if (logging) {
|
|
1369
|
-
console.log({
|
|
1370
|
-
value,
|
|
1371
|
-
minDisplay,
|
|
1372
|
-
maxDisplay,
|
|
1373
|
-
tokenPrice,
|
|
1374
|
-
ignoreMinDisplay,
|
|
1375
|
-
absValue
|
|
1376
|
-
});
|
|
1377
|
-
}
|
|
1378
|
-
if (!ignoreMinDisplay && absValue < minDisplay) {
|
|
1379
|
-
return `<${minDisplay}`;
|
|
1380
|
-
}
|
|
1381
|
-
if (absValue > maxDisplay) {
|
|
1382
|
-
return (0, numeral_1.default)(value).format(forceDecimals ? "0,0.00a" : "0,0.[00]a");
|
|
1383
|
-
}
|
|
1384
|
-
if (!ignoreMinDisplay && Math.abs(value) >= 0.01) {
|
|
1385
|
-
return (0, numeral_1.default)(value).format(forceDecimals && Math.abs(value) > 0.99 ? "0,0.00a" : "0,0.[0000]a");
|
|
1386
|
-
}
|
|
1387
|
-
if (ignoreMinDisplay) {
|
|
1388
|
-
const decimalPart = absValue - Math.floor(absValue);
|
|
1389
|
-
const decimalPlaces = decimalPart > 0 ? 3 : 0;
|
|
1390
|
-
if (absValue >= 1) {
|
|
1391
|
-
return value.toFixed(decimalPlaces).replace(/\.?0+$/, "");
|
|
1392
|
-
} else {
|
|
1393
|
-
const exponent = Math.floor(Math.log10(absValue));
|
|
1394
|
-
const significantDecimals = Math.max(3, 2 - exponent);
|
|
1395
|
-
return value.toFixed(significantDecimals).replace(/\.?0+$/, "");
|
|
1396
|
-
}
|
|
1397
|
-
}
|
|
1398
|
-
if (Math.abs(value) >= minDisplay) {
|
|
1399
|
-
const decimalPlaces = Math.max(0, Math.ceil(-Math.log10(minDisplay)));
|
|
1400
|
-
return (0, numeral_1.default)(value).format(`0,0.[${"0".repeat(decimalPlaces)}]`);
|
|
1401
|
-
}
|
|
1402
|
-
if (tokenPrice) {
|
|
1403
|
-
const smallestUnit = minDisplay / tokenPrice;
|
|
1404
|
-
const significantDecimals = Math.max(3, Math.ceil(-Math.log10(smallestUnit)));
|
|
1405
|
-
return value.toFixed(significantDecimals).replace(/\.?0+$/, "");
|
|
1406
|
-
}
|
|
1407
|
-
return "0";
|
|
1408
|
-
};
|
|
1409
|
-
exports$1.dynamicNumeralFormatter = dynamicNumeralFormatter;
|
|
1410
|
-
var groupedNumberFormatterDyn = new Intl.NumberFormat("en-US", {
|
|
1411
|
-
useGrouping: true,
|
|
1412
|
-
minimumFractionDigits: 0,
|
|
1413
|
-
maximumFractionDigits: 2
|
|
1414
|
-
});
|
|
1415
|
-
exports$1.groupedNumberFormatterDyn = groupedNumberFormatterDyn;
|
|
1416
|
-
var usdFormatter = new Intl.NumberFormat("en-US", {
|
|
1417
|
-
style: "currency",
|
|
1418
|
-
currency: "USD",
|
|
1419
|
-
minimumFractionDigits: 2,
|
|
1420
|
-
maximumFractionDigits: 2,
|
|
1421
|
-
signDisplay: "auto"
|
|
1422
|
-
});
|
|
1423
|
-
exports$1.usdFormatter = usdFormatter;
|
|
1424
|
-
var usdFormatterDyn = new Intl.NumberFormat("en-US", {
|
|
1425
|
-
style: "currency",
|
|
1426
|
-
currency: "USD",
|
|
1427
|
-
minimumFractionDigits: 0,
|
|
1428
|
-
maximumFractionDigits: 2,
|
|
1429
|
-
signDisplay: "auto"
|
|
1430
|
-
});
|
|
1431
|
-
exports$1.usdFormatterDyn = usdFormatterDyn;
|
|
1432
|
-
var percentFormatter = new Intl.NumberFormat("en-US", {
|
|
1433
|
-
style: "percent",
|
|
1434
|
-
minimumFractionDigits: 2,
|
|
1435
|
-
maximumFractionDigits: 2
|
|
1436
|
-
});
|
|
1437
|
-
exports$1.percentFormatter = percentFormatter;
|
|
1438
|
-
var percentFormatterDyn = new Intl.NumberFormat("en-US", {
|
|
1439
|
-
style: "percent",
|
|
1440
|
-
minimumFractionDigits: 0,
|
|
1441
|
-
maximumFractionDigits: 2
|
|
1442
|
-
});
|
|
1443
|
-
exports$1.percentFormatterDyn = percentFormatterDyn;
|
|
1444
|
-
var percentFormatterMod = (value, opts = { minFractionDigits: 2, maxFractionDigits: 2 }) => {
|
|
1445
|
-
const percentFormatter2 = new Intl.NumberFormat("en-US", {
|
|
1446
|
-
style: "percent",
|
|
1447
|
-
minimumFractionDigits: opts.minFractionDigits,
|
|
1448
|
-
maximumFractionDigits: opts.maxFractionDigits
|
|
1449
|
-
});
|
|
1450
|
-
if (value === 0) {
|
|
1451
|
-
return "0%";
|
|
1452
|
-
} else {
|
|
1453
|
-
return percentFormatter2.format(value);
|
|
1454
|
-
}
|
|
1455
|
-
};
|
|
1456
|
-
exports$1.percentFormatterMod = percentFormatterMod;
|
|
1457
|
-
var clampedNumeralFormatter = (value) => {
|
|
1458
|
-
if (value === 0) {
|
|
1459
|
-
return "0";
|
|
1460
|
-
} else if (value < 0.01) {
|
|
1461
|
-
return "< 0.01";
|
|
1462
|
-
} else {
|
|
1463
|
-
return (0, numeral_1.default)(value).format("0.00a");
|
|
1464
|
-
}
|
|
1465
|
-
};
|
|
1466
|
-
exports$1.clampedNumeralFormatter = clampedNumeralFormatter;
|
|
1467
|
-
var tokenPriceFormatter = (price, style = "currency") => {
|
|
1468
|
-
if (price === 0) {
|
|
1469
|
-
return 0;
|
|
1470
|
-
}
|
|
1471
|
-
const reformatNum = Number(price.toFixed(20));
|
|
1472
|
-
if (price === 0) {
|
|
1473
|
-
return 0;
|
|
1474
|
-
}
|
|
1475
|
-
if (reformatNum < 1e-8) {
|
|
1476
|
-
return price.toExponential(2);
|
|
1477
|
-
}
|
|
1478
|
-
const { minFractionDigits, maxFractionDigits } = reformatNum > 1 ? { minFractionDigits: 2, maxFractionDigits: 2 } : reformatNum > 1e-6 ? { minFractionDigits: 2, maxFractionDigits: 7 } : { minFractionDigits: 7, maxFractionDigits: 10 };
|
|
1479
|
-
const formatter = new Intl.NumberFormat("en-US", {
|
|
1480
|
-
style,
|
|
1481
|
-
currency: "USD",
|
|
1482
|
-
minimumFractionDigits: minFractionDigits,
|
|
1483
|
-
maximumFractionDigits: maxFractionDigits,
|
|
1484
|
-
signDisplay: "auto"
|
|
1485
|
-
});
|
|
1486
|
-
return formatter.format(price);
|
|
1487
|
-
};
|
|
1488
|
-
exports$1.tokenPriceFormatter = tokenPriceFormatter;
|
|
1489
|
-
}
|
|
1490
|
-
});
|
|
1491
|
-
|
|
1492
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/utils/index.js
|
|
1493
|
-
var require_utils = __commonJS({
|
|
1494
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/utils/index.js"(exports$1) {
|
|
1495
|
-
var __createBinding = exports$1 && exports$1.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
1496
|
-
if (k2 === void 0) k2 = k;
|
|
1497
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1498
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1499
|
-
desc = { enumerable: true, get: function() {
|
|
1500
|
-
return m[k];
|
|
1501
|
-
} };
|
|
1502
|
-
}
|
|
1503
|
-
Object.defineProperty(o, k2, desc);
|
|
1504
|
-
}) : (function(o, m, k, k2) {
|
|
1505
|
-
if (k2 === void 0) k2 = k;
|
|
1506
|
-
o[k2] = m[k];
|
|
1507
|
-
}));
|
|
1508
|
-
var __exportStar = exports$1 && exports$1.__exportStar || function(m, exports2) {
|
|
1509
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
|
|
1510
|
-
};
|
|
1511
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
1512
|
-
__exportStar(require_accounting_utils(), exports$1);
|
|
1513
|
-
__exportStar(require_conversion_utils(), exports$1);
|
|
1514
|
-
__exportStar(require_formatters_utils(), exports$1);
|
|
1515
|
-
}
|
|
1516
|
-
});
|
|
1517
|
-
|
|
1518
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/modules/transactions/transaction.utils.js
|
|
1519
|
-
var require_transaction_utils = __commonJS({
|
|
1520
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/modules/transactions/transaction.utils.js"(exports$1) {
|
|
1521
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
1522
|
-
exports$1.microLamportsToUi = exports$1.uiToMicroLamports = void 0;
|
|
1523
|
-
exports$1.isV0Tx = isV0Tx;
|
|
1524
|
-
exports$1.getTxSize = getTxSize;
|
|
1525
|
-
exports$1.getAccountKeys = getAccountKeys;
|
|
1526
|
-
exports$1.decodeInstruction = decodeInstruction;
|
|
1527
|
-
exports$1.decompileV0Transaction = decompileV0Transaction;
|
|
1528
|
-
exports$1.legacyTxToV0Tx = legacyTxToV0Tx;
|
|
1529
|
-
exports$1.updateV0Tx = updateV0Tx;
|
|
1530
|
-
exports$1.compareInstructions = compareInstructions;
|
|
1531
|
-
exports$1.replaceV0TxInstructions = replaceV0TxInstructions;
|
|
1532
|
-
exports$1.replaceV0TxBlockhash = replaceV0TxBlockhash;
|
|
1533
|
-
exports$1.addTransactionMetadata = addTransactionMetadata;
|
|
1534
|
-
exports$1.decodeComputeBudgetInstruction = decodeComputeBudgetInstruction;
|
|
1535
|
-
exports$1.getComputeBudgetUnits = getComputeBudgetUnits;
|
|
1536
|
-
exports$1.splitInstructionsToFitTransactions = splitInstructionsToFitTransactions;
|
|
1537
|
-
var anchor_1 = __require("@coral-xyz/anchor");
|
|
1538
|
-
var web3_js_1 = __require("@solana/web3.js");
|
|
1539
|
-
var constants_1 = require_constants();
|
|
1540
|
-
function isV0Tx(tx) {
|
|
1541
|
-
return "message" in tx;
|
|
1542
|
-
}
|
|
1543
|
-
function getTxSize(tx) {
|
|
1544
|
-
const isVersioned = isV0Tx(tx);
|
|
1545
|
-
const numSigners = tx.signatures.length;
|
|
1546
|
-
const numRequiredSignatures = isVersioned ? tx.message.header.numRequiredSignatures : 0;
|
|
1547
|
-
const feePayerSize = isVersioned || tx.feePayer ? 0 : 32;
|
|
1548
|
-
const signaturesSize = (numRequiredSignatures - numSigners) * 64 + 1;
|
|
1549
|
-
try {
|
|
1550
|
-
const baseTxSize = isVersioned ? tx.serialize().length : tx.serialize({ requireAllSignatures: false, verifySignatures: false }).length;
|
|
1551
|
-
return baseTxSize + feePayerSize + signaturesSize;
|
|
1552
|
-
} catch (error) {
|
|
1553
|
-
return 9999;
|
|
1554
|
-
}
|
|
1555
|
-
}
|
|
1556
|
-
function getAccountKeys(tx, lookupTableAccounts) {
|
|
1557
|
-
const isVersioned = isV0Tx(tx);
|
|
1558
|
-
try {
|
|
1559
|
-
if (isVersioned) {
|
|
1560
|
-
const message = web3_js_1.TransactionMessage.decompile(tx.message, { addressLookupTableAccounts: lookupTableAccounts });
|
|
1561
|
-
return message.compileToLegacyMessage().getAccountKeys().length;
|
|
1562
|
-
} else {
|
|
1563
|
-
return tx.compileMessage().getAccountKeys().length;
|
|
1564
|
-
}
|
|
1565
|
-
} catch (error) {
|
|
1566
|
-
return 9999;
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
function decodeInstruction(idl, encoded) {
|
|
1570
|
-
const coder = new anchor_1.BorshInstructionCoder(idl);
|
|
1571
|
-
return coder.decode(encoded, "base58");
|
|
1572
|
-
}
|
|
1573
|
-
function decompileV0Transaction(tx, lookupTableAccounts) {
|
|
1574
|
-
return web3_js_1.TransactionMessage.decompile(tx.message, { addressLookupTableAccounts: lookupTableAccounts });
|
|
1575
|
-
}
|
|
1576
|
-
function legacyTxToV0Tx(transaction, opts) {
|
|
1577
|
-
const feePayer = opts?.feePayer ?? transaction.feePayer;
|
|
1578
|
-
const blockhash = opts?.blockhash ?? transaction.recentBlockhash;
|
|
1579
|
-
const additionalIxs = opts?.additionalIxs ?? [];
|
|
1580
|
-
const addressLookupTables = opts?.addressLookupTables ?? [];
|
|
1581
|
-
if (!feePayer || !blockhash) {
|
|
1582
|
-
throw new Error("Fee payer and blockhash are required");
|
|
1583
|
-
}
|
|
1584
|
-
const ixs = transaction.instructions;
|
|
1585
|
-
const versionedMessage = new web3_js_1.TransactionMessage({
|
|
1586
|
-
instructions: [...additionalIxs, ...ixs],
|
|
1587
|
-
payerKey: feePayer,
|
|
1588
|
-
recentBlockhash: blockhash
|
|
1589
|
-
});
|
|
1590
|
-
return new web3_js_1.VersionedTransaction(versionedMessage.compileToV0Message(addressLookupTables));
|
|
1591
|
-
}
|
|
1592
|
-
function updateV0Tx(transaction, opts) {
|
|
1593
|
-
const additionalIxs = opts?.additionalIxs ?? [];
|
|
1594
|
-
const addressLookupTables = opts?.addressLookupTables ?? [];
|
|
1595
|
-
let instructions = [];
|
|
1596
|
-
const message = decompileV0Transaction(transaction, addressLookupTables);
|
|
1597
|
-
const feePayer = opts?.feePayer ?? message.payerKey;
|
|
1598
|
-
const blockhash = opts?.blockhash ?? message.recentBlockhash;
|
|
1599
|
-
if (additionalIxs.length > 0) {
|
|
1600
|
-
instructions = replaceV0TxInstructions(additionalIxs, message.instructions, opts?.replaceOnly, opts?.indexOffset);
|
|
1601
|
-
} else {
|
|
1602
|
-
instructions = message.instructions;
|
|
1603
|
-
}
|
|
1604
|
-
const versionedMessage = new web3_js_1.TransactionMessage({
|
|
1605
|
-
instructions,
|
|
1606
|
-
payerKey: feePayer,
|
|
1607
|
-
recentBlockhash: blockhash
|
|
1608
|
-
});
|
|
1609
|
-
return new web3_js_1.VersionedTransaction(versionedMessage.compileToV0Message(addressLookupTables));
|
|
1610
|
-
}
|
|
1611
|
-
function compareInstructions(ix1, ix2) {
|
|
1612
|
-
const dataCompare = ix1.data.equals(ix2.data);
|
|
1613
|
-
const programIdCompare = ix1.programId.equals(ix2.programId);
|
|
1614
|
-
const keysCompare = ix1.keys.length === ix2.keys.length && ix1.keys.every((key, index) => {
|
|
1615
|
-
const key2 = ix2.keys[index];
|
|
1616
|
-
return key.pubkey.equals(key2.pubkey) && key.isSigner === key2.isSigner && key.isWritable === key2.isWritable;
|
|
1617
|
-
});
|
|
1618
|
-
return dataCompare && programIdCompare && keysCompare;
|
|
1619
|
-
}
|
|
1620
|
-
function replaceV0TxInstructions(additionalInstructions, instructions, replaceOnly, indexOffset) {
|
|
1621
|
-
let updatedAdditionalIxs = additionalInstructions;
|
|
1622
|
-
const updatedInstructions = instructions.map((ix) => {
|
|
1623
|
-
const programId = ix.programId;
|
|
1624
|
-
const additionalIxs = additionalInstructions.filter((a) => a.programId.equals(programId));
|
|
1625
|
-
if (additionalIxs.length > 0) {
|
|
1626
|
-
if (ix.programId.equals(web3_js_1.ComputeBudgetProgram.programId)) {
|
|
1627
|
-
const decoded = decodeComputeBudgetInstruction(ix);
|
|
1628
|
-
const updatedCuPriceIx = additionalIxs.find((a) => decodeComputeBudgetInstruction(a).instructionType === "SetComputeUnitPrice");
|
|
1629
|
-
const updatedCuLimitIx = additionalIxs.find((a) => decodeComputeBudgetInstruction(a).instructionType === "SetComputeUnitLimit");
|
|
1630
|
-
if (decoded.instructionType === "SetComputeUnitPrice" && updatedCuPriceIx) {
|
|
1631
|
-
updatedAdditionalIxs = updatedAdditionalIxs.filter((a) => !compareInstructions(a, updatedCuPriceIx));
|
|
1632
|
-
return updatedCuPriceIx;
|
|
1633
|
-
}
|
|
1634
|
-
if (decoded.instructionType === "SetComputeUnitLimit" && updatedCuLimitIx) {
|
|
1635
|
-
updatedAdditionalIxs = updatedAdditionalIxs.filter((a) => !compareInstructions(a, updatedCuLimitIx));
|
|
1636
|
-
return updatedCuLimitIx;
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
return ix;
|
|
1641
|
-
});
|
|
1642
|
-
if (replaceOnly) {
|
|
1643
|
-
return updatedInstructions;
|
|
1644
|
-
}
|
|
1645
|
-
if (indexOffset === void 0) {
|
|
1646
|
-
return [...updatedAdditionalIxs, ...updatedInstructions];
|
|
1647
|
-
}
|
|
1648
|
-
const result = [...updatedInstructions];
|
|
1649
|
-
result.splice(indexOffset, 0, ...updatedAdditionalIxs);
|
|
1650
|
-
return result;
|
|
1651
|
-
}
|
|
1652
|
-
function replaceV0TxBlockhash(transaction, blockhash) {
|
|
1653
|
-
let message = transaction.message;
|
|
1654
|
-
message.recentBlockhash = blockhash;
|
|
1655
|
-
return new web3_js_1.VersionedTransaction(message);
|
|
1656
|
-
}
|
|
1657
|
-
function addTransactionMetadata(transaction, options) {
|
|
1658
|
-
return Object.assign(transaction, options);
|
|
1659
|
-
}
|
|
1660
|
-
function identifyComputeBudgetInstruction(data) {
|
|
1661
|
-
const discriminator = data.readUInt8(0);
|
|
1662
|
-
switch (discriminator) {
|
|
1663
|
-
case 0:
|
|
1664
|
-
return "RequestUnits";
|
|
1665
|
-
case 1:
|
|
1666
|
-
return "RequestHeapFrame";
|
|
1667
|
-
case 2:
|
|
1668
|
-
return "SetComputeUnitLimit";
|
|
1669
|
-
case 3:
|
|
1670
|
-
return "SetComputeUnitPrice";
|
|
1671
|
-
case 4:
|
|
1672
|
-
return "SetLoadedAccountsDataSizeLimit";
|
|
1673
|
-
default:
|
|
1674
|
-
throw new Error("Unknown ComputeBudget instruction discriminator.");
|
|
1675
|
-
}
|
|
1676
|
-
}
|
|
1677
|
-
function decodeComputeBudgetInstruction(instruction) {
|
|
1678
|
-
const data = Buffer.from(instruction.data || instruction);
|
|
1679
|
-
const instructionType = identifyComputeBudgetInstruction(data);
|
|
1680
|
-
switch (instructionType) {
|
|
1681
|
-
case "RequestUnits": {
|
|
1682
|
-
if (data.length !== 9) {
|
|
1683
|
-
throw new Error("Invalid data length for RequestUnits");
|
|
1684
|
-
}
|
|
1685
|
-
const units = data.readUInt32LE(1);
|
|
1686
|
-
const additionalFee = data.readUInt32LE(5);
|
|
1687
|
-
return { instructionType, units, additionalFee };
|
|
1688
|
-
}
|
|
1689
|
-
case "RequestHeapFrame": {
|
|
1690
|
-
if (data.length !== 5) {
|
|
1691
|
-
throw new Error("Invalid data length for RequestHeapFrame");
|
|
1692
|
-
}
|
|
1693
|
-
const bytes = data.readUInt32LE(1);
|
|
1694
|
-
return { instructionType, bytes };
|
|
1695
|
-
}
|
|
1696
|
-
case "SetComputeUnitLimit": {
|
|
1697
|
-
if (data.length !== 5) {
|
|
1698
|
-
throw new Error("Invalid data length for SetComputeUnitLimit");
|
|
1699
|
-
}
|
|
1700
|
-
const units = data.readUInt32LE(1);
|
|
1701
|
-
return { instructionType, units };
|
|
1702
|
-
}
|
|
1703
|
-
case "SetComputeUnitPrice": {
|
|
1704
|
-
if (data.length !== 9) {
|
|
1705
|
-
throw new Error("Invalid data length for SetComputeUnitPrice");
|
|
1706
|
-
}
|
|
1707
|
-
const microLamports = data.readBigUInt64LE(1);
|
|
1708
|
-
return { instructionType, microLamports: microLamports.toString() };
|
|
1709
|
-
}
|
|
1710
|
-
case "SetLoadedAccountsDataSizeLimit": {
|
|
1711
|
-
if (data.length !== 5) {
|
|
1712
|
-
throw new Error("Invalid data length for SetLoadedAccountsDataSizeLimit");
|
|
1713
|
-
}
|
|
1714
|
-
const accountDataSizeLimit = data.readUInt32LE(1);
|
|
1715
|
-
return { instructionType, accountDataSizeLimit };
|
|
1716
|
-
}
|
|
1717
|
-
default:
|
|
1718
|
-
throw new Error("Unknown ComputeBudget instruction type.");
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
var DEFAULT_COMPUTE_BUDGET_IX = 2e5;
|
|
1722
|
-
function getComputeBudgetUnits(tx) {
|
|
1723
|
-
let instructions = [];
|
|
1724
|
-
if (isV0Tx(tx)) {
|
|
1725
|
-
const addressLookupTableAccounts = tx.addressLookupTables ?? [];
|
|
1726
|
-
const message = decompileV0Transaction(tx, addressLookupTableAccounts);
|
|
1727
|
-
instructions = message.instructions;
|
|
1728
|
-
} else {
|
|
1729
|
-
instructions = tx.instructions;
|
|
1730
|
-
}
|
|
1731
|
-
const computeBudgetIxs = instructions.filter((ix) => ix.programId.equals(web3_js_1.ComputeBudgetProgram.programId));
|
|
1732
|
-
if (computeBudgetIxs.length === 0) {
|
|
1733
|
-
return Math.min(instructions.length * DEFAULT_COMPUTE_BUDGET_IX, 14e5);
|
|
1734
|
-
}
|
|
1735
|
-
const decoded = computeBudgetIxs.map((ix) => decodeComputeBudgetInstruction(ix));
|
|
1736
|
-
const limit = decoded.find((ix) => ix.instructionType === "SetComputeUnitLimit");
|
|
1737
|
-
return limit?.units ?? instructions.length * DEFAULT_COMPUTE_BUDGET_IX;
|
|
1738
|
-
}
|
|
1739
|
-
var uiToMicroLamports = (ui, limitCU = 14e5) => {
|
|
1740
|
-
const priorityFeeMicroLamports = ui * web3_js_1.LAMPORTS_PER_SOL * 1e6;
|
|
1741
|
-
return priorityFeeMicroLamports / limitCU;
|
|
1742
|
-
};
|
|
1743
|
-
exports$1.uiToMicroLamports = uiToMicroLamports;
|
|
1744
|
-
var microLamportsToUi = (microLamports, limitCU = 14e5) => {
|
|
1745
|
-
const priorityFeeMicroLamports = microLamports * limitCU;
|
|
1746
|
-
const priorityFeeUi = priorityFeeMicroLamports / (web3_js_1.LAMPORTS_PER_SOL * 1e6);
|
|
1747
|
-
return Math.trunc(priorityFeeUi * web3_js_1.LAMPORTS_PER_SOL) / web3_js_1.LAMPORTS_PER_SOL;
|
|
1748
|
-
};
|
|
1749
|
-
exports$1.microLamportsToUi = microLamportsToUi;
|
|
1750
|
-
function splitInstructionsToFitTransactions(mandatoryIxs, ixs, opts) {
|
|
1751
|
-
const result = [];
|
|
1752
|
-
let buffer = [];
|
|
1753
|
-
function buildTx(mandatoryIxs2, extraIxs, opts2) {
|
|
1754
|
-
const messageV0 = new web3_js_1.TransactionMessage({
|
|
1755
|
-
payerKey: opts2.payerKey,
|
|
1756
|
-
recentBlockhash: opts2.blockhash,
|
|
1757
|
-
instructions: [...mandatoryIxs2, ...extraIxs]
|
|
1758
|
-
}).compileToV0Message(opts2.luts);
|
|
1759
|
-
return new web3_js_1.VersionedTransaction(messageV0);
|
|
1760
|
-
}
|
|
1761
|
-
for (const ix of ixs) {
|
|
1762
|
-
const trial = buildTx(mandatoryIxs, [...buffer, ix], opts);
|
|
1763
|
-
if (getTxSize(trial) <= constants_1.MAX_TX_SIZE) {
|
|
1764
|
-
buffer.push(ix);
|
|
1765
|
-
} else {
|
|
1766
|
-
if (buffer.length === 0) {
|
|
1767
|
-
throw new Error("Single instruction too large to fit in a transaction");
|
|
1768
|
-
}
|
|
1769
|
-
const tx = buildTx(mandatoryIxs, buffer, opts);
|
|
1770
|
-
result.push(tx);
|
|
1771
|
-
buffer = [ix];
|
|
1772
|
-
const solo = buildTx(mandatoryIxs, buffer, opts);
|
|
1773
|
-
if (getTxSize(solo) > constants_1.MAX_TX_SIZE) {
|
|
1774
|
-
throw new Error("Single instruction too large to fit in a transaction");
|
|
1775
|
-
}
|
|
1776
|
-
}
|
|
1777
|
-
}
|
|
1778
|
-
if (buffer.length > 0) {
|
|
1779
|
-
const tx = buildTx(mandatoryIxs, buffer, opts);
|
|
1780
|
-
result.push(tx);
|
|
1781
|
-
}
|
|
1782
|
-
return result;
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
});
|
|
1786
|
-
|
|
1787
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/modules/transactions/transaction.types.js
|
|
1788
|
-
var require_transaction_types = __commonJS({
|
|
1789
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/modules/transactions/transaction.types.js"(exports$1) {
|
|
1790
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
1791
|
-
exports$1.TransactionArenaKeyMap = exports$1.TransactionConfigMap = exports$1.TransactionType = void 0;
|
|
1792
|
-
var web3_js_1 = __require("@solana/web3.js");
|
|
1793
|
-
var TransactionType;
|
|
1794
|
-
(function(TransactionType2) {
|
|
1795
|
-
TransactionType2["DEPOSIT"] = "DEPOSIT";
|
|
1796
|
-
TransactionType2["WITHDRAW"] = "WITHDRAW";
|
|
1797
|
-
TransactionType2["REPAY"] = "REPAY";
|
|
1798
|
-
TransactionType2["BORROW"] = "BORROW";
|
|
1799
|
-
TransactionType2["FLASHLOAN"] = "FLASHLOAN";
|
|
1800
|
-
TransactionType2["LOOP"] = "LOOP";
|
|
1801
|
-
TransactionType2["REPAY_COLLAT"] = "REPAY_COLLAT";
|
|
1802
|
-
TransactionType2["LONG"] = "LONG";
|
|
1803
|
-
TransactionType2["SHORT"] = "SHORT";
|
|
1804
|
-
TransactionType2["CREATE_ACCOUNT"] = "CREATE_ACCOUNT";
|
|
1805
|
-
TransactionType2["CREATE_ATA"] = "CREATE_ATA";
|
|
1806
|
-
TransactionType2["CLOSE_ACCOUNT"] = "CLOSE_ACCOUNT";
|
|
1807
|
-
TransactionType2["CLOSE_POSITION"] = "CLOSE_POSITION";
|
|
1808
|
-
TransactionType2["MOVE_POSITION_WITHDRAW"] = "MOVE_POSITION_WITHDRAW";
|
|
1809
|
-
TransactionType2["MOVE_POSITION_DEPOSIT"] = "MOVE_POSITION_DEPOSIT";
|
|
1810
|
-
TransactionType2["WITHDRAW_ALL"] = "WITHDRAW_ALL";
|
|
1811
|
-
TransactionType2["TRANSFER_AUTH"] = "TRANSFER_AUTH";
|
|
1812
|
-
TransactionType2["CRANK"] = "CRANK";
|
|
1813
|
-
TransactionType2["DEPOSIT_STAKE"] = "DEPOSIT_STAKE";
|
|
1814
|
-
TransactionType2["WITHDRAW_STAKE"] = "WITHDRAW_STAKE";
|
|
1815
|
-
TransactionType2["INITIALIZE_STAKED_POOL"] = "INITIALIZE_STAKED_POOL";
|
|
1816
|
-
TransactionType2["ADD_STAKED_BANK"] = "ADD_STAKED_BANK";
|
|
1817
|
-
TransactionType2["MERGE_STAKE_ACCOUNTS"] = "MERGE_STAKE_ACCOUNTS";
|
|
1818
|
-
TransactionType2["STAKE_TO_STAKE"] = "STAKE_TO_STAKE";
|
|
1819
|
-
TransactionType2["MINT_LST_NATIVE"] = "MINT_LST_NATIVE";
|
|
1820
|
-
TransactionType2["SWAP_TO_SOL"] = "SWAP_TO_SOL";
|
|
1821
|
-
TransactionType2["SOL_TO_LST"] = "SOL_TO_LST";
|
|
1822
|
-
TransactionType2["UNSTAKE_LST"] = "UNSTAKE_LST";
|
|
1823
|
-
TransactionType2["WITHDRAW_EMISSIONS"] = "WITHDRAW_EMISSIONS";
|
|
1824
|
-
TransactionType2["LIQUIDATE_ACCOUNT"] = "LIQUIDATE_ACCOUNT";
|
|
1825
|
-
TransactionType2["CREATE_PERM_BANK"] = "CREATE_PERM_BANK";
|
|
1826
|
-
TransactionType2["CREATE_GROUP"] = "CREATE_GROUP";
|
|
1827
|
-
TransactionType2["JUPITER_SWAP"] = "JUPITER_SWAP";
|
|
1828
|
-
})(TransactionType || (exports$1.TransactionType = TransactionType = {}));
|
|
1829
|
-
exports$1.TransactionConfigMap = {
|
|
1830
|
-
// BASE LENDING ACTIONS
|
|
1831
|
-
[TransactionType.DEPOSIT]: {
|
|
1832
|
-
label: ({ amount, token } = {}) => amount && token ? `Deposit ${amount} ${token}` : "Deposit"
|
|
1833
|
-
},
|
|
1834
|
-
[TransactionType.WITHDRAW]: {
|
|
1835
|
-
label: ({ amount, token } = {}) => amount && token ? `Withdraw ${amount} ${token}` : "Withdraw"
|
|
1836
|
-
},
|
|
1837
|
-
[TransactionType.REPAY]: {
|
|
1838
|
-
label: ({ amount, token } = {}) => amount && token ? `Repay ${amount} ${token}` : "Repay"
|
|
1839
|
-
},
|
|
1840
|
-
[TransactionType.BORROW]: {
|
|
1841
|
-
label: ({ amount, token } = {}) => amount && token ? `Borrow ${amount} ${token}` : "Borrow"
|
|
1842
|
-
},
|
|
1843
|
-
// FLASHLOANS
|
|
1844
|
-
[TransactionType.FLASHLOAN]: { label: () => "Executing Flashloan" },
|
|
1845
|
-
[TransactionType.LOOP]: {
|
|
1846
|
-
label: ({ depositAmount, depositToken, borrowAmount, borrowToken } = {}) => depositAmount && depositToken && borrowAmount && borrowToken ? `Loop ${depositAmount} ${depositToken} with ${borrowAmount} ${borrowToken}` : "Loop"
|
|
1847
|
-
},
|
|
1848
|
-
[TransactionType.REPAY_COLLAT]: {
|
|
1849
|
-
label: ({ repayAmount, repayToken, amount, token } = {}) => repayAmount && repayToken && amount && token ? `Repay ${repayAmount} ${token} with ${amount} ${repayToken}` : "Repay with collateral"
|
|
1850
|
-
},
|
|
1851
|
-
[TransactionType.LONG]: {
|
|
1852
|
-
label: ({ depositToken, depositAmount, borrowToken } = {}) => depositToken && depositAmount && borrowToken ? `Long ${depositToken} with ${depositAmount} ${borrowToken}` : "Open long position"
|
|
1853
|
-
},
|
|
1854
|
-
[TransactionType.SHORT]: {
|
|
1855
|
-
label: ({ borrowToken, depositAmount, depositToken } = {}) => borrowToken && depositAmount && depositToken ? `Short ${borrowToken} with ${depositAmount} ${depositToken}` : "Open short position"
|
|
1856
|
-
},
|
|
1857
|
-
// SWB
|
|
1858
|
-
[TransactionType.CRANK]: { label: () => "Updating latest prices" },
|
|
1859
|
-
[TransactionType.JUPITER_SWAP]: {
|
|
1860
|
-
label: ({ originAmount, originToken, destinationAmount, destinationToken } = {}) => originAmount && originToken && destinationAmount && destinationToken ? `Swap ${originAmount} ${originToken} for ${destinationAmount} ${destinationToken}` : "Swap tokens"
|
|
1861
|
-
},
|
|
1862
|
-
// SETUP
|
|
1863
|
-
[TransactionType.CREATE_ACCOUNT]: { label: () => "Create marginfi account" },
|
|
1864
|
-
[TransactionType.CREATE_ATA]: { label: () => "Configure token account" },
|
|
1865
|
-
// ACCOUNT MANAGEMENT
|
|
1866
|
-
[TransactionType.CLOSE_ACCOUNT]: { label: () => "Close marginfi account" },
|
|
1867
|
-
[TransactionType.CLOSE_POSITION]: { label: () => "Close position" },
|
|
1868
|
-
[TransactionType.MOVE_POSITION_WITHDRAW]: {
|
|
1869
|
-
label: ({ originAccountAddress } = {}) => `Move position from ${originAccountAddress}`
|
|
1870
|
-
},
|
|
1871
|
-
[TransactionType.MOVE_POSITION_DEPOSIT]: {
|
|
1872
|
-
label: ({ destinationAccountAddress } = {}) => `Move position to ${destinationAccountAddress}`
|
|
1873
|
-
},
|
|
1874
|
-
[TransactionType.TRANSFER_AUTH]: { label: () => "Authorize account transfer" },
|
|
1875
|
-
// NATIVE STAKE ACTIONS
|
|
1876
|
-
[TransactionType.DEPOSIT_STAKE]: {
|
|
1877
|
-
label: ({ amount, token } = {}) => amount && token ? `Authorize stake account and deposit ${amount} ${token}` : "Authorize stake and deposit"
|
|
1878
|
-
},
|
|
1879
|
-
[TransactionType.WITHDRAW_STAKE]: {
|
|
1880
|
-
label: ({ amount, token } = {}) => "Authorize stake account"
|
|
1881
|
-
},
|
|
1882
|
-
[TransactionType.INITIALIZE_STAKED_POOL]: { label: () => "Initialize stake pool" },
|
|
1883
|
-
[TransactionType.ADD_STAKED_BANK]: { label: () => "Create staked asset bank" },
|
|
1884
|
-
[TransactionType.MERGE_STAKE_ACCOUNTS]: { label: () => "Merge stake accounts" },
|
|
1885
|
-
// LST (Liquid Staking Tokens)
|
|
1886
|
-
[TransactionType.STAKE_TO_STAKE]: { label: () => "Convert stake" },
|
|
1887
|
-
[TransactionType.MINT_LST_NATIVE]: { label: () => "Mint LST" },
|
|
1888
|
-
[TransactionType.SWAP_TO_SOL]: {
|
|
1889
|
-
label: ({ swapAmount, token } = {}) => swapAmount && token ? `Swap ${swapAmount} ${token} to SOL` : "Swap to SOL"
|
|
1890
|
-
},
|
|
1891
|
-
[TransactionType.SOL_TO_LST]: {
|
|
1892
|
-
label: ({ amount } = {}) => amount ? `Mint LST with ${amount} SOL` : "Mint LST with SOL"
|
|
1893
|
-
},
|
|
1894
|
-
[TransactionType.UNSTAKE_LST]: { label: ({ amount } = {}) => amount ? `Unstake ${amount} LST` : "Unstake LST" },
|
|
1895
|
-
// EMISSIONS
|
|
1896
|
-
[TransactionType.WITHDRAW_EMISSIONS]: { label: () => "Withdraw emissions" },
|
|
1897
|
-
// LIQUIDATE
|
|
1898
|
-
[TransactionType.LIQUIDATE_ACCOUNT]: { label: () => "Liquidate account" },
|
|
1899
|
-
// BANK and GROUPS
|
|
1900
|
-
[TransactionType.CREATE_PERM_BANK]: { label: () => "Create permissionless bank" },
|
|
1901
|
-
[TransactionType.CREATE_GROUP]: { label: () => "Create marginfi group" },
|
|
1902
|
-
[TransactionType.WITHDRAW_ALL]: {
|
|
1903
|
-
label: ({ amount, token } = {}) => amount && token ? `Withdraw ${amount} ${token}` : "Withdraw all"
|
|
1904
|
-
}
|
|
1905
|
-
};
|
|
1906
|
-
exports$1.TransactionArenaKeyMap = {
|
|
1907
|
-
[TransactionType.DEPOSIT]: new web3_js_1.PublicKey("ArenaDeposit1111111111111111111111111111111"),
|
|
1908
|
-
[TransactionType.WITHDRAW]: new web3_js_1.PublicKey("ArenaWithdraw111111111111111111111111111111"),
|
|
1909
|
-
[TransactionType.BORROW]: new web3_js_1.PublicKey("ArenaBorrow11111111111111111111111111111111"),
|
|
1910
|
-
[TransactionType.REPAY]: new web3_js_1.PublicKey("ArenaRepay111111111111111111111111111111111"),
|
|
1911
|
-
[TransactionType.REPAY_COLLAT]: new web3_js_1.PublicKey("ArenaRepayCo11at111111111111111111111111111"),
|
|
1912
|
-
[TransactionType.LONG]: new web3_js_1.PublicKey("ArenaLong1111111111111111111111111111111111"),
|
|
1913
|
-
[TransactionType.SHORT]: new web3_js_1.PublicKey("ArenaShort111111111111111111111111111111111"),
|
|
1914
|
-
[TransactionType.CLOSE_POSITION]: new web3_js_1.PublicKey("ArenaC1ose111111111111111111111111111111111")
|
|
1915
|
-
// Add more mappings if needed
|
|
1916
|
-
};
|
|
1917
|
-
}
|
|
1918
|
-
});
|
|
1919
|
-
|
|
1920
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/modules/transactions/index.js
|
|
1921
|
-
var require_transactions = __commonJS({
|
|
1922
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/modules/transactions/index.js"(exports$1) {
|
|
1923
|
-
var __createBinding = exports$1 && exports$1.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
1924
|
-
if (k2 === void 0) k2 = k;
|
|
1925
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1926
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1927
|
-
desc = { enumerable: true, get: function() {
|
|
1928
|
-
return m[k];
|
|
1929
|
-
} };
|
|
1930
|
-
}
|
|
1931
|
-
Object.defineProperty(o, k2, desc);
|
|
1932
|
-
}) : (function(o, m, k, k2) {
|
|
1933
|
-
if (k2 === void 0) k2 = k;
|
|
1934
|
-
o[k2] = m[k];
|
|
1935
|
-
}));
|
|
1936
|
-
var __exportStar = exports$1 && exports$1.__exportStar || function(m, exports2) {
|
|
1937
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
|
|
1938
|
-
};
|
|
1939
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
1940
|
-
__exportStar(require_transaction_utils(), exports$1);
|
|
1941
|
-
__exportStar(require_transaction_types(), exports$1);
|
|
1942
|
-
}
|
|
1943
|
-
});
|
|
1944
|
-
|
|
1945
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/modules/index.js
|
|
1946
|
-
var require_modules = __commonJS({
|
|
1947
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/modules/index.js"(exports$1) {
|
|
1948
|
-
var __createBinding = exports$1 && exports$1.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
1949
|
-
if (k2 === void 0) k2 = k;
|
|
1950
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1951
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1952
|
-
desc = { enumerable: true, get: function() {
|
|
1953
|
-
return m[k];
|
|
1954
|
-
} };
|
|
1955
|
-
}
|
|
1956
|
-
Object.defineProperty(o, k2, desc);
|
|
1957
|
-
}) : (function(o, m, k, k2) {
|
|
1958
|
-
if (k2 === void 0) k2 = k;
|
|
1959
|
-
o[k2] = m[k];
|
|
1960
|
-
}));
|
|
1961
|
-
var __exportStar = exports$1 && exports$1.__exportStar || function(m, exports2) {
|
|
1962
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
|
|
1963
|
-
};
|
|
1964
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
1965
|
-
__exportStar(require_transactions(), exports$1);
|
|
1966
|
-
}
|
|
1967
|
-
});
|
|
1968
|
-
|
|
1969
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/spl.js
|
|
1970
|
-
var require_spl = __commonJS({
|
|
1971
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/spl.js"(exports$1) {
|
|
1972
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
1973
|
-
exports$1.MEMO_PROGRAM_ID = exports$1.MINT_SIZE = exports$1.MintLayout = exports$1.initializeAccountInstructionData = exports$1.TokenInstruction = exports$1.transferCheckedInstructionData = exports$1.closeAccountInstructionData = exports$1.syncNativeInstructionData = exports$1.ASSOCIATED_TOKEN_PROGRAM_ID = exports$1.LENGTH_SIZE = exports$1.TYPE_SIZE = exports$1.ExtensionType = exports$1.TOKEN_2022_PROGRAM_ID = exports$1.TOKEN_PROGRAM_ID = exports$1.NATIVE_MINT = exports$1.ACCOUNT_SIZE = exports$1.AccountLayout = exports$1.AccountState = exports$1.TokenUnsupportedInstructionError = exports$1.TokenInvalidInstructionTypeError = exports$1.TokenInvalidInstructionDataError = exports$1.TokenInvalidInstructionKeysError = exports$1.TokenInvalidInstructionProgramError = exports$1.TokenOwnerOffCurveError = exports$1.TokenInvalidOwnerError = exports$1.TokenInvalidMintError = exports$1.TokenInvalidAccountSizeError = exports$1.TokenInvalidAccountOwnerError = exports$1.TokenInvalidAccountError = exports$1.TokenAccountNotFoundError = exports$1.TokenError = exports$1.ACCOUNT_TYPE_SIZE = exports$1.SplAccountType = exports$1.MULTISIG_SIZE = exports$1.MultisigLayout = void 0;
|
|
1974
|
-
exports$1.getAccount = getAccount2;
|
|
1975
|
-
exports$1.getMultipleAccounts = getMultipleAccounts2;
|
|
1976
|
-
exports$1.getMinimumBalanceForRentExemptAccount = getMinimumBalanceForRentExemptAccount2;
|
|
1977
|
-
exports$1.getAccountLen = getAccountLen2;
|
|
1978
|
-
exports$1.getMinimumBalanceForRentExemptAccountWithExtensions = getMinimumBalanceForRentExemptAccountWithExtensions2;
|
|
1979
|
-
exports$1.unpackAccount = unpackAccount2;
|
|
1980
|
-
exports$1.getAssociatedTokenAddressSync = getAssociatedTokenAddressSync2;
|
|
1981
|
-
exports$1.createAssociatedTokenAccountInstruction = createAssociatedTokenAccountInstruction2;
|
|
1982
|
-
exports$1.createAssociatedTokenAccountIdempotentInstruction = createAssociatedTokenAccountIdempotentInstruction2;
|
|
1983
|
-
exports$1.createSyncNativeInstruction = createSyncNativeInstruction2;
|
|
1984
|
-
exports$1.createCloseAccountInstruction = createCloseAccountInstruction2;
|
|
1985
|
-
exports$1.createTransferCheckedInstruction = createTransferCheckedInstruction2;
|
|
1986
|
-
exports$1.createInitializeAccountInstruction = createInitializeAccountInstruction2;
|
|
1987
|
-
exports$1.addSigners = addSigners2;
|
|
1988
|
-
exports$1.getMint = getMint2;
|
|
1989
|
-
exports$1.createMemoInstruction = createMemoInstruction2;
|
|
1990
|
-
var buffer_layout_1 = __require("@solana/buffer-layout");
|
|
1991
|
-
var buffer_layout_utils_1 = __require("@solana/buffer-layout-utils");
|
|
1992
|
-
var web3_js_1 = __require("@solana/web3.js");
|
|
1993
|
-
var buffer_1 = __require("buffer");
|
|
1994
|
-
exports$1.MultisigLayout = (0, buffer_layout_1.struct)([
|
|
1995
|
-
(0, buffer_layout_1.u8)("m"),
|
|
1996
|
-
(0, buffer_layout_1.u8)("n"),
|
|
1997
|
-
(0, buffer_layout_utils_1.bool)("isInitialized"),
|
|
1998
|
-
(0, buffer_layout_utils_1.publicKey)("signer1"),
|
|
1999
|
-
(0, buffer_layout_utils_1.publicKey)("signer2"),
|
|
2000
|
-
(0, buffer_layout_utils_1.publicKey)("signer3"),
|
|
2001
|
-
(0, buffer_layout_utils_1.publicKey)("signer4"),
|
|
2002
|
-
(0, buffer_layout_utils_1.publicKey)("signer5"),
|
|
2003
|
-
(0, buffer_layout_utils_1.publicKey)("signer6"),
|
|
2004
|
-
(0, buffer_layout_utils_1.publicKey)("signer7"),
|
|
2005
|
-
(0, buffer_layout_utils_1.publicKey)("signer8"),
|
|
2006
|
-
(0, buffer_layout_utils_1.publicKey)("signer9"),
|
|
2007
|
-
(0, buffer_layout_utils_1.publicKey)("signer10"),
|
|
2008
|
-
(0, buffer_layout_utils_1.publicKey)("signer11")
|
|
2009
|
-
]);
|
|
2010
|
-
exports$1.MULTISIG_SIZE = exports$1.MultisigLayout.span;
|
|
2011
|
-
var SplAccountType2;
|
|
2012
|
-
(function(SplAccountType3) {
|
|
2013
|
-
SplAccountType3[SplAccountType3["Uninitialized"] = 0] = "Uninitialized";
|
|
2014
|
-
SplAccountType3[SplAccountType3["Mint"] = 1] = "Mint";
|
|
2015
|
-
SplAccountType3[SplAccountType3["Account"] = 2] = "Account";
|
|
2016
|
-
})(SplAccountType2 || (exports$1.SplAccountType = SplAccountType2 = {}));
|
|
2017
|
-
exports$1.ACCOUNT_TYPE_SIZE = 1;
|
|
2018
|
-
var TokenError2 = class extends Error {
|
|
2019
|
-
constructor(message) {
|
|
2020
|
-
super(message);
|
|
2021
|
-
}
|
|
2022
|
-
};
|
|
2023
|
-
exports$1.TokenError = TokenError2;
|
|
2024
|
-
var TokenAccountNotFoundError2 = class extends TokenError2 {
|
|
2025
|
-
constructor() {
|
|
2026
|
-
super(...arguments);
|
|
2027
|
-
this.name = "TokenAccountNotFoundError";
|
|
2028
|
-
}
|
|
2029
|
-
};
|
|
2030
|
-
exports$1.TokenAccountNotFoundError = TokenAccountNotFoundError2;
|
|
2031
|
-
var TokenInvalidAccountError2 = class extends TokenError2 {
|
|
2032
|
-
constructor() {
|
|
2033
|
-
super(...arguments);
|
|
2034
|
-
this.name = "TokenInvalidAccountError";
|
|
2035
|
-
}
|
|
2036
|
-
};
|
|
2037
|
-
exports$1.TokenInvalidAccountError = TokenInvalidAccountError2;
|
|
2038
|
-
var TokenInvalidAccountOwnerError2 = class extends TokenError2 {
|
|
2039
|
-
constructor() {
|
|
2040
|
-
super(...arguments);
|
|
2041
|
-
this.name = "TokenInvalidAccountOwnerError";
|
|
2042
|
-
}
|
|
2043
|
-
};
|
|
2044
|
-
exports$1.TokenInvalidAccountOwnerError = TokenInvalidAccountOwnerError2;
|
|
2045
|
-
var TokenInvalidAccountSizeError2 = class extends TokenError2 {
|
|
2046
|
-
constructor() {
|
|
2047
|
-
super(...arguments);
|
|
2048
|
-
this.name = "TokenInvalidAccountSizeError";
|
|
2049
|
-
}
|
|
2050
|
-
};
|
|
2051
|
-
exports$1.TokenInvalidAccountSizeError = TokenInvalidAccountSizeError2;
|
|
2052
|
-
var TokenInvalidMintError2 = class extends TokenError2 {
|
|
2053
|
-
constructor() {
|
|
2054
|
-
super(...arguments);
|
|
2055
|
-
this.name = "TokenInvalidMintError";
|
|
2056
|
-
}
|
|
2057
|
-
};
|
|
2058
|
-
exports$1.TokenInvalidMintError = TokenInvalidMintError2;
|
|
2059
|
-
var TokenInvalidOwnerError2 = class extends TokenError2 {
|
|
2060
|
-
constructor() {
|
|
2061
|
-
super(...arguments);
|
|
2062
|
-
this.name = "TokenInvalidOwnerError";
|
|
2063
|
-
}
|
|
2064
|
-
};
|
|
2065
|
-
exports$1.TokenInvalidOwnerError = TokenInvalidOwnerError2;
|
|
2066
|
-
var TokenOwnerOffCurveError2 = class extends TokenError2 {
|
|
2067
|
-
constructor() {
|
|
2068
|
-
super(...arguments);
|
|
2069
|
-
this.name = "TokenOwnerOffCurveError";
|
|
2070
|
-
}
|
|
2071
|
-
};
|
|
2072
|
-
exports$1.TokenOwnerOffCurveError = TokenOwnerOffCurveError2;
|
|
2073
|
-
var TokenInvalidInstructionProgramError2 = class extends TokenError2 {
|
|
2074
|
-
constructor() {
|
|
2075
|
-
super(...arguments);
|
|
2076
|
-
this.name = "TokenInvalidInstructionProgramError";
|
|
2077
|
-
}
|
|
2078
|
-
};
|
|
2079
|
-
exports$1.TokenInvalidInstructionProgramError = TokenInvalidInstructionProgramError2;
|
|
2080
|
-
var TokenInvalidInstructionKeysError2 = class extends TokenError2 {
|
|
2081
|
-
constructor() {
|
|
2082
|
-
super(...arguments);
|
|
2083
|
-
this.name = "TokenInvalidInstructionKeysError";
|
|
2084
|
-
}
|
|
2085
|
-
};
|
|
2086
|
-
exports$1.TokenInvalidInstructionKeysError = TokenInvalidInstructionKeysError2;
|
|
2087
|
-
var TokenInvalidInstructionDataError2 = class extends TokenError2 {
|
|
2088
|
-
constructor() {
|
|
2089
|
-
super(...arguments);
|
|
2090
|
-
this.name = "TokenInvalidInstructionDataError";
|
|
2091
|
-
}
|
|
2092
|
-
};
|
|
2093
|
-
exports$1.TokenInvalidInstructionDataError = TokenInvalidInstructionDataError2;
|
|
2094
|
-
var TokenInvalidInstructionTypeError2 = class extends TokenError2 {
|
|
2095
|
-
constructor() {
|
|
2096
|
-
super(...arguments);
|
|
2097
|
-
this.name = "TokenInvalidInstructionTypeError";
|
|
2098
|
-
}
|
|
2099
|
-
};
|
|
2100
|
-
exports$1.TokenInvalidInstructionTypeError = TokenInvalidInstructionTypeError2;
|
|
2101
|
-
var TokenUnsupportedInstructionError2 = class extends TokenError2 {
|
|
2102
|
-
constructor() {
|
|
2103
|
-
super(...arguments);
|
|
2104
|
-
this.name = "TokenUnsupportedInstructionError";
|
|
2105
|
-
}
|
|
2106
|
-
};
|
|
2107
|
-
exports$1.TokenUnsupportedInstructionError = TokenUnsupportedInstructionError2;
|
|
2108
|
-
var AccountState2;
|
|
2109
|
-
(function(AccountState3) {
|
|
2110
|
-
AccountState3[AccountState3["Uninitialized"] = 0] = "Uninitialized";
|
|
2111
|
-
AccountState3[AccountState3["Initialized"] = 1] = "Initialized";
|
|
2112
|
-
AccountState3[AccountState3["Frozen"] = 2] = "Frozen";
|
|
2113
|
-
})(AccountState2 || (exports$1.AccountState = AccountState2 = {}));
|
|
2114
|
-
exports$1.AccountLayout = (0, buffer_layout_1.struct)([
|
|
2115
|
-
(0, buffer_layout_utils_1.publicKey)("mint"),
|
|
2116
|
-
(0, buffer_layout_utils_1.publicKey)("owner"),
|
|
2117
|
-
(0, buffer_layout_utils_1.u64)("amount"),
|
|
2118
|
-
(0, buffer_layout_1.u32)("delegateOption"),
|
|
2119
|
-
(0, buffer_layout_utils_1.publicKey)("delegate"),
|
|
2120
|
-
(0, buffer_layout_1.u8)("state"),
|
|
2121
|
-
(0, buffer_layout_1.u32)("isNativeOption"),
|
|
2122
|
-
(0, buffer_layout_utils_1.u64)("isNative"),
|
|
2123
|
-
(0, buffer_layout_utils_1.u64)("delegatedAmount"),
|
|
2124
|
-
(0, buffer_layout_1.u32)("closeAuthorityOption"),
|
|
2125
|
-
(0, buffer_layout_utils_1.publicKey)("closeAuthority")
|
|
2126
|
-
]);
|
|
2127
|
-
exports$1.ACCOUNT_SIZE = exports$1.AccountLayout.span;
|
|
2128
|
-
exports$1.NATIVE_MINT = new web3_js_1.PublicKey("So11111111111111111111111111111111111111112");
|
|
2129
|
-
async function getAccount2(connection, address, commitment, programId = exports$1.TOKEN_PROGRAM_ID) {
|
|
2130
|
-
const info = await connection.getAccountInfo(address, commitment);
|
|
2131
|
-
return unpackAccount2(address, info, programId);
|
|
2132
|
-
}
|
|
2133
|
-
exports$1.TOKEN_PROGRAM_ID = new web3_js_1.PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
|
|
2134
|
-
exports$1.TOKEN_2022_PROGRAM_ID = new web3_js_1.PublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
|
|
2135
|
-
async function getMultipleAccounts2(connection, addresses, commitment, programId = exports$1.TOKEN_PROGRAM_ID) {
|
|
2136
|
-
const infos = await connection.getMultipleAccountsInfo(addresses, commitment);
|
|
2137
|
-
return addresses.map((address, i) => (
|
|
2138
|
-
//@ts-ignore
|
|
2139
|
-
unpackAccount2(address, infos[i], programId)
|
|
2140
|
-
));
|
|
2141
|
-
}
|
|
2142
|
-
async function getMinimumBalanceForRentExemptAccount2(connection, commitment) {
|
|
2143
|
-
return await getMinimumBalanceForRentExemptAccountWithExtensions2(connection, [], commitment);
|
|
2144
|
-
}
|
|
2145
|
-
var ExtensionType2;
|
|
2146
|
-
(function(ExtensionType3) {
|
|
2147
|
-
ExtensionType3[ExtensionType3["Uninitialized"] = 0] = "Uninitialized";
|
|
2148
|
-
ExtensionType3[ExtensionType3["TransferFeeConfig"] = 1] = "TransferFeeConfig";
|
|
2149
|
-
ExtensionType3[ExtensionType3["TransferFeeAmount"] = 2] = "TransferFeeAmount";
|
|
2150
|
-
ExtensionType3[ExtensionType3["MintCloseAuthority"] = 3] = "MintCloseAuthority";
|
|
2151
|
-
ExtensionType3[ExtensionType3["ConfidentialTransferMint"] = 4] = "ConfidentialTransferMint";
|
|
2152
|
-
ExtensionType3[ExtensionType3["ConfidentialTransferAccount"] = 5] = "ConfidentialTransferAccount";
|
|
2153
|
-
ExtensionType3[ExtensionType3["DefaultAccountState"] = 6] = "DefaultAccountState";
|
|
2154
|
-
ExtensionType3[ExtensionType3["ImmutableOwner"] = 7] = "ImmutableOwner";
|
|
2155
|
-
ExtensionType3[ExtensionType3["MemoTransfer"] = 8] = "MemoTransfer";
|
|
2156
|
-
ExtensionType3[ExtensionType3["NonTransferable"] = 9] = "NonTransferable";
|
|
2157
|
-
ExtensionType3[ExtensionType3["InterestBearingMint"] = 10] = "InterestBearingMint";
|
|
2158
|
-
})(ExtensionType2 || (exports$1.ExtensionType = ExtensionType2 = {}));
|
|
2159
|
-
function getAccountLen2(extensionTypes) {
|
|
2160
|
-
return getLen2(extensionTypes, exports$1.ACCOUNT_SIZE);
|
|
2161
|
-
}
|
|
2162
|
-
exports$1.TYPE_SIZE = 2;
|
|
2163
|
-
exports$1.LENGTH_SIZE = 2;
|
|
2164
|
-
function getLen2(extensionTypes, baseSize) {
|
|
2165
|
-
if (extensionTypes.length === 0) {
|
|
2166
|
-
return baseSize;
|
|
2167
|
-
} else {
|
|
2168
|
-
const accountLength = exports$1.ACCOUNT_SIZE + exports$1.ACCOUNT_TYPE_SIZE;
|
|
2169
|
-
if (accountLength === exports$1.MULTISIG_SIZE) {
|
|
2170
|
-
return accountLength + exports$1.TYPE_SIZE;
|
|
2171
|
-
} else {
|
|
2172
|
-
return accountLength;
|
|
2173
|
-
}
|
|
2174
|
-
}
|
|
2175
|
-
}
|
|
2176
|
-
async function getMinimumBalanceForRentExemptAccountWithExtensions2(connection, extensions, commitment) {
|
|
2177
|
-
const accountLen = getAccountLen2(extensions);
|
|
2178
|
-
return await connection.getMinimumBalanceForRentExemption(accountLen, commitment);
|
|
2179
|
-
}
|
|
2180
|
-
function unpackAccount2(address, info, programId = exports$1.TOKEN_PROGRAM_ID) {
|
|
2181
|
-
if (!info)
|
|
2182
|
-
throw new TokenAccountNotFoundError2();
|
|
2183
|
-
if (!info.owner.equals(programId))
|
|
2184
|
-
throw new TokenInvalidAccountOwnerError2();
|
|
2185
|
-
if (info.data.length < exports$1.ACCOUNT_SIZE)
|
|
2186
|
-
throw new TokenInvalidAccountSizeError2();
|
|
2187
|
-
const rawAccount = exports$1.AccountLayout.decode(info.data.slice(0, exports$1.ACCOUNT_SIZE));
|
|
2188
|
-
let tlvData = buffer_1.Buffer.alloc(0);
|
|
2189
|
-
if (info.data.length > exports$1.ACCOUNT_SIZE) {
|
|
2190
|
-
if (info.data.length === exports$1.MULTISIG_SIZE)
|
|
2191
|
-
throw new TokenInvalidAccountSizeError2();
|
|
2192
|
-
if (info.data[exports$1.ACCOUNT_SIZE] != SplAccountType2.Account)
|
|
2193
|
-
throw new TokenInvalidAccountError2();
|
|
2194
|
-
tlvData = info.data.slice(exports$1.ACCOUNT_SIZE + exports$1.ACCOUNT_TYPE_SIZE);
|
|
2195
|
-
}
|
|
2196
|
-
return {
|
|
2197
|
-
address,
|
|
2198
|
-
mint: rawAccount.mint,
|
|
2199
|
-
owner: rawAccount.owner,
|
|
2200
|
-
amount: rawAccount.amount,
|
|
2201
|
-
delegate: rawAccount.delegateOption ? rawAccount.delegate : null,
|
|
2202
|
-
delegatedAmount: rawAccount.delegatedAmount,
|
|
2203
|
-
isInitialized: rawAccount.state !== AccountState2.Uninitialized,
|
|
2204
|
-
isFrozen: rawAccount.state === AccountState2.Frozen,
|
|
2205
|
-
isNative: !!rawAccount.isNativeOption,
|
|
2206
|
-
rentExemptReserve: rawAccount.isNativeOption ? rawAccount.isNative : null,
|
|
2207
|
-
closeAuthority: rawAccount.closeAuthorityOption ? rawAccount.closeAuthority : null,
|
|
2208
|
-
tlvData
|
|
2209
|
-
};
|
|
2210
|
-
}
|
|
2211
|
-
exports$1.ASSOCIATED_TOKEN_PROGRAM_ID = new web3_js_1.PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
|
|
2212
|
-
function getAssociatedTokenAddressSync2(mint, owner, allowOwnerOffCurve = false, programId = exports$1.TOKEN_PROGRAM_ID, associatedTokenProgramId = exports$1.ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
2213
|
-
if (!allowOwnerOffCurve && !web3_js_1.PublicKey.isOnCurve(owner.toBuffer()))
|
|
2214
|
-
throw new TokenOwnerOffCurveError2();
|
|
2215
|
-
const [address] = web3_js_1.PublicKey.findProgramAddressSync([owner.toBuffer(), programId.toBuffer(), mint.toBuffer()], associatedTokenProgramId);
|
|
2216
|
-
return address;
|
|
2217
|
-
}
|
|
2218
|
-
function createAssociatedTokenAccountInstruction2(payer, associatedToken, owner, mint, programId = exports$1.TOKEN_PROGRAM_ID, associatedTokenProgramId = exports$1.ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
2219
|
-
const keys = [
|
|
2220
|
-
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
2221
|
-
{ pubkey: associatedToken, isSigner: false, isWritable: true },
|
|
2222
|
-
{ pubkey: owner, isSigner: false, isWritable: false },
|
|
2223
|
-
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
2224
|
-
{ pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2225
|
-
{ pubkey: programId, isSigner: false, isWritable: false },
|
|
2226
|
-
{ pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }
|
|
2227
|
-
];
|
|
2228
|
-
return new web3_js_1.TransactionInstruction({
|
|
2229
|
-
keys,
|
|
2230
|
-
programId: associatedTokenProgramId,
|
|
2231
|
-
data: buffer_1.Buffer.alloc(0)
|
|
2232
|
-
});
|
|
2233
|
-
}
|
|
2234
|
-
function createAssociatedTokenAccountIdempotentInstruction2(payer, associatedToken, owner, mint, programId = exports$1.TOKEN_PROGRAM_ID, associatedTokenProgramId = exports$1.ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
2235
|
-
return buildAssociatedTokenAccountInstruction2(payer, associatedToken, owner, mint, buffer_1.Buffer.from([1]), programId, associatedTokenProgramId);
|
|
2236
|
-
}
|
|
2237
|
-
exports$1.syncNativeInstructionData = (0, buffer_layout_1.struct)([(0, buffer_layout_1.u8)("instruction")]);
|
|
2238
|
-
function createSyncNativeInstruction2(account, programId = exports$1.TOKEN_PROGRAM_ID) {
|
|
2239
|
-
const keys = [{ pubkey: account, isSigner: false, isWritable: true }];
|
|
2240
|
-
const data = buffer_1.Buffer.alloc(exports$1.syncNativeInstructionData.span);
|
|
2241
|
-
exports$1.syncNativeInstructionData.encode({ instruction: TokenInstruction2.SyncNative }, data);
|
|
2242
|
-
return new web3_js_1.TransactionInstruction({ keys, programId, data });
|
|
2243
|
-
}
|
|
2244
|
-
exports$1.closeAccountInstructionData = (0, buffer_layout_1.struct)([(0, buffer_layout_1.u8)("instruction")]);
|
|
2245
|
-
function createCloseAccountInstruction2(account, destination, authority, multiSigners = [], programId = exports$1.TOKEN_PROGRAM_ID) {
|
|
2246
|
-
const keys = addSigners2([
|
|
2247
|
-
{ pubkey: account, isSigner: false, isWritable: true },
|
|
2248
|
-
{ pubkey: destination, isSigner: false, isWritable: true }
|
|
2249
|
-
], authority, multiSigners);
|
|
2250
|
-
const data = buffer_1.Buffer.alloc(exports$1.closeAccountInstructionData.span);
|
|
2251
|
-
exports$1.closeAccountInstructionData.encode({ instruction: TokenInstruction2.CloseAccount }, data);
|
|
2252
|
-
return new web3_js_1.TransactionInstruction({ keys, programId, data });
|
|
2253
|
-
}
|
|
2254
|
-
function buildAssociatedTokenAccountInstruction2(payer, associatedToken, owner, mint, instructionData, programId = exports$1.TOKEN_PROGRAM_ID, associatedTokenProgramId = exports$1.ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
2255
|
-
const keys = [
|
|
2256
|
-
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
2257
|
-
{ pubkey: associatedToken, isSigner: false, isWritable: true },
|
|
2258
|
-
{ pubkey: owner, isSigner: false, isWritable: false },
|
|
2259
|
-
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
2260
|
-
{ pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2261
|
-
{ pubkey: programId, isSigner: false, isWritable: false }
|
|
2262
|
-
];
|
|
2263
|
-
return new web3_js_1.TransactionInstruction({
|
|
2264
|
-
keys,
|
|
2265
|
-
programId: associatedTokenProgramId,
|
|
2266
|
-
data: instructionData
|
|
2267
|
-
});
|
|
2268
|
-
}
|
|
2269
|
-
exports$1.transferCheckedInstructionData = (0, buffer_layout_1.struct)([
|
|
2270
|
-
(0, buffer_layout_1.u8)("instruction"),
|
|
2271
|
-
(0, buffer_layout_utils_1.u64)("amount"),
|
|
2272
|
-
(0, buffer_layout_1.u8)("decimals")
|
|
2273
|
-
]);
|
|
2274
|
-
function createTransferCheckedInstruction2(source, mint, destination, owner, amount, decimals, multiSigners = [], programId = exports$1.TOKEN_PROGRAM_ID) {
|
|
2275
|
-
const keys = addSigners2([
|
|
2276
|
-
{ pubkey: source, isSigner: false, isWritable: true },
|
|
2277
|
-
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
2278
|
-
{ pubkey: destination, isSigner: false, isWritable: true }
|
|
2279
|
-
], owner, multiSigners);
|
|
2280
|
-
const data = buffer_1.Buffer.alloc(exports$1.transferCheckedInstructionData.span);
|
|
2281
|
-
exports$1.transferCheckedInstructionData.encode({
|
|
2282
|
-
instruction: TokenInstruction2.TransferChecked,
|
|
2283
|
-
amount: BigInt(amount),
|
|
2284
|
-
decimals
|
|
2285
|
-
}, data);
|
|
2286
|
-
return new web3_js_1.TransactionInstruction({ keys, programId, data });
|
|
2287
|
-
}
|
|
2288
|
-
var TokenInstruction2;
|
|
2289
|
-
(function(TokenInstruction3) {
|
|
2290
|
-
TokenInstruction3[TokenInstruction3["InitializeAccount"] = 1] = "InitializeAccount";
|
|
2291
|
-
TokenInstruction3[TokenInstruction3["TransferChecked"] = 12] = "TransferChecked";
|
|
2292
|
-
TokenInstruction3[TokenInstruction3["CloseAccount"] = 9] = "CloseAccount";
|
|
2293
|
-
TokenInstruction3[TokenInstruction3["SyncNative"] = 17] = "SyncNative";
|
|
2294
|
-
})(TokenInstruction2 || (exports$1.TokenInstruction = TokenInstruction2 = {}));
|
|
2295
|
-
exports$1.initializeAccountInstructionData = (0, buffer_layout_1.struct)([(0, buffer_layout_1.u8)("instruction")]);
|
|
2296
|
-
function createInitializeAccountInstruction2(account, mint, owner, programId = exports$1.TOKEN_PROGRAM_ID) {
|
|
2297
|
-
const keys = [
|
|
2298
|
-
{ pubkey: account, isSigner: false, isWritable: true },
|
|
2299
|
-
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
2300
|
-
{ pubkey: owner, isSigner: false, isWritable: false },
|
|
2301
|
-
{ pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }
|
|
2302
|
-
];
|
|
2303
|
-
const data = buffer_1.Buffer.alloc(exports$1.initializeAccountInstructionData.span);
|
|
2304
|
-
exports$1.initializeAccountInstructionData.encode({ instruction: TokenInstruction2.InitializeAccount }, data);
|
|
2305
|
-
return new web3_js_1.TransactionInstruction({ keys, programId, data });
|
|
2306
|
-
}
|
|
2307
|
-
function addSigners2(keys, ownerOrAuthority, multiSigners) {
|
|
2308
|
-
if (multiSigners.length) {
|
|
2309
|
-
keys.push({ pubkey: ownerOrAuthority, isSigner: false, isWritable: false });
|
|
2310
|
-
for (const signer of multiSigners) {
|
|
2311
|
-
keys.push({
|
|
2312
|
-
pubkey: signer.publicKey,
|
|
2313
|
-
isSigner: true,
|
|
2314
|
-
isWritable: false
|
|
2315
|
-
});
|
|
2316
|
-
}
|
|
2317
|
-
} else {
|
|
2318
|
-
keys.push({ pubkey: ownerOrAuthority, isSigner: true, isWritable: false });
|
|
2319
|
-
}
|
|
2320
|
-
return keys;
|
|
2321
|
-
}
|
|
2322
|
-
exports$1.MintLayout = (0, buffer_layout_1.struct)([
|
|
2323
|
-
(0, buffer_layout_1.u32)("mintAuthorityOption"),
|
|
2324
|
-
(0, buffer_layout_utils_1.publicKey)("mintAuthority"),
|
|
2325
|
-
(0, buffer_layout_utils_1.u64)("supply"),
|
|
2326
|
-
(0, buffer_layout_1.u8)("decimals"),
|
|
2327
|
-
(0, buffer_layout_utils_1.bool)("isInitialized"),
|
|
2328
|
-
(0, buffer_layout_1.u32)("freezeAuthorityOption"),
|
|
2329
|
-
(0, buffer_layout_utils_1.publicKey)("freezeAuthority")
|
|
2330
|
-
]);
|
|
2331
|
-
exports$1.MINT_SIZE = exports$1.MintLayout.span;
|
|
2332
|
-
async function getMint2(connection, address, commitment, programId = exports$1.TOKEN_PROGRAM_ID) {
|
|
2333
|
-
const info = await connection.getAccountInfo(address, commitment);
|
|
2334
|
-
if (!info)
|
|
2335
|
-
throw new TokenAccountNotFoundError2();
|
|
2336
|
-
if (!info.owner.equals(programId))
|
|
2337
|
-
throw new TokenInvalidAccountOwnerError2();
|
|
2338
|
-
if (info.data.length != exports$1.MINT_SIZE)
|
|
2339
|
-
throw new TokenInvalidAccountSizeError2();
|
|
2340
|
-
const rawMint = exports$1.MintLayout.decode(info.data);
|
|
2341
|
-
return {
|
|
2342
|
-
address,
|
|
2343
|
-
mintAuthority: rawMint.mintAuthorityOption ? rawMint.mintAuthority : null,
|
|
2344
|
-
supply: rawMint.supply,
|
|
2345
|
-
decimals: rawMint.decimals,
|
|
2346
|
-
isInitialized: rawMint.isInitialized,
|
|
2347
|
-
freezeAuthority: rawMint.freezeAuthorityOption ? rawMint.freezeAuthority : null
|
|
2348
|
-
};
|
|
2349
|
-
}
|
|
2350
|
-
exports$1.MEMO_PROGRAM_ID = new web3_js_1.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr");
|
|
2351
|
-
function createMemoInstruction2(memo, signerPubkeys) {
|
|
2352
|
-
const keys = signerPubkeys == null ? [] : signerPubkeys.map(function(key) {
|
|
2353
|
-
return { pubkey: key, isSigner: true, isWritable: false };
|
|
2354
|
-
});
|
|
2355
|
-
return new web3_js_1.TransactionInstruction({
|
|
2356
|
-
keys,
|
|
2357
|
-
programId: exports$1.MEMO_PROGRAM_ID,
|
|
2358
|
-
data: buffer_1.Buffer.from(memo, "utf8")
|
|
2359
|
-
});
|
|
2360
|
-
}
|
|
2361
|
-
}
|
|
2362
|
-
});
|
|
2363
|
-
|
|
2364
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/priority.js
|
|
2365
|
-
var require_priority = __commonJS({
|
|
2366
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/priority.js"(exports$1) {
|
|
2367
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
2368
|
-
exports$1.getRecentPrioritizationFeesByPercentile = exports$1.getMedianPrioritizationFeeByPercentile = exports$1.getMeanPrioritizationFeeByPercentile = exports$1.getMaxPrioritizationFeeByPercentile = exports$1.getMinPrioritizationFeeByPercentile = exports$1.getCalculatedPrioritizationFeeByPercentile = exports$1.PriotitizationFeeLevels = void 0;
|
|
2369
|
-
var PriotitizationFeeLevels;
|
|
2370
|
-
(function(PriotitizationFeeLevels2) {
|
|
2371
|
-
PriotitizationFeeLevels2[PriotitizationFeeLevels2["LOW"] = 2500] = "LOW";
|
|
2372
|
-
PriotitizationFeeLevels2[PriotitizationFeeLevels2["MEDIAN"] = 5e3] = "MEDIAN";
|
|
2373
|
-
PriotitizationFeeLevels2[PriotitizationFeeLevels2["HIGH"] = 7500] = "HIGH";
|
|
2374
|
-
PriotitizationFeeLevels2[PriotitizationFeeLevels2["MAX"] = 1e4] = "MAX";
|
|
2375
|
-
})(PriotitizationFeeLevels || (exports$1.PriotitizationFeeLevels = PriotitizationFeeLevels = {}));
|
|
2376
|
-
var getCalculatedPrioritizationFeeByPercentile = async (connection, config, slotsToReturn) => {
|
|
2377
|
-
const fees = await (0, exports$1.getRecentPrioritizationFeesByPercentile)(connection, config, slotsToReturn);
|
|
2378
|
-
const { min, max, sum } = fees.reduce((acc, fee) => ({
|
|
2379
|
-
min: fee.prioritizationFee < acc.min.prioritizationFee ? fee : acc.min,
|
|
2380
|
-
max: fee.prioritizationFee > acc.max.prioritizationFee ? fee : acc.max,
|
|
2381
|
-
sum: acc.sum + fee.prioritizationFee
|
|
2382
|
-
}), { min: fees[0], max: fees[0], sum: 0 });
|
|
2383
|
-
const mean = Math.ceil(sum / fees.length);
|
|
2384
|
-
const sortedFees = [...fees].sort((a, b) => a.prioritizationFee - b.prioritizationFee);
|
|
2385
|
-
const midIndex = Math.floor(fees.length / 2);
|
|
2386
|
-
const median = fees.length % 2 === 0 ? Math.ceil((sortedFees[midIndex - 1].prioritizationFee + sortedFees[midIndex].prioritizationFee) / 2) : sortedFees[midIndex].prioritizationFee;
|
|
2387
|
-
return {
|
|
2388
|
-
min,
|
|
2389
|
-
max,
|
|
2390
|
-
mean,
|
|
2391
|
-
median
|
|
2392
|
-
};
|
|
2393
|
-
};
|
|
2394
|
-
exports$1.getCalculatedPrioritizationFeeByPercentile = getCalculatedPrioritizationFeeByPercentile;
|
|
2395
|
-
var getMinPrioritizationFeeByPercentile = async (connection, config, slotsToReturn) => {
|
|
2396
|
-
const recentPrioritizationFees = await (0, exports$1.getRecentPrioritizationFeesByPercentile)(connection, config, slotsToReturn);
|
|
2397
|
-
const minPriorityFee = recentPrioritizationFees.reduce((min, current) => {
|
|
2398
|
-
return current.prioritizationFee < min.prioritizationFee ? current : min;
|
|
2399
|
-
});
|
|
2400
|
-
return minPriorityFee.prioritizationFee;
|
|
2401
|
-
};
|
|
2402
|
-
exports$1.getMinPrioritizationFeeByPercentile = getMinPrioritizationFeeByPercentile;
|
|
2403
|
-
var getMaxPrioritizationFeeByPercentile = async (connection, config, slotsToReturn) => {
|
|
2404
|
-
const recentPrioritizationFees = await (0, exports$1.getRecentPrioritizationFeesByPercentile)(connection, config, slotsToReturn);
|
|
2405
|
-
const maxPriorityFee = recentPrioritizationFees.reduce((max, current) => {
|
|
2406
|
-
return current.prioritizationFee > max.prioritizationFee ? current : max;
|
|
2407
|
-
});
|
|
2408
|
-
return maxPriorityFee.prioritizationFee;
|
|
2409
|
-
};
|
|
2410
|
-
exports$1.getMaxPrioritizationFeeByPercentile = getMaxPrioritizationFeeByPercentile;
|
|
2411
|
-
var getMeanPrioritizationFeeByPercentile = async (connection, config, slotsToReturn) => {
|
|
2412
|
-
const recentPrioritizationFees = await (0, exports$1.getRecentPrioritizationFeesByPercentile)(connection, config, slotsToReturn);
|
|
2413
|
-
const mean = Math.ceil(recentPrioritizationFees.reduce((acc, fee) => acc + fee.prioritizationFee, 0) / recentPrioritizationFees.length);
|
|
2414
|
-
return mean;
|
|
2415
|
-
};
|
|
2416
|
-
exports$1.getMeanPrioritizationFeeByPercentile = getMeanPrioritizationFeeByPercentile;
|
|
2417
|
-
var getMedianPrioritizationFeeByPercentile = async (connection, config, slotsToReturn) => {
|
|
2418
|
-
const recentPrioritizationFees = await (0, exports$1.getRecentPrioritizationFeesByPercentile)(connection, config, slotsToReturn);
|
|
2419
|
-
recentPrioritizationFees.sort((a, b) => a.prioritizationFee - b.prioritizationFee);
|
|
2420
|
-
const half = Math.floor(recentPrioritizationFees.length / 2);
|
|
2421
|
-
if (recentPrioritizationFees.length % 2) {
|
|
2422
|
-
return recentPrioritizationFees[half].prioritizationFee;
|
|
2423
|
-
}
|
|
2424
|
-
return Math.ceil((recentPrioritizationFees[half - 1].prioritizationFee + recentPrioritizationFees[half].prioritizationFee) / 2);
|
|
2425
|
-
};
|
|
2426
|
-
exports$1.getMedianPrioritizationFeeByPercentile = getMedianPrioritizationFeeByPercentile;
|
|
2427
|
-
var getRecentPrioritizationFeesFromRpc = async (config, rpcRequest) => {
|
|
2428
|
-
const accounts = config?.lockedWritableAccounts?.map((key) => key.toBase58());
|
|
2429
|
-
const args = accounts?.length ? [accounts] : [[]];
|
|
2430
|
-
config.percentile && args.push({ percentile: config.percentile });
|
|
2431
|
-
const response = await rpcRequest("getRecentPrioritizationFees", args);
|
|
2432
|
-
return response;
|
|
2433
|
-
};
|
|
2434
|
-
var getRecentPrioritizationFeesByPercentile = async (connection, config, slotsToReturn) => {
|
|
2435
|
-
const { fallback = true, lockedWritableAccounts = [] } = config || {};
|
|
2436
|
-
slotsToReturn = slotsToReturn && Number.isInteger(slotsToReturn) ? slotsToReturn : -1;
|
|
2437
|
-
const promises = [];
|
|
2438
|
-
let tritonRpcResponse = void 0;
|
|
2439
|
-
let fallbackRpcResponse = void 0;
|
|
2440
|
-
const rpcRequest = connection._rpcRequest;
|
|
2441
|
-
promises.push(getRecentPrioritizationFeesFromRpc(config, rpcRequest).then((result) => {
|
|
2442
|
-
tritonRpcResponse = result;
|
|
2443
|
-
}));
|
|
2444
|
-
if (fallback) {
|
|
2445
|
-
promises.push(getRecentPrioritizationFeesFromRpc({ lockedWritableAccounts }, rpcRequest).then((result) => {
|
|
2446
|
-
fallbackRpcResponse = result;
|
|
2447
|
-
}));
|
|
2448
|
-
}
|
|
2449
|
-
await Promise.all(promises);
|
|
2450
|
-
const tritonGRPFResponse = tritonRpcResponse;
|
|
2451
|
-
const fallbackGRPFResponse = fallbackRpcResponse;
|
|
2452
|
-
let recentPrioritizationFees = [];
|
|
2453
|
-
if (tritonGRPFResponse?.result) {
|
|
2454
|
-
recentPrioritizationFees = tritonGRPFResponse.result;
|
|
2455
|
-
}
|
|
2456
|
-
if (fallbackGRPFResponse?.result && !tritonGRPFResponse?.result) {
|
|
2457
|
-
recentPrioritizationFees = fallbackGRPFResponse.result;
|
|
2458
|
-
}
|
|
2459
|
-
if (fallback && fallbackGRPFResponse.error) {
|
|
2460
|
-
return fallbackGRPFResponse.error;
|
|
2461
|
-
}
|
|
2462
|
-
if (tritonGRPFResponse?.error) {
|
|
2463
|
-
return tritonGRPFResponse.error;
|
|
2464
|
-
}
|
|
2465
|
-
recentPrioritizationFees.sort((a, b) => a.slot - b.slot);
|
|
2466
|
-
if (slotsToReturn > 0)
|
|
2467
|
-
return recentPrioritizationFees.slice(0, slotsToReturn);
|
|
2468
|
-
return recentPrioritizationFees;
|
|
2469
|
-
};
|
|
2470
|
-
exports$1.getRecentPrioritizationFeesByPercentile = getRecentPrioritizationFeesByPercentile;
|
|
2471
|
-
}
|
|
2472
|
-
});
|
|
2473
|
-
|
|
2474
|
-
// node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/index.js
|
|
2475
|
-
var require_dist = __commonJS({
|
|
2476
|
-
"node_modules/.pnpm/@mrgnlabs+mrgn-common@2.0.5_bufferutil@4.1.0_typescript@5.9.3_utf-8-validate@5.0.10/node_modules/@mrgnlabs/mrgn-common/dist/index.js"(exports$1) {
|
|
2477
|
-
var __createBinding = exports$1 && exports$1.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
2478
|
-
if (k2 === void 0) k2 = k;
|
|
2479
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
2480
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
2481
|
-
desc = { enumerable: true, get: function() {
|
|
2482
|
-
return m[k];
|
|
2483
|
-
} };
|
|
2484
|
-
}
|
|
2485
|
-
Object.defineProperty(o, k2, desc);
|
|
2486
|
-
}) : (function(o, m, k, k2) {
|
|
2487
|
-
if (k2 === void 0) k2 = k;
|
|
2488
|
-
o[k2] = m[k];
|
|
2489
|
-
}));
|
|
2490
|
-
var __exportStar = exports$1 && exports$1.__exportStar || function(m, exports2) {
|
|
2491
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
|
|
2492
|
-
};
|
|
2493
|
-
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
2494
|
-
exports$1.NodeWallet = void 0;
|
|
2495
|
-
var nodeWallet_1 = require_nodeWallet();
|
|
2496
|
-
Object.defineProperty(exports$1, "NodeWallet", { enumerable: true, get: function() {
|
|
2497
|
-
return nodeWallet_1.NodeWallet;
|
|
2498
|
-
} });
|
|
2499
|
-
__exportStar(require_cache(), exports$1);
|
|
2500
|
-
__exportStar(require_types(), exports$1);
|
|
2501
|
-
__exportStar(require_misc(), exports$1);
|
|
2502
|
-
__exportStar(require_math(), exports$1);
|
|
2503
|
-
__exportStar(require_utils(), exports$1);
|
|
2504
|
-
__exportStar(require_modules(), exports$1);
|
|
2505
|
-
__exportStar(require_spl(), exports$1);
|
|
2506
|
-
__exportStar(require_priority(), exports$1);
|
|
2507
|
-
__exportStar(require_constants(), exports$1);
|
|
2508
|
-
}
|
|
2509
|
-
});
|
|
2510
|
-
|
|
2511
13
|
// src/vendor/pyth_legacy/readBig.ts
|
|
2512
14
|
var ERR_BUFFER_OUT_OF_BOUNDS = () => new Error("Attempt to access memory outside buffer bounds");
|
|
2513
15
|
var ERR_INVALID_ARG_TYPE = (name, expected, actual) => new Error(
|
|
@@ -2737,6 +239,9 @@ var SYSVAR_STAKE_HISTORY_ID = new PublicKey(
|
|
|
2737
239
|
new PublicKey(
|
|
2738
240
|
"StakeConfig11111111111111111111111111111111"
|
|
2739
241
|
);
|
|
242
|
+
new PublicKey("So11111111111111111111111111111111111111112");
|
|
243
|
+
new PublicKey("LSTxxxnJzKDFSLr4dUkPcmCf5VyryEqzPLz5j4bpxFp");
|
|
244
|
+
var USDC_MINT = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
|
|
2740
245
|
|
|
2741
246
|
// src/vendor/spl/types/account.types.ts
|
|
2742
247
|
var AccountState = /* @__PURE__ */ ((AccountState2) => {
|
|
@@ -30620,15 +28125,12 @@ function calculateBorrowAPR(bank, delta = ZERO, currentUtilization = null) {
|
|
|
30620
28125
|
}
|
|
30621
28126
|
|
|
30622
28127
|
// src/vendor/drift/utils/rewards.utils.ts
|
|
30623
|
-
var import_mrgn_common = __toESM(require_dist());
|
|
30624
28128
|
async function getDriftRewards(spotMarkets, userStates, connection) {
|
|
30625
28129
|
let missingMarketIndexes = /* @__PURE__ */ new Set();
|
|
30626
|
-
const spotMarketsMap = new Map(
|
|
30627
|
-
spotMarkets.map((market) => [market.marketIndex, market])
|
|
30628
|
-
);
|
|
28130
|
+
const spotMarketsMap = new Map(spotMarkets.map((market) => [market.marketIndex, market]));
|
|
30629
28131
|
const userStatesWithRewards = userStates.map((userState) => {
|
|
30630
28132
|
const spotPositions = userState.driftUser.spotPositions;
|
|
30631
|
-
const isUsdc = userState.marketMint.equals(
|
|
28133
|
+
const isUsdc = userState.marketMint.equals(USDC_MINT);
|
|
30632
28134
|
spotPositions.length;
|
|
30633
28135
|
const rewardIndex = isUsdc ? 1 : 2;
|
|
30634
28136
|
const rewards = spotPositions.slice(rewardIndex).filter((p) => p.marketIndex !== 0);
|
|
@@ -30653,9 +28155,7 @@ async function getDriftRewards(spotMarkets, userStates, connection) {
|
|
|
30653
28155
|
const missingMarketsAccounts = missingMarketKeys.length ? await connection.getMultipleAccountsInfo(missingMarketKeys) : [];
|
|
30654
28156
|
const missingMarketsMap = new Map([
|
|
30655
28157
|
// Include all existing spot markets
|
|
30656
|
-
...spotMarkets.map(
|
|
30657
|
-
(market) => [market.marketIndex, market]
|
|
30658
|
-
),
|
|
28158
|
+
...spotMarkets.map((market) => [market.marketIndex, market]),
|
|
30659
28159
|
// Add newly fetched missing markets
|
|
30660
28160
|
...missingMarketsAccounts.map((account, idx) => {
|
|
30661
28161
|
const marketIndex = missingMarketIndexesArray[idx];
|
|
@@ -30664,18 +28164,13 @@ async function getDriftRewards(spotMarkets, userStates, connection) {
|
|
|
30664
28164
|
return null;
|
|
30665
28165
|
}
|
|
30666
28166
|
if (!account) {
|
|
30667
|
-
console.error(
|
|
30668
|
-
"Missing market account, for ",
|
|
30669
|
-
missingMarketKeys[idx]?.toBase58()
|
|
30670
|
-
);
|
|
28167
|
+
console.error("Missing market account, for ", missingMarketKeys[idx]?.toBase58());
|
|
30671
28168
|
return null;
|
|
30672
28169
|
} else {
|
|
30673
28170
|
const decodedMarket = decodeDriftSpotMarketData(account.data);
|
|
30674
28171
|
return [marketIndex, decodedMarket];
|
|
30675
28172
|
}
|
|
30676
|
-
}).filter(
|
|
30677
|
-
(market) => market !== null
|
|
30678
|
-
)
|
|
28173
|
+
}).filter((market) => market !== null)
|
|
30679
28174
|
]);
|
|
30680
28175
|
const driftRewardsByBank = new Map(
|
|
30681
28176
|
userStatesWithRewards.map((userStateWithRewards) => {
|
|
@@ -30709,15 +28204,11 @@ async function getAllRequiredMarkets(spotMarkets, driftUsers, connection) {
|
|
|
30709
28204
|
const missingMarketIndexes = Array.from(allKeysFlattened).filter(
|
|
30710
28205
|
(index) => !spotMarkets.some((market) => market.marketIndex === index)
|
|
30711
28206
|
);
|
|
30712
|
-
const missingMarketKeys = missingMarketIndexes.map(
|
|
30713
|
-
(index) => deriveDriftSpotMarket(index)[0]
|
|
30714
|
-
);
|
|
28207
|
+
const missingMarketKeys = missingMarketIndexes.map((index) => deriveDriftSpotMarket(index)[0]);
|
|
30715
28208
|
const missingMarketsAccounts = missingMarketKeys.length ? await connection.getMultipleAccountsInfo(missingMarketKeys) : [];
|
|
30716
28209
|
const allMarketsMap = new Map([
|
|
30717
28210
|
// Include all existing spot markets
|
|
30718
|
-
...spotMarkets.map(
|
|
30719
|
-
(market) => [market.marketIndex, market]
|
|
30720
|
-
),
|
|
28211
|
+
...spotMarkets.map((market) => [market.marketIndex, market]),
|
|
30721
28212
|
// Add newly fetched missing markets
|
|
30722
28213
|
...missingMarketsAccounts.map((account, idx) => {
|
|
30723
28214
|
const marketIndex = missingMarketIndexes[idx];
|
|
@@ -30726,18 +28217,13 @@ async function getAllRequiredMarkets(spotMarkets, driftUsers, connection) {
|
|
|
30726
28217
|
return null;
|
|
30727
28218
|
}
|
|
30728
28219
|
if (!account) {
|
|
30729
|
-
console.error(
|
|
30730
|
-
"Missing market account, for ",
|
|
30731
|
-
missingMarketKeys[idx]?.toBase58()
|
|
30732
|
-
);
|
|
28220
|
+
console.error("Missing market account, for ", missingMarketKeys[idx]?.toBase58());
|
|
30733
28221
|
return null;
|
|
30734
28222
|
} else {
|
|
30735
28223
|
const decodedMarket = decodeDriftSpotMarketData(account.data);
|
|
30736
28224
|
return [marketIndex, decodedMarket];
|
|
30737
28225
|
}
|
|
30738
|
-
}).filter(
|
|
30739
|
-
(market) => market !== null
|
|
30740
|
-
)
|
|
28226
|
+
}).filter((market) => market !== null)
|
|
30741
28227
|
]);
|
|
30742
28228
|
return Array.from(allMarketsMap.values());
|
|
30743
28229
|
}
|
|
@@ -30786,17 +28272,6 @@ function makeUpdateSpotMarketIx({ spotMarket }) {
|
|
|
30786
28272
|
spotMarketVault
|
|
30787
28273
|
);
|
|
30788
28274
|
}
|
|
30789
|
-
/*! Bundled license information:
|
|
30790
|
-
|
|
30791
|
-
numeral/numeral.js:
|
|
30792
|
-
(*! @preserve
|
|
30793
|
-
* numeral.js
|
|
30794
|
-
* version : 2.0.6
|
|
30795
|
-
* author : Adam Draper
|
|
30796
|
-
* license : MIT
|
|
30797
|
-
* http://adamwdraper.github.com/Numeral-js/
|
|
30798
|
-
*)
|
|
30799
|
-
*/
|
|
30800
28275
|
|
|
30801
28276
|
export { ACCOUNT_SIZE, ACCOUNT_TYPE_SIZE, ASSOCIATED_TOKEN_PROGRAM_ID, AccountLayout, AccountState, AccountType, CorpAction, DEFAULT_RECENT_SLOT_DURATION_MS, DRIFT_IDL, DRIFT_PROGRAM_ID, DriftSpotBalanceType, ExtensionType, FARMS_PROGRAM_ID, KFARMS_IDL, KLEND_ACCOUNT_CODER, KLEND_IDL, KLEND_PROGRAM_ID, LENGTH_SIZE, MAX_SLOT_DIFFERENCE, MEMO_PROGRAM_ID, MINT_SIZE, MULTISIG_SIZE, MintLayout, MultisigLayout, NATIVE_MINT, ONE, ONE_HUNDRED_PCT_IN_BPS, ONE_YEAR, PERCENTAGE_PRECISION, PERCENTAGE_PRECISION_EXP, PriceStatus, PriceType, REFRESH_OBLIGATION_DISCRIMINATOR, SEED_BASE_REFERRER_STATE, SEED_BASE_REFERRER_TOKEN_STATE, SEED_BASE_SHORT_URL, SEED_BASE_USER_METADATA, SEED_DRIFT_SIGNER, SEED_DRIFT_STATE, SEED_FEE_RECEIVER, SEED_LENDING_MARKET_AUTH, SEED_RESERVE_COLL_MINT, SEED_RESERVE_COLL_SUPPLY, SEED_RESERVE_LIQ_SUPPLY, SEED_SPOT_MARKET, SEED_SPOT_MARKET_VAULT, SEED_USER, SEED_USER_STATE, SEED_USER_STATS, SLOTS_PER_DAY, SLOTS_PER_HOUR, SLOTS_PER_MINUTE, SLOTS_PER_SECOND, SLOTS_PER_YEAR, SPOT_MARKET_RATE_PRECISION, SPOT_MARKET_RATE_PRECISION_EXP, SPOT_MARKET_UTILIZATION_PRECISION, SPOT_MARKET_UTILIZATION_PRECISION_EXP, SWITCHBOARD_ONDEMANDE_PRICE_PRECISION, SinglePoolInstruction, SplAccountType, SpotBalanceType, TEN, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, TYPE_SIZE, TokenAccountNotFoundError, TokenError, TokenInstruction, TokenInvalidAccountError, TokenInvalidAccountOwnerError, TokenInvalidAccountSizeError, TokenInvalidInstructionDataError, TokenInvalidInstructionKeysError, TokenInvalidInstructionProgramError, TokenInvalidInstructionTypeError, TokenInvalidMintError, TokenInvalidOwnerError, TokenOwnerOffCurveError, TokenUnsupportedInstructionError, ZERO, addSigners, calculateAPYFromAPR, calculateBorrowAPR, calculateBorrowAPY, calculateBorrowRate, calculateDepositRate, calculateEstimatedBorrowRate, calculateEstimatedSupplyRate, calculateInterestRate, calculateLendingAPR, calculateLendingAPY, calculateRewardApy, calculateSlotAdjustmentFactor, calculateSupplyAPY, calculateUtilization, calculateUtilizationRatio, closeAccountInstructionData, createAccountIx, createAssociatedTokenAccountIdempotentInstruction, createAssociatedTokenAccountInstruction, createCloseAccountInstruction, createInitializeAccountInstruction, createMemoInstruction, createPoolOnrampIx, createSyncNativeInstruction, createTransferCheckedInstruction, decodeDriftSpotMarketData, decodeDriftStateData, decodeDriftUserData, decodeDriftUserStatsData, decodeFarmDataRaw, decodeKlendObligationData, decodeKlendReserveData, decodeSwitchboardPullFeedData, deriveBaseObligation, deriveDriftSigner, deriveDriftSpotMarket, deriveDriftSpotMarketVault, deriveDriftState, deriveDriftUser, deriveDriftUserStats, deriveFeeReceiver, deriveLendingMarketAuthority, deriveObligation, deriveReferrerState, deriveReferrerTokenState, deriveReserveCollateralMint, deriveReserveCollateralSupply, deriveReserveLiquiditySupply, deriveShortUrl, deriveUserMetadata, deriveUserState, driftRewardsRawToDto, driftSpotMarketRawToDto, driftStateRawToDto, driftUserRawToDto, driftUserStatsRawToDto, dtoToDriftRewardsRaw, dtoToDriftSpotMarketRaw, dtoToDriftStateRaw, dtoToDriftUserRaw, dtoToDriftUserStatsRaw, dtoToFarmRaw, dtoToObligationRaw, dtoToReserveRaw, farmRawToDto, findMplMetadataAddress, findPoolAddress, findPoolMintAddress, findPoolMintAddressByVoteAccount, findPoolMintAuthorityAddress, findPoolMplAuthorityAddress, findPoolOnRampAddress, findPoolStakeAddress, findPoolStakeAuthorityAddress, generateKaminoReserveCurve, getAccount, getAccountLen, getAllDerivedDriftAccounts, getAllDerivedKaminoAccounts, getAllRequiredMarkets, getAssociatedTokenAddressSync, getBorrowRate, getDriftRewards, getFixedHostInterestRate, getMinimumBalanceForRentExemptAccount, getMinimumBalanceForRentExemptAccountWithExtensions, getMint, getMultipleAccounts, getProtocolTakeRatePct, getReserveRewardsApy, getRewardPerTimeUnitSecond, getStakeAccount, getSwitchboardProgram, getTokenAmount, getTotalSupply, initializeAccountInstructionData, initializeStakedPoolIxs, initializeStakedPoolTx, interpolateLinear, isSpotBalanceTypeVariant, layout, makeRefreshObligationIx, makeRefreshReservesBatchIx, makeRefreshingIxs, makeUpdateSpotMarketCumulativeInterestIx, makeUpdateSpotMarketIx, obligationRawToDto, parsePriceData, parsePriceInfo2 as parsePriceInfo, replenishPoolIx, reserveRawToDto, scaledSupplies, slotAdjustmentFactor, switchboardAccountCoder, syncNativeInstructionData, transferCheckedInstructionData, truncateBorrowCurve, unpackAccount };
|
|
30802
28277
|
//# sourceMappingURL=vendor.js.map
|