@proton/wrap-constants 0.2.71 → 0.2.72
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/index.d.ts +8868 -6
- package/dist/index.js +3728 -5
- package/dist/index.mjs +3602 -0
- package/package.json +6 -12
- package/dist/coins.d.ts +0 -121
- package/dist/constants.d.ts +0 -63
- package/dist/graph.d.ts +0 -30
- package/dist/math.d.ts +0 -17
- package/dist/parsers/actions.d.ts +0 -1323
- package/dist/parsers/address.d.ts +0 -932
- package/dist/parsers/auth.d.ts +0 -1816
- package/dist/parsers/base.d.ts +0 -35
- package/dist/parsers/currency.d.ts +0 -236
- package/dist/parsers/deposit.d.ts +0 -66
- package/dist/parsers/dex.d.ts +0 -1516
- package/dist/parsers/index.d.ts +0 -13
- package/dist/parsers/login.d.ts +0 -892
- package/dist/parsers/otc.d.ts +0 -46
- package/dist/parsers/pool.d.ts +0 -52
- package/dist/parsers/withdraw.d.ts +0 -1053
- package/dist/parsers/withdrawalHistory.d.ts +0 -98
- package/dist/parsers/wrap.d.ts +0 -109
- package/dist/utils.d.ts +0 -8
- package/dist/wrap-constants.cjs.development.js +0 -2228
- package/dist/wrap-constants.cjs.development.js.map +0 -1
- package/dist/wrap-constants.cjs.production.min.js +0 -2
- package/dist/wrap-constants.cjs.production.min.js.map +0 -1
- package/dist/wrap-constants.esm.js +0 -2162
- package/dist/wrap-constants.esm.js.map +0 -1
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,3602 @@
|
|
|
1
|
+
// src/coins.ts
|
|
2
|
+
var Chains = /* @__PURE__ */ ((Chains2) => {
|
|
3
|
+
Chains2["BitcoinMainnet"] = "Bitcoin";
|
|
4
|
+
Chains2["BitcoinTestnet"] = "Bitcoin (Testnet)";
|
|
5
|
+
Chains2["EthereumMainnet"] = "Ethereum";
|
|
6
|
+
Chains2["EthereumRopsten"] = "Ethereum (Ropsten)";
|
|
7
|
+
Chains2["LitecoinMainnet"] = "Litecoin";
|
|
8
|
+
Chains2["LitecoinTestnet"] = "Litecoin (Testnet)";
|
|
9
|
+
Chains2["BitcoinCashMainnet"] = "Bitcoin Cash";
|
|
10
|
+
Chains2["BitcoinCashTestnet"] = "Bitcoin Cash (Testnet)";
|
|
11
|
+
Chains2["StellarMainnet"] = "Stellar";
|
|
12
|
+
Chains2["StellarTestnet"] = "Stellar (Testnet)";
|
|
13
|
+
Chains2["ProtonMainnet"] = "Proton";
|
|
14
|
+
Chains2["ProtonTestnet"] = "Proton (Testnet)";
|
|
15
|
+
Chains2["PolkadotMainnet"] = "Polkadot";
|
|
16
|
+
Chains2["BinanceBEP2"] = "Binance (BEP2)";
|
|
17
|
+
Chains2["BinanceBEP20"] = "Binance (BEP20)";
|
|
18
|
+
Chains2["EosMainnet"] = "EOS";
|
|
19
|
+
Chains2["EosTestnet"] = "EOS (Jungle Testnet)";
|
|
20
|
+
Chains2["HederaMainnet"] = "Hedera (Mainnet)";
|
|
21
|
+
Chains2["HederaTestnet"] = "Hedera (Testnet)";
|
|
22
|
+
Chains2["DogeMainnet"] = "Dogecoin";
|
|
23
|
+
Chains2["CardanoMainnet"] = "Cardano";
|
|
24
|
+
Chains2["AvalancheXChain"] = "Avalanche X-Chain";
|
|
25
|
+
Chains2["AvalancheCChain"] = "Avalanche C-Chain";
|
|
26
|
+
Chains2["PolygonMainnet"] = "Polygon";
|
|
27
|
+
Chains2["TerraMainnet"] = "Terra";
|
|
28
|
+
Chains2["RippleMainnet"] = "Ripple";
|
|
29
|
+
Chains2["SolanaMainnet"] = "Solana";
|
|
30
|
+
Chains2["XDCMainnet"] = "XDC Network";
|
|
31
|
+
Chains2["MetalXTestnet"] = "Metal X-Chain (Testnet)";
|
|
32
|
+
Chains2["MetalCTestnet"] = "Metal C-Chain (Testnet)";
|
|
33
|
+
Chains2["MetalCMainnet"] = "Metal C-Chain";
|
|
34
|
+
return Chains2;
|
|
35
|
+
})(Chains || {});
|
|
36
|
+
var Networks = /* @__PURE__ */ ((Networks2) => {
|
|
37
|
+
Networks2["Mainnet"] = "mainnet";
|
|
38
|
+
Networks2["Testnet"] = "testnet";
|
|
39
|
+
Networks2["Ropsten"] = "ropsten";
|
|
40
|
+
Networks2["ERC20"] = "erc20";
|
|
41
|
+
Networks2["BEP20"] = "bep20";
|
|
42
|
+
Networks2["XLM"] = "xlm";
|
|
43
|
+
Networks2["AVM"] = "avm";
|
|
44
|
+
Networks2["EVM"] = "evm";
|
|
45
|
+
return Networks2;
|
|
46
|
+
})(Networks || {});
|
|
47
|
+
var similarChains = {
|
|
48
|
+
["Ethereum" /* EthereumMainnet */]: ["Binance (BEP20)" /* BinanceBEP20 */],
|
|
49
|
+
["Binance (BEP20)" /* BinanceBEP20 */]: ["Ethereum" /* EthereumMainnet */]
|
|
50
|
+
};
|
|
51
|
+
var Providers = /* @__PURE__ */ ((Providers2) => {
|
|
52
|
+
Providers2["FIREBLOCKS"] = "fireblocks";
|
|
53
|
+
Providers2["METAL"] = "metal";
|
|
54
|
+
return Providers2;
|
|
55
|
+
})(Providers || {});
|
|
56
|
+
var explorerLinkByChain = {
|
|
57
|
+
["Bitcoin" /* BitcoinMainnet */]: (txid) => `https://blockchain.com/btc/tx/${txid}`,
|
|
58
|
+
["Bitcoin (Testnet)" /* BitcoinTestnet */]: (txid) => `https://blockstream.info/testnet/tx/${txid}`,
|
|
59
|
+
["Ethereum" /* EthereumMainnet */]: (txid) => `https://etherscan.io/tx/${txid}`,
|
|
60
|
+
["Ethereum (Ropsten)" /* EthereumRopsten */]: (txid) => `https://ropsten.etherscan.io/tx/${txid}`,
|
|
61
|
+
["Litecoin" /* LitecoinMainnet */]: (txid) => `https://blockchair.com/litecoin/transaction/${txid}`,
|
|
62
|
+
["Litecoin (Testnet)" /* LitecoinTestnet */]: (txid) => `https://blockexplorer.one/litecoin/testnet/blockHash/${txid}`,
|
|
63
|
+
["Bitcoin Cash" /* BitcoinCashMainnet */]: (txid) => `https://blockchair.com/bitcoin-cash/transaction/${txid}`,
|
|
64
|
+
["Bitcoin Cash (Testnet)" /* BitcoinCashTestnet */]: (txid) => `https://blockexplorer.one/bitcoin-cash/testnet/blockHash/${txid}`,
|
|
65
|
+
["Stellar" /* StellarMainnet */]: (txid) => `https://blockchair.com/stellar/transaction/${txid}`,
|
|
66
|
+
["Stellar (Testnet)" /* StellarTestnet */]: (txid) => `https://testnet.steexp.com/tx/${txid}`,
|
|
67
|
+
["Proton" /* ProtonMainnet */]: (txid, traces) => `https://proton.bloks.io/transaction/${txid}${traces ? "?tab=traces" : ""}`,
|
|
68
|
+
["Proton (Testnet)" /* ProtonTestnet */]: (txid, traces) => `https://proton-test.bloks.io/transaction/${txid}${traces ? "?tab=traces" : ""}`,
|
|
69
|
+
["Polkadot" /* PolkadotMainnet */]: (txid) => `https://polkadot.subscan.io/extrinsic/${txid}`,
|
|
70
|
+
["Binance (BEP2)" /* BinanceBEP2 */]: (txid) => `https://binance.mintscan.io/txs/${txid}`,
|
|
71
|
+
["Binance (BEP20)" /* BinanceBEP20 */]: (txid) => `https://bscscan.com/tx/${txid}`,
|
|
72
|
+
["EOS" /* EosMainnet */]: (txid) => `https://bloks.io/transaction/${txid}`,
|
|
73
|
+
["EOS (Jungle Testnet)" /* EosTestnet */]: (txid) => `https://jungle.bloks.io/transaction/${txid}`,
|
|
74
|
+
["Hedera (Mainnet)" /* HederaMainnet */]: (txid) => `https://app.dragonglass.me/transactions/${txid}`,
|
|
75
|
+
["Hedera (Testnet)" /* HederaTestnet */]: (txid) => `https://testnet.dragonglass.me/transactions/${txid}`,
|
|
76
|
+
["Dogecoin" /* DogeMainnet */]: (txid) => `https://blockchair.com/dogecoin/transaction/${txid}`,
|
|
77
|
+
["Cardano" /* CardanoMainnet */]: (txid) => `https://explorer.cardano.org/en/transaction?id=${txid}`,
|
|
78
|
+
["Avalanche X-Chain" /* AvalancheXChain */]: (txid) => `https://avascan.info/blockchain/x/tx/${txid}`,
|
|
79
|
+
["Avalanche C-Chain" /* AvalancheCChain */]: (txid) => `https://snowtrace.io/tx/${txid}`,
|
|
80
|
+
["Polygon" /* PolygonMainnet */]: (txid) => `https://polygonscan.com/tx/${txid}`,
|
|
81
|
+
["Terra" /* TerraMainnet */]: (txid) => `https://terra.stake.id/?#/tx/${txid}`,
|
|
82
|
+
["Ripple" /* RippleMainnet */]: (txid) => `https://xrpscan.com/tx/${txid}`,
|
|
83
|
+
["Solana" /* SolanaMainnet */]: (txid) => `https://explorer.solana.com/tx/${txid}`,
|
|
84
|
+
["Metal X-Chain (Testnet)" /* MetalXTestnet */]: (txid) => `https://metalscan.io/tx/${txid}`,
|
|
85
|
+
["Metal C-Chain (Testnet)" /* MetalCTestnet */]: (txid) => `https://tahoe.metaltrace.io/tx/${txid}`,
|
|
86
|
+
["Metal C-Chain" /* MetalCMainnet */]: (txid) => `https://metalscan.io/tx/${txid}`,
|
|
87
|
+
["XDC Network" /* XDCMainnet */]: (txid) => `https://xdc.blocksscan.io/txs/${txid}`
|
|
88
|
+
};
|
|
89
|
+
var protonExplorerTxUrl = (chain, txId, traces) => chain === "proton" ? explorerLinkByChain["Proton" /* ProtonMainnet */](txId, traces) : explorerLinkByChain["Proton (Testnet)" /* ProtonTestnet */](txId, traces);
|
|
90
|
+
var initializeCoins = (protonChain) => {
|
|
91
|
+
const IS_MAINNET = protonChain === "proton";
|
|
92
|
+
const IS_TESTNET = protonChain === "proton-test";
|
|
93
|
+
const coins = [
|
|
94
|
+
{
|
|
95
|
+
allowSwap: true,
|
|
96
|
+
allowBridge: IS_MAINNET,
|
|
97
|
+
allowLend: true,
|
|
98
|
+
allowBorrow: true,
|
|
99
|
+
name: "Proton",
|
|
100
|
+
coin: "XPR",
|
|
101
|
+
xtokenSymbol: "XPR",
|
|
102
|
+
xtokenPrecision: 4,
|
|
103
|
+
xtokenContract: "eosio.token",
|
|
104
|
+
wallets: [
|
|
105
|
+
...IS_MAINNET ? [
|
|
106
|
+
{
|
|
107
|
+
wallet: "XPR-ERC20",
|
|
108
|
+
symbol: "XPR",
|
|
109
|
+
chain: "Ethereum" /* EthereumMainnet */,
|
|
110
|
+
network: "erc20" /* ERC20 */,
|
|
111
|
+
precision: 4,
|
|
112
|
+
contract: "0xD7EFB00D12C2C13131FD319336FDF952525DA2AF",
|
|
113
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
114
|
+
hasWithdrawMemo: false
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
wallet: "XPR-BEP20",
|
|
118
|
+
symbol: "XPR",
|
|
119
|
+
chain: "Binance (BEP20)" /* BinanceBEP20 */,
|
|
120
|
+
network: "bep20" /* BEP20 */,
|
|
121
|
+
precision: 4,
|
|
122
|
+
contract: "0x5DE3939B2F811A61D830E6F52D13B066881412AB",
|
|
123
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
124
|
+
hasWithdrawMemo: false
|
|
125
|
+
}
|
|
126
|
+
] : []
|
|
127
|
+
],
|
|
128
|
+
image: "https://www.proton.org/images/tokens/eosio-tokenXPR.png",
|
|
129
|
+
coingeckoId: "proton"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
allowSwap: true,
|
|
133
|
+
allowBridge: true,
|
|
134
|
+
allowLend: true,
|
|
135
|
+
allowBorrow: true,
|
|
136
|
+
name: "USD Coin",
|
|
137
|
+
coin: "USDC",
|
|
138
|
+
xtokenSymbol: "XUSDC",
|
|
139
|
+
xtokenPrecision: 6,
|
|
140
|
+
xtokenContract: "xtokens",
|
|
141
|
+
wallets: [
|
|
142
|
+
...IS_MAINNET ? [
|
|
143
|
+
{
|
|
144
|
+
wallet: "USDC",
|
|
145
|
+
symbol: "USDC",
|
|
146
|
+
chain: "Ethereum" /* EthereumMainnet */,
|
|
147
|
+
network: "erc20" /* ERC20 */,
|
|
148
|
+
precision: 6,
|
|
149
|
+
contract: "0xA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48",
|
|
150
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
151
|
+
hasWithdrawMemo: false
|
|
152
|
+
},
|
|
153
|
+
// {
|
|
154
|
+
// wallet: 'USDC-BEP20',
|
|
155
|
+
// symbol: 'USDC',
|
|
156
|
+
// chain: Chains.BinanceBEP20,
|
|
157
|
+
// network: Networks.BEP20,
|
|
158
|
+
// precision: 18,
|
|
159
|
+
// contract: '0x8AC76A51CC950D9822D68B83FE1AD97B32CD580D',
|
|
160
|
+
// provider: Providers.FIREBLOCKS,
|
|
161
|
+
// hasWithdrawMemo: false
|
|
162
|
+
// },
|
|
163
|
+
{
|
|
164
|
+
wallet: "USDC-XLM",
|
|
165
|
+
symbol: "USDC",
|
|
166
|
+
chain: "Stellar" /* StellarMainnet */,
|
|
167
|
+
network: "xlm" /* XLM */,
|
|
168
|
+
precision: 7,
|
|
169
|
+
contract: void 0,
|
|
170
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
171
|
+
hasWithdrawMemo: true
|
|
172
|
+
}
|
|
173
|
+
] : [],
|
|
174
|
+
...IS_TESTNET ? [
|
|
175
|
+
{
|
|
176
|
+
wallet: "USDC",
|
|
177
|
+
symbol: "USDC",
|
|
178
|
+
chain: "Ethereum (Ropsten)" /* EthereumRopsten */,
|
|
179
|
+
network: "ropsten" /* Ropsten */,
|
|
180
|
+
precision: 6,
|
|
181
|
+
contract: "0xA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48",
|
|
182
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
183
|
+
hasWithdrawMemo: false
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
wallet: "USDC-XLM",
|
|
187
|
+
symbol: "USDC",
|
|
188
|
+
chain: "Stellar (Testnet)" /* StellarTestnet */,
|
|
189
|
+
network: "xlm" /* XLM */,
|
|
190
|
+
precision: 7,
|
|
191
|
+
contract: void 0,
|
|
192
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
193
|
+
hasWithdrawMemo: true
|
|
194
|
+
}
|
|
195
|
+
] : []
|
|
196
|
+
],
|
|
197
|
+
image: "https://www.proton.org/images/tokens/xtokensXUSDC.png",
|
|
198
|
+
coingeckoId: "usd-coin"
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
allowSwap: true,
|
|
202
|
+
allowBridge: IS_MAINNET,
|
|
203
|
+
allowLend: true,
|
|
204
|
+
allowBorrow: true,
|
|
205
|
+
name: "Metal DAO",
|
|
206
|
+
coin: "MTL",
|
|
207
|
+
xtokenSymbol: "XMT",
|
|
208
|
+
xtokenPrecision: 8,
|
|
209
|
+
xtokenContract: "xtokens",
|
|
210
|
+
wallets: [
|
|
211
|
+
...IS_MAINNET ? [{
|
|
212
|
+
wallet: "MTL",
|
|
213
|
+
symbol: "MTL",
|
|
214
|
+
chain: "Ethereum" /* EthereumMainnet */,
|
|
215
|
+
network: "erc20" /* ERC20 */,
|
|
216
|
+
precision: 8,
|
|
217
|
+
contract: "0xF433089366899D83A9F26A773D59EC7ECF30355E",
|
|
218
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
219
|
+
hasWithdrawMemo: false
|
|
220
|
+
}] : []
|
|
221
|
+
],
|
|
222
|
+
image: "https://www.proton.org/images/tokens/xtokensXMT.png",
|
|
223
|
+
coingeckoId: "metal"
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
allowSwap: true,
|
|
227
|
+
allowBridge: true,
|
|
228
|
+
allowLend: false,
|
|
229
|
+
allowBorrow: false,
|
|
230
|
+
name: "Metal Blockchain",
|
|
231
|
+
coin: "METAL",
|
|
232
|
+
xtokenSymbol: "METAL",
|
|
233
|
+
xtokenPrecision: 8,
|
|
234
|
+
xtokenContract: "xtokens",
|
|
235
|
+
wallets: [
|
|
236
|
+
...IS_TESTNET ? [{
|
|
237
|
+
wallet: "METAL",
|
|
238
|
+
symbol: "METAL",
|
|
239
|
+
chain: "Metal C-Chain (Testnet)" /* MetalCTestnet */,
|
|
240
|
+
network: "evm" /* EVM */,
|
|
241
|
+
precision: 18,
|
|
242
|
+
contract: "",
|
|
243
|
+
provider: "metal" /* METAL */,
|
|
244
|
+
hasWithdrawMemo: false
|
|
245
|
+
}] : [],
|
|
246
|
+
...IS_MAINNET ? [
|
|
247
|
+
{
|
|
248
|
+
wallet: "METAL",
|
|
249
|
+
symbol: "METAL",
|
|
250
|
+
chain: "Metal C-Chain" /* MetalCMainnet */,
|
|
251
|
+
network: "evm" /* EVM */,
|
|
252
|
+
precision: 18,
|
|
253
|
+
contract: "",
|
|
254
|
+
provider: "metal" /* METAL */,
|
|
255
|
+
hasWithdrawMemo: false
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
wallet: "METAL",
|
|
259
|
+
symbol: "METAL",
|
|
260
|
+
chain: "Ethereum" /* EthereumMainnet */,
|
|
261
|
+
network: "erc20" /* ERC20 */,
|
|
262
|
+
precision: 18,
|
|
263
|
+
contract: "",
|
|
264
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
265
|
+
hasWithdrawMemo: false
|
|
266
|
+
}
|
|
267
|
+
] : []
|
|
268
|
+
],
|
|
269
|
+
image: "https://raw.githubusercontent.com/eoscafe/eos-airdrops/master/logos/metal-chain.png",
|
|
270
|
+
coingeckoId: "metal-blockchain"
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
allowSwap: true,
|
|
274
|
+
allowBridge: true,
|
|
275
|
+
allowLend: true,
|
|
276
|
+
allowBorrow: true,
|
|
277
|
+
name: "Bitcoin",
|
|
278
|
+
coin: "BTC",
|
|
279
|
+
xtokenSymbol: "XBTC",
|
|
280
|
+
xtokenPrecision: 8,
|
|
281
|
+
xtokenContract: "xtokens",
|
|
282
|
+
wallets: [
|
|
283
|
+
...IS_MAINNET ? [{
|
|
284
|
+
wallet: "BTC",
|
|
285
|
+
symbol: "BTC",
|
|
286
|
+
chain: "Bitcoin" /* BitcoinMainnet */,
|
|
287
|
+
network: "mainnet" /* Mainnet */,
|
|
288
|
+
precision: 8,
|
|
289
|
+
contract: void 0,
|
|
290
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
291
|
+
hasWithdrawMemo: false
|
|
292
|
+
}] : [],
|
|
293
|
+
...IS_TESTNET ? [{
|
|
294
|
+
wallet: "BTC",
|
|
295
|
+
symbol: "BTC",
|
|
296
|
+
chain: "Bitcoin (Testnet)" /* BitcoinTestnet */,
|
|
297
|
+
network: "testnet" /* Testnet */,
|
|
298
|
+
precision: 8,
|
|
299
|
+
contract: void 0,
|
|
300
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
301
|
+
hasWithdrawMemo: false
|
|
302
|
+
}] : []
|
|
303
|
+
],
|
|
304
|
+
image: "https://www.proton.org/images/tokens/xtokensXBTC.png",
|
|
305
|
+
coingeckoId: "bitcoin"
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
allowSwap: true,
|
|
309
|
+
allowBridge: true,
|
|
310
|
+
allowLend: true,
|
|
311
|
+
allowBorrow: true,
|
|
312
|
+
name: "Ethereum",
|
|
313
|
+
coin: "ETH",
|
|
314
|
+
xtokenSymbol: "XETH",
|
|
315
|
+
xtokenPrecision: 8,
|
|
316
|
+
xtokenContract: "xtokens",
|
|
317
|
+
wallets: [
|
|
318
|
+
...IS_MAINNET ? [{
|
|
319
|
+
wallet: "ETH",
|
|
320
|
+
symbol: "ETH",
|
|
321
|
+
chain: "Ethereum" /* EthereumMainnet */,
|
|
322
|
+
network: "mainnet" /* Mainnet */,
|
|
323
|
+
precision: 18,
|
|
324
|
+
contract: "0x0000000000000000000000000000000000000000",
|
|
325
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
326
|
+
hasWithdrawMemo: false
|
|
327
|
+
}] : [],
|
|
328
|
+
...IS_TESTNET ? [{
|
|
329
|
+
wallet: "ETH",
|
|
330
|
+
symbol: "ETH",
|
|
331
|
+
chain: "Ethereum (Ropsten)" /* EthereumRopsten */,
|
|
332
|
+
network: "ropsten" /* Ropsten */,
|
|
333
|
+
precision: 18,
|
|
334
|
+
contract: "0x0000000000000000000000000000000000000000",
|
|
335
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
336
|
+
hasWithdrawMemo: false
|
|
337
|
+
}] : []
|
|
338
|
+
],
|
|
339
|
+
image: "https://www.proton.org/images/tokens/xtokensXETH.png",
|
|
340
|
+
coingeckoId: "ethereum"
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
allowSwap: true,
|
|
344
|
+
allowBridge: false,
|
|
345
|
+
allowLend: false,
|
|
346
|
+
allowBorrow: false,
|
|
347
|
+
name: "Loan",
|
|
348
|
+
coin: "LOAN",
|
|
349
|
+
xtokenSymbol: "LOAN",
|
|
350
|
+
xtokenPrecision: 4,
|
|
351
|
+
xtokenContract: "loan.token",
|
|
352
|
+
wallets: [],
|
|
353
|
+
image: "https://raw.githubusercontent.com/eoscafe/eos-airdrops/master/logos/loan.png",
|
|
354
|
+
coingeckoId: "proton-loan"
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
allowSwap: true,
|
|
358
|
+
allowBridge: true,
|
|
359
|
+
allowLend: false,
|
|
360
|
+
allowBorrow: false,
|
|
361
|
+
name: "Tether",
|
|
362
|
+
coin: "USDT",
|
|
363
|
+
xtokenSymbol: "XUSDT",
|
|
364
|
+
xtokenPrecision: 6,
|
|
365
|
+
xtokenContract: "xtokens",
|
|
366
|
+
wallets: [
|
|
367
|
+
...IS_MAINNET ? [{
|
|
368
|
+
wallet: "USDT",
|
|
369
|
+
symbol: "USDT",
|
|
370
|
+
chain: "Ethereum" /* EthereumMainnet */,
|
|
371
|
+
network: "erc20" /* ERC20 */,
|
|
372
|
+
precision: 6,
|
|
373
|
+
contract: "0xDAC17F958D2EE523A2206206994597C13D831EC7",
|
|
374
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
375
|
+
hasWithdrawMemo: false
|
|
376
|
+
}] : [],
|
|
377
|
+
...IS_MAINNET ? [{
|
|
378
|
+
wallet: "USDT-BEP20",
|
|
379
|
+
symbol: "USDT",
|
|
380
|
+
chain: "Binance (BEP20)" /* BinanceBEP20 */,
|
|
381
|
+
network: "bep20" /* BEP20 */,
|
|
382
|
+
precision: 18,
|
|
383
|
+
contract: "0x55d398326f99059fF775485246999027B3197955",
|
|
384
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
385
|
+
hasWithdrawMemo: false
|
|
386
|
+
}] : [],
|
|
387
|
+
...IS_TESTNET ? [{
|
|
388
|
+
wallet: "USDT",
|
|
389
|
+
symbol: "USDT",
|
|
390
|
+
chain: "Ethereum (Ropsten)" /* EthereumRopsten */,
|
|
391
|
+
network: "ropsten" /* Ropsten */,
|
|
392
|
+
precision: 6,
|
|
393
|
+
contract: "0xDAC17F958D2EE523A2206206994597C13D831EC7",
|
|
394
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
395
|
+
hasWithdrawMemo: false
|
|
396
|
+
}] : []
|
|
397
|
+
],
|
|
398
|
+
image: "https://www.proton.org/images/tokens/xtokensXUSDT.png",
|
|
399
|
+
coingeckoId: "tether"
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
allowSwap: false,
|
|
403
|
+
allowBridge: IS_MAINNET,
|
|
404
|
+
allowLend: false,
|
|
405
|
+
allowBorrow: false,
|
|
406
|
+
name: "TrueUSD",
|
|
407
|
+
coin: "TUSD",
|
|
408
|
+
xtokenSymbol: "XTUSD",
|
|
409
|
+
xtokenPrecision: 6,
|
|
410
|
+
xtokenContract: "xtokens",
|
|
411
|
+
wallets: [
|
|
412
|
+
...IS_MAINNET ? [{
|
|
413
|
+
wallet: "TUSD",
|
|
414
|
+
symbol: "TUSD",
|
|
415
|
+
chain: "Ethereum" /* EthereumMainnet */,
|
|
416
|
+
network: "erc20" /* ERC20 */,
|
|
417
|
+
precision: 18,
|
|
418
|
+
contract: "0x0000000000085D4780B73119B644AE5ECD22B376",
|
|
419
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
420
|
+
hasWithdrawMemo: false
|
|
421
|
+
}] : []
|
|
422
|
+
],
|
|
423
|
+
image: "https://www.proton.org/images/tokens/xtokensXTUSD.png",
|
|
424
|
+
coingeckoId: "true-usd"
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
allowSwap: false,
|
|
428
|
+
allowBridge: IS_MAINNET,
|
|
429
|
+
allowLend: false,
|
|
430
|
+
allowBorrow: false,
|
|
431
|
+
name: "Euro Coin",
|
|
432
|
+
coin: "EUROC",
|
|
433
|
+
xtokenSymbol: "XEUROC",
|
|
434
|
+
xtokenPrecision: 6,
|
|
435
|
+
xtokenContract: "xtokens",
|
|
436
|
+
wallets: [
|
|
437
|
+
...IS_MAINNET ? [{
|
|
438
|
+
wallet: "EUROC",
|
|
439
|
+
symbol: "EUROC-ERC20",
|
|
440
|
+
chain: "Ethereum" /* EthereumMainnet */,
|
|
441
|
+
network: "erc20" /* ERC20 */,
|
|
442
|
+
precision: 6,
|
|
443
|
+
contract: "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
|
|
444
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
445
|
+
hasWithdrawMemo: false
|
|
446
|
+
}] : []
|
|
447
|
+
],
|
|
448
|
+
image: "https://assets.coingecko.com/coins/images/26045/small/euro-coin.png?1655394420",
|
|
449
|
+
coingeckoId: "euro-coin"
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
allowSwap: false,
|
|
453
|
+
allowBridge: IS_MAINNET,
|
|
454
|
+
allowLend: false,
|
|
455
|
+
allowBorrow: false,
|
|
456
|
+
name: "XDC Network",
|
|
457
|
+
coin: "XDC",
|
|
458
|
+
xtokenSymbol: "XDC",
|
|
459
|
+
xtokenPrecision: 4,
|
|
460
|
+
xtokenContract: "xtokens",
|
|
461
|
+
wallets: [
|
|
462
|
+
...IS_MAINNET ? [{
|
|
463
|
+
wallet: "XDC",
|
|
464
|
+
symbol: "XDC",
|
|
465
|
+
chain: "XDC Network" /* XDCMainnet */,
|
|
466
|
+
network: "mainnet" /* Mainnet */,
|
|
467
|
+
precision: 18,
|
|
468
|
+
contract: "",
|
|
469
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
470
|
+
hasWithdrawMemo: false
|
|
471
|
+
}] : []
|
|
472
|
+
],
|
|
473
|
+
image: "https://assets.coingecko.com/coins/images/2912/small/xdc-icon.png?1633700890",
|
|
474
|
+
coingeckoId: "xdce-crowd-sale"
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
allowSwap: false,
|
|
478
|
+
allowBridge: IS_MAINNET,
|
|
479
|
+
allowLend: false,
|
|
480
|
+
allowBorrow: false,
|
|
481
|
+
name: "Paxos Dollar",
|
|
482
|
+
coin: "PAX",
|
|
483
|
+
xtokenSymbol: "XPAX",
|
|
484
|
+
xtokenPrecision: 6,
|
|
485
|
+
xtokenContract: "xtokens",
|
|
486
|
+
wallets: [
|
|
487
|
+
...IS_MAINNET ? [{
|
|
488
|
+
wallet: "PAX",
|
|
489
|
+
symbol: "PAX",
|
|
490
|
+
chain: "Ethereum" /* EthereumMainnet */,
|
|
491
|
+
network: "erc20" /* ERC20 */,
|
|
492
|
+
precision: 18,
|
|
493
|
+
contract: "0x8E870D67F660D95D5BE530380D0EC0BD388289E1",
|
|
494
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
495
|
+
hasWithdrawMemo: false
|
|
496
|
+
}] : []
|
|
497
|
+
],
|
|
498
|
+
image: "https://www.proton.org/images/tokens/xtokensXPAX.png",
|
|
499
|
+
coingeckoId: "paxos-standard"
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
allowSwap: false,
|
|
503
|
+
allowBridge: true,
|
|
504
|
+
allowLend: false,
|
|
505
|
+
allowBorrow: false,
|
|
506
|
+
name: "Paxos Gold",
|
|
507
|
+
coin: "PAXG",
|
|
508
|
+
xtokenSymbol: "XPAXG",
|
|
509
|
+
xtokenPrecision: 8,
|
|
510
|
+
xtokenContract: "xtokens",
|
|
511
|
+
wallets: [
|
|
512
|
+
...IS_MAINNET ? [{
|
|
513
|
+
wallet: "PAXG",
|
|
514
|
+
symbol: "PAXG",
|
|
515
|
+
chain: "Ethereum" /* EthereumMainnet */,
|
|
516
|
+
network: "erc20" /* ERC20 */,
|
|
517
|
+
precision: 18,
|
|
518
|
+
contract: "0x45804880DE22913DAFE09F4980848ECE6ECBAF78",
|
|
519
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
520
|
+
hasWithdrawMemo: false
|
|
521
|
+
}] : [],
|
|
522
|
+
...IS_TESTNET ? [{
|
|
523
|
+
wallet: "PAXG",
|
|
524
|
+
symbol: "PAXG",
|
|
525
|
+
chain: "Ethereum (Ropsten)" /* EthereumRopsten */,
|
|
526
|
+
network: "ropsten" /* Ropsten */,
|
|
527
|
+
precision: 18,
|
|
528
|
+
contract: "0x45804880DE22913DAFE09F4980848ECE6ECBAF78",
|
|
529
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
530
|
+
hasWithdrawMemo: false
|
|
531
|
+
}] : []
|
|
532
|
+
],
|
|
533
|
+
image: "https://www.proton.org/images/tokens/xtokensXPAXG.png",
|
|
534
|
+
coingeckoId: "pax-gold"
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
allowSwap: IS_MAINNET,
|
|
538
|
+
allowBridge: false,
|
|
539
|
+
allowLend: false,
|
|
540
|
+
allowBorrow: false,
|
|
541
|
+
name: "Storex",
|
|
542
|
+
coin: "STRX",
|
|
543
|
+
xtokenSymbol: "STRX",
|
|
544
|
+
xtokenPrecision: 4,
|
|
545
|
+
xtokenContract: "storex",
|
|
546
|
+
wallets: [],
|
|
547
|
+
image: "https://raw.githubusercontent.com/eoscafe/eos-airdrops/master/logos/strx.png",
|
|
548
|
+
coingeckoId: ""
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
allowSwap: IS_MAINNET,
|
|
552
|
+
allowBridge: false,
|
|
553
|
+
allowLend: false,
|
|
554
|
+
allowBorrow: false,
|
|
555
|
+
name: "Mint",
|
|
556
|
+
coin: "MINT",
|
|
557
|
+
xtokenSymbol: "MINT",
|
|
558
|
+
xtokenPrecision: 4,
|
|
559
|
+
xtokenContract: "protonmint",
|
|
560
|
+
wallets: [],
|
|
561
|
+
image: "https://raw.githubusercontent.com/eoscafe/eos-airdrops/master/logos/PMLogo-04.png",
|
|
562
|
+
coingeckoId: ""
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
allowSwap: IS_MAINNET,
|
|
566
|
+
allowBridge: false,
|
|
567
|
+
allowLend: false,
|
|
568
|
+
allowBorrow: false,
|
|
569
|
+
name: "Snipcoins",
|
|
570
|
+
coin: "SNIPS",
|
|
571
|
+
xtokenSymbol: "SNIPS",
|
|
572
|
+
xtokenPrecision: 4,
|
|
573
|
+
xtokenContract: "snipcoins",
|
|
574
|
+
wallets: [],
|
|
575
|
+
image: "https://raw.githubusercontent.com/eoscafe/eos-airdrops/master/logos/snips.png",
|
|
576
|
+
coingeckoId: ""
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
allowSwap: IS_MAINNET,
|
|
580
|
+
allowBridge: true,
|
|
581
|
+
allowLend: false,
|
|
582
|
+
allowBorrow: false,
|
|
583
|
+
name: "Uniswap",
|
|
584
|
+
coin: "UNI",
|
|
585
|
+
xtokenSymbol: "XUNI",
|
|
586
|
+
xtokenPrecision: 6,
|
|
587
|
+
xtokenContract: "xtokens",
|
|
588
|
+
wallets: [
|
|
589
|
+
...IS_MAINNET ? [{
|
|
590
|
+
wallet: "UNI",
|
|
591
|
+
symbol: "UNI",
|
|
592
|
+
chain: "Ethereum" /* EthereumMainnet */,
|
|
593
|
+
network: "erc20" /* ERC20 */,
|
|
594
|
+
precision: 18,
|
|
595
|
+
contract: "0x1F9840A85D5AF5BF1D1762F925BDADDC4201F984",
|
|
596
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
597
|
+
hasWithdrawMemo: false
|
|
598
|
+
}] : [],
|
|
599
|
+
...IS_TESTNET ? [{
|
|
600
|
+
wallet: "UNI",
|
|
601
|
+
symbol: "UNI",
|
|
602
|
+
chain: "Ethereum (Ropsten)" /* EthereumRopsten */,
|
|
603
|
+
network: "ropsten" /* Ropsten */,
|
|
604
|
+
precision: 18,
|
|
605
|
+
contract: "0x1F9840A85D5AF5BF1D1762F925BDADDC4201F984",
|
|
606
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
607
|
+
hasWithdrawMemo: false
|
|
608
|
+
}] : []
|
|
609
|
+
],
|
|
610
|
+
image: "https://www.proton.org/images/tokens/xtokensXUNI.png",
|
|
611
|
+
coingeckoId: "uniswap"
|
|
612
|
+
},
|
|
613
|
+
{
|
|
614
|
+
allowSwap: false,
|
|
615
|
+
allowBridge: false,
|
|
616
|
+
allowLend: false,
|
|
617
|
+
allowBorrow: false,
|
|
618
|
+
name: "1INCH",
|
|
619
|
+
coin: "1INCH",
|
|
620
|
+
xtokenSymbol: "XINCH",
|
|
621
|
+
xtokenPrecision: 6,
|
|
622
|
+
xtokenContract: "xtokens",
|
|
623
|
+
wallets: [
|
|
624
|
+
...IS_MAINNET ? [{
|
|
625
|
+
wallet: "1INCH",
|
|
626
|
+
symbol: "1INCH",
|
|
627
|
+
chain: "Ethereum" /* EthereumMainnet */,
|
|
628
|
+
network: "erc20" /* ERC20 */,
|
|
629
|
+
precision: 18,
|
|
630
|
+
contract: "0x111111111117DC0AA78B770FA6A738034120C302",
|
|
631
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
632
|
+
hasWithdrawMemo: false
|
|
633
|
+
}] : []
|
|
634
|
+
],
|
|
635
|
+
image: "https://www.proton.org/images/tokens/xtokensXINCH.png",
|
|
636
|
+
coingeckoId: "1inch"
|
|
637
|
+
},
|
|
638
|
+
{
|
|
639
|
+
allowSwap: false,
|
|
640
|
+
allowBridge: false,
|
|
641
|
+
allowLend: false,
|
|
642
|
+
allowBorrow: false,
|
|
643
|
+
name: "Chainlink",
|
|
644
|
+
coin: "LINK",
|
|
645
|
+
xtokenSymbol: "XLINK",
|
|
646
|
+
xtokenPrecision: 6,
|
|
647
|
+
xtokenContract: "xtokens",
|
|
648
|
+
wallets: [
|
|
649
|
+
...IS_MAINNET ? [{
|
|
650
|
+
wallet: "LINK",
|
|
651
|
+
symbol: "LINK",
|
|
652
|
+
chain: "Ethereum" /* EthereumMainnet */,
|
|
653
|
+
network: "erc20" /* ERC20 */,
|
|
654
|
+
precision: 18,
|
|
655
|
+
contract: "0x514910771AF9CA656AF840DFF83E8264ECF986CA",
|
|
656
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
657
|
+
hasWithdrawMemo: false
|
|
658
|
+
}] : []
|
|
659
|
+
],
|
|
660
|
+
image: "https://www.proton.org/images/tokens/xtokensXLINK.png",
|
|
661
|
+
coingeckoId: "chainlink"
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
allowSwap: IS_MAINNET,
|
|
665
|
+
allowBridge: true,
|
|
666
|
+
allowLend: false,
|
|
667
|
+
allowBorrow: false,
|
|
668
|
+
name: "Litecoin",
|
|
669
|
+
coin: "LTC",
|
|
670
|
+
xtokenSymbol: "XLTC",
|
|
671
|
+
xtokenPrecision: 8,
|
|
672
|
+
xtokenContract: "xtokens",
|
|
673
|
+
wallets: [
|
|
674
|
+
...IS_MAINNET ? [{
|
|
675
|
+
wallet: "LTC",
|
|
676
|
+
symbol: "LTC",
|
|
677
|
+
chain: "Litecoin" /* LitecoinMainnet */,
|
|
678
|
+
network: "mainnet" /* Mainnet */,
|
|
679
|
+
precision: 8,
|
|
680
|
+
contract: void 0,
|
|
681
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
682
|
+
hasWithdrawMemo: false
|
|
683
|
+
}] : [],
|
|
684
|
+
...IS_TESTNET ? [{
|
|
685
|
+
wallet: "LTC",
|
|
686
|
+
symbol: "LTC",
|
|
687
|
+
chain: "Litecoin (Testnet)" /* LitecoinTestnet */,
|
|
688
|
+
network: "testnet" /* Testnet */,
|
|
689
|
+
precision: 8,
|
|
690
|
+
contract: void 0,
|
|
691
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
692
|
+
hasWithdrawMemo: false
|
|
693
|
+
}] : []
|
|
694
|
+
],
|
|
695
|
+
image: "https://www.proton.org/images/tokens/xtokensXLTC.png",
|
|
696
|
+
coingeckoId: "litecoin"
|
|
697
|
+
},
|
|
698
|
+
{
|
|
699
|
+
allowSwap: false,
|
|
700
|
+
allowBridge: true,
|
|
701
|
+
allowLend: false,
|
|
702
|
+
allowBorrow: false,
|
|
703
|
+
name: "Bitcoin Cash",
|
|
704
|
+
coin: "BCH",
|
|
705
|
+
xtokenSymbol: "XBCH",
|
|
706
|
+
xtokenPrecision: 8,
|
|
707
|
+
xtokenContract: "xtokens",
|
|
708
|
+
wallets: [
|
|
709
|
+
...IS_MAINNET ? [{
|
|
710
|
+
wallet: "BCH",
|
|
711
|
+
symbol: "BCH",
|
|
712
|
+
chain: "Bitcoin Cash" /* BitcoinCashMainnet */,
|
|
713
|
+
network: "mainnet" /* Mainnet */,
|
|
714
|
+
precision: 8,
|
|
715
|
+
contract: void 0,
|
|
716
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
717
|
+
hasWithdrawMemo: false
|
|
718
|
+
}] : [],
|
|
719
|
+
...IS_TESTNET ? [{
|
|
720
|
+
wallet: "BCH",
|
|
721
|
+
symbol: "BCH",
|
|
722
|
+
chain: "Bitcoin Cash (Testnet)" /* BitcoinCashTestnet */,
|
|
723
|
+
network: "testnet" /* Testnet */,
|
|
724
|
+
precision: 8,
|
|
725
|
+
contract: void 0,
|
|
726
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
727
|
+
hasWithdrawMemo: false
|
|
728
|
+
}] : []
|
|
729
|
+
],
|
|
730
|
+
image: "https://www.proton.org/images/tokens/xtokensXBCH.png",
|
|
731
|
+
coingeckoId: "bitcoin-cash"
|
|
732
|
+
},
|
|
733
|
+
{
|
|
734
|
+
allowSwap: true,
|
|
735
|
+
allowBridge: true,
|
|
736
|
+
allowLend: false,
|
|
737
|
+
allowBorrow: false,
|
|
738
|
+
name: "LunarCrush",
|
|
739
|
+
coin: "LUNR",
|
|
740
|
+
xtokenSymbol: "XLUNR",
|
|
741
|
+
xtokenPrecision: 4,
|
|
742
|
+
xtokenContract: "xtokens",
|
|
743
|
+
wallets: [
|
|
744
|
+
...IS_MAINNET ? [{
|
|
745
|
+
wallet: "LUNR",
|
|
746
|
+
symbol: "LUNR",
|
|
747
|
+
chain: "Ethereum" /* EthereumMainnet */,
|
|
748
|
+
network: "erc20" /* ERC20 */,
|
|
749
|
+
precision: 4,
|
|
750
|
+
contract: void 0,
|
|
751
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
752
|
+
hasWithdrawMemo: false
|
|
753
|
+
}] : []
|
|
754
|
+
],
|
|
755
|
+
image: "https://raw.githubusercontent.com/eoscafe/eos-airdrops/master/logos/xlunr.png",
|
|
756
|
+
coingeckoId: "lunr-token"
|
|
757
|
+
},
|
|
758
|
+
{
|
|
759
|
+
allowSwap: false,
|
|
760
|
+
allowBridge: IS_TESTNET,
|
|
761
|
+
allowLend: false,
|
|
762
|
+
allowBorrow: false,
|
|
763
|
+
name: "Stellar",
|
|
764
|
+
coin: "XLM",
|
|
765
|
+
xtokenSymbol: "XXLM",
|
|
766
|
+
xtokenPrecision: 6,
|
|
767
|
+
xtokenContract: "xtokens",
|
|
768
|
+
wallets: [
|
|
769
|
+
...IS_MAINNET ? [{
|
|
770
|
+
wallet: "XLM",
|
|
771
|
+
symbol: "XLM",
|
|
772
|
+
chain: "Stellar" /* StellarMainnet */,
|
|
773
|
+
network: "mainnet" /* Mainnet */,
|
|
774
|
+
precision: 7,
|
|
775
|
+
contract: void 0,
|
|
776
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
777
|
+
hasWithdrawMemo: true
|
|
778
|
+
}] : [],
|
|
779
|
+
...IS_TESTNET ? [{
|
|
780
|
+
wallet: "XLM",
|
|
781
|
+
symbol: "XLM",
|
|
782
|
+
chain: "Stellar (Testnet)" /* StellarTestnet */,
|
|
783
|
+
network: "testnet" /* Testnet */,
|
|
784
|
+
precision: 7,
|
|
785
|
+
contract: void 0,
|
|
786
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
787
|
+
hasWithdrawMemo: true
|
|
788
|
+
}] : []
|
|
789
|
+
],
|
|
790
|
+
image: "https://www.proton.org/images/tokens/xtokensXXLM.png",
|
|
791
|
+
coingeckoId: "stellar"
|
|
792
|
+
},
|
|
793
|
+
{
|
|
794
|
+
allowSwap: false,
|
|
795
|
+
allowBridge: false,
|
|
796
|
+
allowLend: false,
|
|
797
|
+
allowBorrow: false,
|
|
798
|
+
name: "Sense",
|
|
799
|
+
coin: "SENSE",
|
|
800
|
+
xtokenSymbol: "XSENSE",
|
|
801
|
+
xtokenPrecision: 4,
|
|
802
|
+
xtokenContract: "sense",
|
|
803
|
+
wallets: [],
|
|
804
|
+
image: "https://www.proton.org/images/tokens/senseXSENSE.png",
|
|
805
|
+
coingeckoId: "sense"
|
|
806
|
+
},
|
|
807
|
+
{
|
|
808
|
+
allowSwap: false,
|
|
809
|
+
allowBridge: false,
|
|
810
|
+
allowLend: false,
|
|
811
|
+
allowBorrow: false,
|
|
812
|
+
name: "Polkadot",
|
|
813
|
+
coin: "DOT",
|
|
814
|
+
xtokenSymbol: "XDOT",
|
|
815
|
+
xtokenPrecision: 8,
|
|
816
|
+
xtokenContract: "xtokens",
|
|
817
|
+
wallets: [
|
|
818
|
+
...IS_MAINNET ? [{
|
|
819
|
+
wallet: "DOT",
|
|
820
|
+
symbol: "DOT",
|
|
821
|
+
chain: "Polkadot" /* PolkadotMainnet */,
|
|
822
|
+
network: "mainnet" /* Mainnet */,
|
|
823
|
+
precision: 10,
|
|
824
|
+
contract: void 0,
|
|
825
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
826
|
+
hasWithdrawMemo: false
|
|
827
|
+
}] : []
|
|
828
|
+
],
|
|
829
|
+
image: "https://www.proton.org/images/tokens/xtokensXDOT.png",
|
|
830
|
+
coingeckoId: "polkadot"
|
|
831
|
+
},
|
|
832
|
+
{
|
|
833
|
+
allowSwap: true,
|
|
834
|
+
allowBridge: IS_MAINNET,
|
|
835
|
+
allowLend: false,
|
|
836
|
+
allowBorrow: false,
|
|
837
|
+
name: "Binance Coin",
|
|
838
|
+
coin: "BNB",
|
|
839
|
+
xtokenSymbol: "XBNB",
|
|
840
|
+
xtokenPrecision: 8,
|
|
841
|
+
xtokenContract: "xtokens",
|
|
842
|
+
wallets: [
|
|
843
|
+
...IS_MAINNET ? [{
|
|
844
|
+
wallet: "BNB",
|
|
845
|
+
symbol: "BNB",
|
|
846
|
+
chain: "Binance (BEP20)" /* BinanceBEP20 */,
|
|
847
|
+
network: "bep20" /* BEP20 */,
|
|
848
|
+
precision: 18,
|
|
849
|
+
contract: void 0,
|
|
850
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
851
|
+
hasWithdrawMemo: false
|
|
852
|
+
}] : []
|
|
853
|
+
],
|
|
854
|
+
image: "https://www.proton.org/images/tokens/xtokensXBNB.png",
|
|
855
|
+
coingeckoId: "binancecoin"
|
|
856
|
+
},
|
|
857
|
+
{
|
|
858
|
+
allowSwap: false,
|
|
859
|
+
allowBridge: false,
|
|
860
|
+
allowLend: false,
|
|
861
|
+
allowBorrow: false,
|
|
862
|
+
name: "Binance USD",
|
|
863
|
+
coin: "BUSD",
|
|
864
|
+
xtokenSymbol: "XBUSD",
|
|
865
|
+
xtokenPrecision: 6,
|
|
866
|
+
xtokenContract: "xtokens",
|
|
867
|
+
wallets: [
|
|
868
|
+
// ...(IS_MAINNET ? [{
|
|
869
|
+
// wallet: 'BUSD-BEP20',
|
|
870
|
+
// symbol: 'BUSD',
|
|
871
|
+
// chain: Chains.BinanceBEP20,
|
|
872
|
+
// network: Networks.BEP20,
|
|
873
|
+
// precision: 18,
|
|
874
|
+
// contract: '0xe9e7cea3dedca5984780bafc599bd69add087d56',
|
|
875
|
+
// provider: Providers.FIREBLOCKS,
|
|
876
|
+
// hasWithdrawMemo: false
|
|
877
|
+
// }]: [])
|
|
878
|
+
],
|
|
879
|
+
image: "https://raw.githubusercontent.com/eoscafe/eos-airdrops/master/logos/xbusd.png",
|
|
880
|
+
coingeckoId: "binance-usd"
|
|
881
|
+
},
|
|
882
|
+
{
|
|
883
|
+
allowSwap: true,
|
|
884
|
+
allowBridge: true,
|
|
885
|
+
allowLend: false,
|
|
886
|
+
allowBorrow: false,
|
|
887
|
+
name: "EOS",
|
|
888
|
+
coin: "EOS",
|
|
889
|
+
xtokenSymbol: "XEOS",
|
|
890
|
+
xtokenPrecision: 4,
|
|
891
|
+
xtokenContract: "xtokens",
|
|
892
|
+
wallets: [
|
|
893
|
+
...IS_MAINNET ? [{
|
|
894
|
+
wallet: "EOS",
|
|
895
|
+
symbol: "EOS",
|
|
896
|
+
chain: "EOS" /* EosMainnet */,
|
|
897
|
+
network: "mainnet" /* Mainnet */,
|
|
898
|
+
precision: 4,
|
|
899
|
+
contract: void 0,
|
|
900
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
901
|
+
hasWithdrawMemo: true
|
|
902
|
+
}] : [],
|
|
903
|
+
...IS_TESTNET ? [{
|
|
904
|
+
wallet: "EOS",
|
|
905
|
+
symbol: "EOS",
|
|
906
|
+
chain: "EOS (Jungle Testnet)" /* EosTestnet */,
|
|
907
|
+
network: "testnet" /* Testnet */,
|
|
908
|
+
precision: 4,
|
|
909
|
+
contract: void 0,
|
|
910
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
911
|
+
hasWithdrawMemo: true
|
|
912
|
+
}] : []
|
|
913
|
+
],
|
|
914
|
+
image: "https://www.proton.org/images/tokens/xtokensXEOS.png",
|
|
915
|
+
coingeckoId: "eos"
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
allowSwap: IS_MAINNET,
|
|
919
|
+
allowBridge: IS_MAINNET,
|
|
920
|
+
allowLend: true,
|
|
921
|
+
allowBorrow: true,
|
|
922
|
+
name: "Dogecoin",
|
|
923
|
+
coin: "DOGE",
|
|
924
|
+
xtokenSymbol: "XDOGE",
|
|
925
|
+
xtokenPrecision: 6,
|
|
926
|
+
xtokenContract: "xtokens",
|
|
927
|
+
wallets: [
|
|
928
|
+
...IS_MAINNET ? [{
|
|
929
|
+
wallet: "DOGE",
|
|
930
|
+
symbol: "DOGE",
|
|
931
|
+
chain: "Dogecoin" /* DogeMainnet */,
|
|
932
|
+
network: "mainnet" /* Mainnet */,
|
|
933
|
+
precision: 8,
|
|
934
|
+
contract: void 0,
|
|
935
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
936
|
+
hasWithdrawMemo: false
|
|
937
|
+
}] : []
|
|
938
|
+
],
|
|
939
|
+
image: "https://www.proton.org/images/tokens/xtokensXDOGE.png",
|
|
940
|
+
coingeckoId: "dogecoin"
|
|
941
|
+
},
|
|
942
|
+
{
|
|
943
|
+
allowSwap: IS_MAINNET,
|
|
944
|
+
allowBridge: IS_MAINNET,
|
|
945
|
+
allowLend: false,
|
|
946
|
+
allowBorrow: false,
|
|
947
|
+
name: "Cardano",
|
|
948
|
+
coin: "ADA",
|
|
949
|
+
xtokenSymbol: "XADA",
|
|
950
|
+
xtokenPrecision: 6,
|
|
951
|
+
xtokenContract: "xtokens",
|
|
952
|
+
wallets: [
|
|
953
|
+
...IS_MAINNET ? [{
|
|
954
|
+
wallet: "ADA",
|
|
955
|
+
symbol: "ADA",
|
|
956
|
+
chain: "Cardano" /* CardanoMainnet */,
|
|
957
|
+
network: "mainnet" /* Mainnet */,
|
|
958
|
+
precision: 6,
|
|
959
|
+
contract: void 0,
|
|
960
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
961
|
+
hasWithdrawMemo: false
|
|
962
|
+
}] : []
|
|
963
|
+
],
|
|
964
|
+
image: "https://www.proton.org/images/tokens/xtokensXADA.png",
|
|
965
|
+
coingeckoId: "cardano"
|
|
966
|
+
},
|
|
967
|
+
// Adding
|
|
968
|
+
{
|
|
969
|
+
allowSwap: false,
|
|
970
|
+
allowBridge: false,
|
|
971
|
+
allowLend: false,
|
|
972
|
+
allowBorrow: false,
|
|
973
|
+
name: "Terra",
|
|
974
|
+
coin: "LUNA",
|
|
975
|
+
xtokenSymbol: "XLUNA",
|
|
976
|
+
xtokenPrecision: 6,
|
|
977
|
+
xtokenContract: "xtokens",
|
|
978
|
+
wallets: [
|
|
979
|
+
// ...(IS_MAINNET ? [{
|
|
980
|
+
// wallet: 'LUNA',
|
|
981
|
+
// symbol: 'LUNA',
|
|
982
|
+
// chain: Chains.TerraMainnet,
|
|
983
|
+
// network: Networks.Mainnet,
|
|
984
|
+
// precision: 6,
|
|
985
|
+
// contract: undefined,
|
|
986
|
+
// provider: Providers.FIREBLOCKS,
|
|
987
|
+
// hasWithdrawMemo: true
|
|
988
|
+
// }]: [])
|
|
989
|
+
],
|
|
990
|
+
image: "https://www.proton.org/images/tokens/xtokensXLUNA.png",
|
|
991
|
+
coingeckoId: "terra-luna"
|
|
992
|
+
},
|
|
993
|
+
{
|
|
994
|
+
allowSwap: false,
|
|
995
|
+
allowBridge: false,
|
|
996
|
+
allowLend: false,
|
|
997
|
+
allowBorrow: false,
|
|
998
|
+
name: "TerraUSD",
|
|
999
|
+
coin: "UST",
|
|
1000
|
+
xtokenSymbol: "XUST",
|
|
1001
|
+
xtokenPrecision: 6,
|
|
1002
|
+
xtokenContract: "xtokens",
|
|
1003
|
+
wallets: [
|
|
1004
|
+
...IS_MAINNET ? [{
|
|
1005
|
+
wallet: "UST",
|
|
1006
|
+
symbol: "UST",
|
|
1007
|
+
chain: "Terra" /* TerraMainnet */,
|
|
1008
|
+
network: "mainnet" /* Mainnet */,
|
|
1009
|
+
precision: 6,
|
|
1010
|
+
contract: void 0,
|
|
1011
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
1012
|
+
hasWithdrawMemo: true
|
|
1013
|
+
}] : []
|
|
1014
|
+
],
|
|
1015
|
+
image: "https://www.proton.org/images/tokens/xtokensXUST.png",
|
|
1016
|
+
coingeckoId: "terrausd"
|
|
1017
|
+
},
|
|
1018
|
+
{
|
|
1019
|
+
allowSwap: false,
|
|
1020
|
+
allowBridge: IS_MAINNET,
|
|
1021
|
+
allowLend: false,
|
|
1022
|
+
allowBorrow: false,
|
|
1023
|
+
name: "Solana",
|
|
1024
|
+
coin: "SOL",
|
|
1025
|
+
xtokenSymbol: "XSOL",
|
|
1026
|
+
xtokenPrecision: 6,
|
|
1027
|
+
xtokenContract: "xtokens",
|
|
1028
|
+
wallets: [
|
|
1029
|
+
...IS_MAINNET ? [{
|
|
1030
|
+
wallet: "SOL",
|
|
1031
|
+
symbol: "SOL",
|
|
1032
|
+
chain: "Solana" /* SolanaMainnet */,
|
|
1033
|
+
network: "mainnet" /* Mainnet */,
|
|
1034
|
+
precision: 9,
|
|
1035
|
+
contract: void 0,
|
|
1036
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
1037
|
+
hasWithdrawMemo: false
|
|
1038
|
+
}] : []
|
|
1039
|
+
],
|
|
1040
|
+
image: "https://raw.githubusercontent.com/eoscafe/eos-airdrops/master/logos/xsol.png",
|
|
1041
|
+
coingeckoId: "solana"
|
|
1042
|
+
},
|
|
1043
|
+
{
|
|
1044
|
+
allowSwap: false,
|
|
1045
|
+
allowBridge: IS_MAINNET,
|
|
1046
|
+
allowLend: false,
|
|
1047
|
+
allowBorrow: false,
|
|
1048
|
+
name: "Ripple",
|
|
1049
|
+
coin: "XRP",
|
|
1050
|
+
xtokenSymbol: "XXRP",
|
|
1051
|
+
xtokenPrecision: 6,
|
|
1052
|
+
xtokenContract: "xtokens",
|
|
1053
|
+
wallets: [
|
|
1054
|
+
...IS_MAINNET ? [{
|
|
1055
|
+
wallet: "XRP",
|
|
1056
|
+
symbol: "XRP",
|
|
1057
|
+
chain: "Ripple" /* RippleMainnet */,
|
|
1058
|
+
network: "mainnet" /* Mainnet */,
|
|
1059
|
+
precision: 6,
|
|
1060
|
+
contract: void 0,
|
|
1061
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
1062
|
+
hasWithdrawMemo: true
|
|
1063
|
+
}] : []
|
|
1064
|
+
],
|
|
1065
|
+
image: "https://raw.githubusercontent.com/eoscafe/eos-airdrops/master/logos/xxrp.png",
|
|
1066
|
+
coingeckoId: "ripple"
|
|
1067
|
+
},
|
|
1068
|
+
// Future
|
|
1069
|
+
{
|
|
1070
|
+
allowSwap: false,
|
|
1071
|
+
allowBridge: false,
|
|
1072
|
+
allowLend: false,
|
|
1073
|
+
allowBorrow: false,
|
|
1074
|
+
name: "Avalanche",
|
|
1075
|
+
coin: "AVAX",
|
|
1076
|
+
xtokenSymbol: "XAVAX",
|
|
1077
|
+
xtokenPrecision: 9,
|
|
1078
|
+
xtokenContract: "xtokens",
|
|
1079
|
+
wallets: [
|
|
1080
|
+
...IS_MAINNET ? [
|
|
1081
|
+
{
|
|
1082
|
+
wallet: "AVAX",
|
|
1083
|
+
symbol: "AVAX",
|
|
1084
|
+
chain: "Avalanche C-Chain" /* AvalancheCChain */,
|
|
1085
|
+
network: "mainnet" /* Mainnet */,
|
|
1086
|
+
precision: 9,
|
|
1087
|
+
contract: void 0,
|
|
1088
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
1089
|
+
hasWithdrawMemo: false
|
|
1090
|
+
}
|
|
1091
|
+
] : []
|
|
1092
|
+
],
|
|
1093
|
+
image: "https://www.proton.org/images/tokens/xtokensXAVAX.png",
|
|
1094
|
+
coingeckoId: "avalanche-2"
|
|
1095
|
+
},
|
|
1096
|
+
{
|
|
1097
|
+
allowSwap: false,
|
|
1098
|
+
allowBridge: false,
|
|
1099
|
+
allowLend: false,
|
|
1100
|
+
allowBorrow: false,
|
|
1101
|
+
name: "Polygon",
|
|
1102
|
+
coin: "MATIC",
|
|
1103
|
+
xtokenSymbol: "XMATIC",
|
|
1104
|
+
xtokenPrecision: 8,
|
|
1105
|
+
xtokenContract: "xtokens",
|
|
1106
|
+
wallets: [
|
|
1107
|
+
...IS_MAINNET ? [{
|
|
1108
|
+
wallet: "MATIC",
|
|
1109
|
+
symbol: "MATIC",
|
|
1110
|
+
chain: "Polygon" /* PolygonMainnet */,
|
|
1111
|
+
network: "mainnet" /* Mainnet */,
|
|
1112
|
+
precision: 18,
|
|
1113
|
+
contract: "0x0000000000000000000000000000000000000000",
|
|
1114
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
1115
|
+
hasWithdrawMemo: false
|
|
1116
|
+
}] : []
|
|
1117
|
+
],
|
|
1118
|
+
image: "https://www.proton.org/images/tokens/xtokensXMATIC.png",
|
|
1119
|
+
coingeckoId: "matic-network"
|
|
1120
|
+
},
|
|
1121
|
+
{
|
|
1122
|
+
allowSwap: true,
|
|
1123
|
+
allowBridge: false,
|
|
1124
|
+
allowLend: false,
|
|
1125
|
+
allowBorrow: false,
|
|
1126
|
+
name: "Metal Dollar",
|
|
1127
|
+
coin: "XMD",
|
|
1128
|
+
xtokenSymbol: "XMD",
|
|
1129
|
+
xtokenPrecision: 6,
|
|
1130
|
+
xtokenContract: "xmd.token",
|
|
1131
|
+
wallets: [],
|
|
1132
|
+
image: "https://github.com/eoscafe/eos-airdrops/blob/master/logos/xmd.png?raw=true",
|
|
1133
|
+
coingeckoId: ""
|
|
1134
|
+
},
|
|
1135
|
+
{
|
|
1136
|
+
allowSwap: false,
|
|
1137
|
+
allowBridge: IS_TESTNET,
|
|
1138
|
+
allowLend: false,
|
|
1139
|
+
allowBorrow: false,
|
|
1140
|
+
name: "HBAR",
|
|
1141
|
+
coin: "HBAR",
|
|
1142
|
+
xtokenSymbol: "XHBAR",
|
|
1143
|
+
xtokenPrecision: 6,
|
|
1144
|
+
xtokenContract: "xtokens",
|
|
1145
|
+
wallets: [
|
|
1146
|
+
...IS_TESTNET ? [{
|
|
1147
|
+
wallet: "HBAR",
|
|
1148
|
+
symbol: "HBAR",
|
|
1149
|
+
chain: "Hedera (Testnet)" /* HederaTestnet */,
|
|
1150
|
+
network: "testnet" /* Testnet */,
|
|
1151
|
+
precision: 8,
|
|
1152
|
+
contract: void 0,
|
|
1153
|
+
provider: "fireblocks" /* FIREBLOCKS */,
|
|
1154
|
+
hasWithdrawMemo: true
|
|
1155
|
+
}] : []
|
|
1156
|
+
],
|
|
1157
|
+
image: "https://www.proton.org/images/tokens/xtokensXHBAR.png",
|
|
1158
|
+
coingeckoId: "hedera-hashgraph"
|
|
1159
|
+
}
|
|
1160
|
+
];
|
|
1161
|
+
const walletWithDuplicateChains = coins.find((coin) => {
|
|
1162
|
+
const chains = coin.wallets.map((wallet) => wallet.chain);
|
|
1163
|
+
return new Set(chains).size !== chains.length;
|
|
1164
|
+
});
|
|
1165
|
+
if (walletWithDuplicateChains) {
|
|
1166
|
+
throw new Error(`Coin ${walletWithDuplicateChains.coin} has duplicate chains in wallet`);
|
|
1167
|
+
}
|
|
1168
|
+
return {
|
|
1169
|
+
allCoins: coins,
|
|
1170
|
+
swapCoins: coins.filter((coin) => coin.allowSwap),
|
|
1171
|
+
bridgeCoins: coins.filter((coin) => coin.allowBridge),
|
|
1172
|
+
lendCoins: coins.filter((coin) => coin.allowLend),
|
|
1173
|
+
borrowCoins: coins.filter((coin) => coin.allowBorrow),
|
|
1174
|
+
loanCoins: coins.filter((coin) => coin.allowLend || coin.allowBorrow),
|
|
1175
|
+
allEnabledCoins: coins.filter((coin) => coin.allowSwap || coin.allowBridge || coin.xtokenSymbol === "XMD")
|
|
1176
|
+
};
|
|
1177
|
+
};
|
|
1178
|
+
|
|
1179
|
+
// src/parsers/actions.ts
|
|
1180
|
+
import * as z2 from "zod";
|
|
1181
|
+
|
|
1182
|
+
// src/parsers/base.ts
|
|
1183
|
+
import * as z from "zod";
|
|
1184
|
+
var accountParser = z.string().regex(/^[.1-5a-z]{0,12}[.1-5a-j]?$/);
|
|
1185
|
+
var authorizationParser = z.object({
|
|
1186
|
+
actor: accountParser,
|
|
1187
|
+
permission: z.string()
|
|
1188
|
+
});
|
|
1189
|
+
var authorizationsParser = z.array(authorizationParser).min(1);
|
|
1190
|
+
var ExtendedAssetParser = z.object({
|
|
1191
|
+
quantity: z.string(),
|
|
1192
|
+
contract: accountParser
|
|
1193
|
+
});
|
|
1194
|
+
|
|
1195
|
+
// src/parsers/actions.ts
|
|
1196
|
+
var actionParser = z2.object({
|
|
1197
|
+
account: z2.string(),
|
|
1198
|
+
name: z2.string(),
|
|
1199
|
+
authorization: z2.array(
|
|
1200
|
+
z2.object({
|
|
1201
|
+
actor: z2.string(),
|
|
1202
|
+
permission: z2.string()
|
|
1203
|
+
})
|
|
1204
|
+
),
|
|
1205
|
+
data: z2.any(),
|
|
1206
|
+
hex_data: z2.string().optional()
|
|
1207
|
+
});
|
|
1208
|
+
var transactionExtensionsParser = z2.array(z2.number().or(z2.string())).optional();
|
|
1209
|
+
var rawTransactionParser = z2.object({
|
|
1210
|
+
expiration: z2.string(),
|
|
1211
|
+
ref_block_num: z2.number(),
|
|
1212
|
+
ref_block_prefix: z2.number(),
|
|
1213
|
+
max_net_usage_words: z2.number(),
|
|
1214
|
+
max_cpu_usage_ms: z2.number(),
|
|
1215
|
+
delay_sec: z2.number(),
|
|
1216
|
+
context_free_actions: z2.array(actionParser),
|
|
1217
|
+
transaction_extensions: z2.array(transactionExtensionsParser)
|
|
1218
|
+
});
|
|
1219
|
+
var baseActionParser = (contract, action, data) => z2.object({
|
|
1220
|
+
account: contract === "*" ? accountParser : z2.literal(contract),
|
|
1221
|
+
name: z2.literal(action),
|
|
1222
|
+
data: z2.object(data),
|
|
1223
|
+
authorization: authorizationsParser
|
|
1224
|
+
});
|
|
1225
|
+
var baseActionSerializedParser = (contract, action, data) => z2.object({
|
|
1226
|
+
account: contract === "*" ? accountParser : z2.literal(contract),
|
|
1227
|
+
name: z2.literal(action),
|
|
1228
|
+
data: z2.string().or(z2.object(data)),
|
|
1229
|
+
authorization: authorizationsParser
|
|
1230
|
+
});
|
|
1231
|
+
var webauthActionParser = (contract, action, data) => z2.object({
|
|
1232
|
+
account: z2.literal("webauthn"),
|
|
1233
|
+
name: z2.literal("exec"),
|
|
1234
|
+
data: z2.object({
|
|
1235
|
+
account: accountParser,
|
|
1236
|
+
key: z2.object({
|
|
1237
|
+
key: z2.array(z2.string().or(z2.object({
|
|
1238
|
+
modulus: z2.string(),
|
|
1239
|
+
exponent: z2.string()
|
|
1240
|
+
}))),
|
|
1241
|
+
user_presence: z2.number(),
|
|
1242
|
+
rpid: z2.string()
|
|
1243
|
+
}),
|
|
1244
|
+
nonce: z2.number(),
|
|
1245
|
+
permissions: authorizationsParser,
|
|
1246
|
+
signature: z2.object({
|
|
1247
|
+
auth_data: z2.string(),
|
|
1248
|
+
client_json: z2.string(),
|
|
1249
|
+
signature: z2.string()
|
|
1250
|
+
}),
|
|
1251
|
+
trx: rawTransactionParser.merge(
|
|
1252
|
+
z2.object({
|
|
1253
|
+
actions: z2.array(
|
|
1254
|
+
baseActionSerializedParser(contract, action, data)
|
|
1255
|
+
).length(1)
|
|
1256
|
+
})
|
|
1257
|
+
)
|
|
1258
|
+
}),
|
|
1259
|
+
authorization: authorizationsParser
|
|
1260
|
+
});
|
|
1261
|
+
var singleActionTransactionParser = (contract, action, data) => {
|
|
1262
|
+
const baseAction = baseActionParser(contract, action, data);
|
|
1263
|
+
const webauthAction = webauthActionParser(contract, action, data);
|
|
1264
|
+
return rawTransactionParser.merge(z2.object({
|
|
1265
|
+
actions: z2.array(baseAction.or(webauthAction)).length(1)
|
|
1266
|
+
}));
|
|
1267
|
+
};
|
|
1268
|
+
|
|
1269
|
+
// src/parsers/address.ts
|
|
1270
|
+
import * as z4 from "zod";
|
|
1271
|
+
|
|
1272
|
+
// src/parsers/auth.ts
|
|
1273
|
+
import * as z3 from "zod";
|
|
1274
|
+
|
|
1275
|
+
// src/constants.ts
|
|
1276
|
+
var WRAP_CONTRACT = "proton.wrap";
|
|
1277
|
+
var WRAP_AUTH_ACTION = "generateauth";
|
|
1278
|
+
var FEE_FACTOR = 1e4;
|
|
1279
|
+
var initializeConstants = (chain) => {
|
|
1280
|
+
const { swapCoins, bridgeCoins, allEnabledCoins, allCoins, lendCoins, borrowCoins, loanCoins } = initializeCoins(chain);
|
|
1281
|
+
const constants = {
|
|
1282
|
+
SWAP_CONTRACT: "proton.swaps",
|
|
1283
|
+
DEX_CONTRACT: "dex",
|
|
1284
|
+
FEE_FACTOR,
|
|
1285
|
+
GOOGLE_MAPS_KEY: "AIzaSyDb2_CrK032kSIqBXbkdwmaLKWELl0SxVs",
|
|
1286
|
+
SWAP_URL: chain === "proton" ? "https://otc.protonswap.com" : "https://otc-test.protonswap.com",
|
|
1287
|
+
WRAP_SERVER_URL: chain === "proton" ? "https://www.api.bloks.io/proton-wrap-public2" : "https://www.api.bloks.io/proton-wrap-testnet-public2",
|
|
1288
|
+
WRAP_CONTRACT,
|
|
1289
|
+
WRAP_ACTIONS: {
|
|
1290
|
+
SAVE_ADDRESS: "saveaddress2",
|
|
1291
|
+
DELETE_ADDRESS: "deladdress2",
|
|
1292
|
+
WRAP_START: "wrapstart2",
|
|
1293
|
+
WRAP_FINISH: "wrapfinish2",
|
|
1294
|
+
WRAP_PROCESS: "wrapprocess2",
|
|
1295
|
+
WRAP_SET_CONF: "wrapsetconf2"
|
|
1296
|
+
},
|
|
1297
|
+
WRAP_TABLES: {
|
|
1298
|
+
ADDRESSES: "addresses2",
|
|
1299
|
+
WRAPS: "wraps2"
|
|
1300
|
+
},
|
|
1301
|
+
ADDRESSES_INDEXES: {
|
|
1302
|
+
BY_ACCOUNT: 2,
|
|
1303
|
+
BY_ADDR_HASH: 3
|
|
1304
|
+
},
|
|
1305
|
+
WRAPS_INDEXES: {
|
|
1306
|
+
BY_ACCOUNT: 2,
|
|
1307
|
+
BY_STATUS: 3,
|
|
1308
|
+
BY_WRAP_HASH: 4
|
|
1309
|
+
},
|
|
1310
|
+
WRAP_PROCESS_TIMER: 5e3,
|
|
1311
|
+
FARM_CONTRACT: "yield.farms",
|
|
1312
|
+
WEBHOOK_PERMISSION: "webhook",
|
|
1313
|
+
PUBLIC_PERMISSION: "public",
|
|
1314
|
+
LIGHT_PERMISSION: "light",
|
|
1315
|
+
WRAP_AUTH_ACTION,
|
|
1316
|
+
METAL_ENDPOINT: chain === "proton" ? "https://cirrus.metalpay.com" : "https://cirrus-dev.metalpay.com",
|
|
1317
|
+
METAL_PROTON_ENDPOINT: chain === "proton" ? "https://api.protonchain.com" : "https://api-dev.protonchain.com",
|
|
1318
|
+
METAL_DEX_HTTP_ENDPOINT: chain === "proton" ? "https://metal-dexdb.global.binfra.one/dex" : "https://metallicus-dbapi-dev01.binfra.one/dex",
|
|
1319
|
+
METAL_DEX_WS_ENDPOINT: chain === "proton" ? "wss://metal-dexdb.global.binfra.one/dexws" : "wss://metallicus-dbapi-dev01.binfra.one/dexws",
|
|
1320
|
+
PROTON_ENDPOINTS: chain === "proton" ? ["https://metal-proton-rpc.global.binfra.one", "https://proton.greymass.com", "https://proton.eoscafeblock.com", "https://proton.cryptolions.io", "https://proton.eosusa.news"] : ["https://metal-protontest-rpc.global.binfra.one", "https://testnet.protonchain.com"],
|
|
1321
|
+
CHAIN_ID: chain === "proton" ? "384da888112027f0321850a169f737c33e53b388aad48b5adace4bab97f437e0" : "71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abeaf3d3dd",
|
|
1322
|
+
DEX_PROCESS_SIZE: 30,
|
|
1323
|
+
DEX_SLTPPROCESS_SIZE: 10,
|
|
1324
|
+
MAX_PRICE: "9223372036854775806",
|
|
1325
|
+
MAX_ITEMS_PER_PAGE_DESKTOP: 25,
|
|
1326
|
+
MIN_PRICE: 1,
|
|
1327
|
+
DEFAULT_DEX_SYMBOL: chain === "proton" ? "XPR_XMD" : "XPR_XUSDC",
|
|
1328
|
+
CHAIN: chain,
|
|
1329
|
+
SWAP_COINS: swapCoins,
|
|
1330
|
+
BRIDGE_COINS: bridgeCoins,
|
|
1331
|
+
ALL_ENABLED_COINS: allEnabledCoins,
|
|
1332
|
+
LEND_COINS: lendCoins,
|
|
1333
|
+
BORROW_COINS: borrowCoins,
|
|
1334
|
+
LOAN_COINS: loanCoins,
|
|
1335
|
+
ALL_COINS: allCoins,
|
|
1336
|
+
findBridgeCoinWalletByXtokenAndChain(xtokenSymbol, chain2) {
|
|
1337
|
+
const bridgeCoin = constants.BRIDGE_COINS.find((bridgeCoin2) => bridgeCoin2.xtokenSymbol === xtokenSymbol);
|
|
1338
|
+
if (!bridgeCoin)
|
|
1339
|
+
return void 0;
|
|
1340
|
+
const bridgeWallet = bridgeCoin.wallets.find((bridgeWallet2) => bridgeWallet2.chain === chain2);
|
|
1341
|
+
if (!bridgeWallet)
|
|
1342
|
+
return void 0;
|
|
1343
|
+
return {
|
|
1344
|
+
...bridgeCoin,
|
|
1345
|
+
...bridgeWallet
|
|
1346
|
+
};
|
|
1347
|
+
},
|
|
1348
|
+
findBridgeCoinWallet(coin, wallet) {
|
|
1349
|
+
const bridgeCoin = constants.BRIDGE_COINS.find((bridgeCoin2) => bridgeCoin2.coin === coin);
|
|
1350
|
+
if (!bridgeCoin)
|
|
1351
|
+
return void 0;
|
|
1352
|
+
const bridgeWallet = bridgeCoin.wallets.find((bridgeWallet2) => bridgeWallet2.wallet === wallet);
|
|
1353
|
+
if (!bridgeWallet)
|
|
1354
|
+
return void 0;
|
|
1355
|
+
return {
|
|
1356
|
+
...bridgeCoin,
|
|
1357
|
+
...bridgeWallet
|
|
1358
|
+
};
|
|
1359
|
+
},
|
|
1360
|
+
findBridgeCoinNetwork(coin, network) {
|
|
1361
|
+
const bridgeCoin = constants.BRIDGE_COINS.find((bridgeCoin2) => bridgeCoin2.coin === coin);
|
|
1362
|
+
if (!bridgeCoin)
|
|
1363
|
+
return void 0;
|
|
1364
|
+
const bridgeWallet = bridgeCoin.wallets.find((bridgeWallet2) => bridgeWallet2.network === network);
|
|
1365
|
+
if (!bridgeWallet)
|
|
1366
|
+
return void 0;
|
|
1367
|
+
return {
|
|
1368
|
+
...bridgeCoin,
|
|
1369
|
+
...bridgeWallet
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
};
|
|
1373
|
+
return constants;
|
|
1374
|
+
};
|
|
1375
|
+
|
|
1376
|
+
// src/parsers/auth.ts
|
|
1377
|
+
var createAbstractAuthParser = (contract, action, data) => {
|
|
1378
|
+
return z3.object({
|
|
1379
|
+
signer: authorizationParser,
|
|
1380
|
+
signatures: z3.array(z3.string()).length(1),
|
|
1381
|
+
transaction: singleActionTransactionParser(contract, action, data)
|
|
1382
|
+
});
|
|
1383
|
+
};
|
|
1384
|
+
var generateAuthData = {
|
|
1385
|
+
time: z3.string(),
|
|
1386
|
+
protonAccount: z3.string()
|
|
1387
|
+
};
|
|
1388
|
+
var generateAuthActionsBaseParser = baseActionParser(WRAP_CONTRACT, WRAP_AUTH_ACTION, generateAuthData);
|
|
1389
|
+
var generateAuthParser = createAbstractAuthParser(WRAP_CONTRACT, WRAP_AUTH_ACTION, generateAuthData);
|
|
1390
|
+
|
|
1391
|
+
// src/parsers/address.ts
|
|
1392
|
+
var addressParser = z4.object({
|
|
1393
|
+
index: z4.number(),
|
|
1394
|
+
account: accountParser,
|
|
1395
|
+
chain: z4.string(),
|
|
1396
|
+
address: z4.string(),
|
|
1397
|
+
address_hash: z4.string()
|
|
1398
|
+
});
|
|
1399
|
+
var generateAddressBodyParser = z4.object({
|
|
1400
|
+
coin: z4.string(),
|
|
1401
|
+
wallet: z4.string()
|
|
1402
|
+
}).merge(generateAuthParser);
|
|
1403
|
+
var generateAddressResponse = z4.object({
|
|
1404
|
+
id: z4.string(),
|
|
1405
|
+
// "2448834505708930950",
|
|
1406
|
+
address: z4.string(),
|
|
1407
|
+
// "0x617C03C1E2Bf81C062A4CEfbE312c070E1d86d18",
|
|
1408
|
+
coin: z4.string(),
|
|
1409
|
+
// "ETH",
|
|
1410
|
+
wallet: z4.string(),
|
|
1411
|
+
// "ETH",
|
|
1412
|
+
memo: z4.string().optional()
|
|
1413
|
+
});
|
|
1414
|
+
|
|
1415
|
+
// src/parsers/currency.ts
|
|
1416
|
+
import * as z5 from "zod";
|
|
1417
|
+
var rateParser = z5.object({
|
|
1418
|
+
counterCurrency: z5.string(),
|
|
1419
|
+
price: z5.number(),
|
|
1420
|
+
priceChangePercent: z5.number(),
|
|
1421
|
+
marketCap: z5.number(),
|
|
1422
|
+
volume: z5.number(),
|
|
1423
|
+
timestamp: z5.number()
|
|
1424
|
+
});
|
|
1425
|
+
var exchangeRateParser = z5.object({
|
|
1426
|
+
contract: z5.string(),
|
|
1427
|
+
symbol: z5.string(),
|
|
1428
|
+
rank: z5.number(),
|
|
1429
|
+
rates: z5.array(rateParser)
|
|
1430
|
+
});
|
|
1431
|
+
var exchangeRatesParser = z5.array(exchangeRateParser);
|
|
1432
|
+
var bloksRatesParser = z5.array(z5.object({
|
|
1433
|
+
contract: z5.string(),
|
|
1434
|
+
symbol: z5.string(),
|
|
1435
|
+
rank: z5.number(),
|
|
1436
|
+
rates: z5.array(rateParser)
|
|
1437
|
+
}));
|
|
1438
|
+
|
|
1439
|
+
// src/parsers/deposit.ts
|
|
1440
|
+
import * as z6 from "zod";
|
|
1441
|
+
var Type = /* @__PURE__ */ ((Type2) => {
|
|
1442
|
+
Type2["RECEIVE"] = "receive";
|
|
1443
|
+
Type2["SEND"] = "send";
|
|
1444
|
+
return Type2;
|
|
1445
|
+
})(Type || {});
|
|
1446
|
+
var depositBodyParser = z6.object({
|
|
1447
|
+
id: z6.string(),
|
|
1448
|
+
// "0x000010203121388fac991"
|
|
1449
|
+
type: z6.nativeEnum(Type),
|
|
1450
|
+
// "receive" or "send"
|
|
1451
|
+
hash: z6.string(),
|
|
1452
|
+
// "0x000010203121388fac991"
|
|
1453
|
+
coin: z6.string(),
|
|
1454
|
+
// "ETH" or "XPR"
|
|
1455
|
+
wallet: z6.string(),
|
|
1456
|
+
// "ETH-ROPSTEN" or "XPR-MAINNET"
|
|
1457
|
+
network: z6.string()
|
|
1458
|
+
// "erc29"
|
|
1459
|
+
});
|
|
1460
|
+
var transactionParser = z6.object({
|
|
1461
|
+
id: z6.string(),
|
|
1462
|
+
// "2629304740076324677"
|
|
1463
|
+
wallet: z6.string(),
|
|
1464
|
+
// "ETH"
|
|
1465
|
+
value: z6.number(),
|
|
1466
|
+
// 10000000000000000
|
|
1467
|
+
valueString: z6.string(),
|
|
1468
|
+
// "10000000000000000"
|
|
1469
|
+
address: z6.string(),
|
|
1470
|
+
// "0x0000"
|
|
1471
|
+
type: z6.nativeEnum(Type),
|
|
1472
|
+
// "receive" or "send"
|
|
1473
|
+
state: z6.string(),
|
|
1474
|
+
// "confirmed"
|
|
1475
|
+
confirmations: z6.number(),
|
|
1476
|
+
// 1
|
|
1477
|
+
hash: z6.string(),
|
|
1478
|
+
// "b4781422be95fee8fbbf720e3e0fa9705ae834474ef25f5724cdd0f5d23211ed"
|
|
1479
|
+
blockHash: z6.string().optional().nullable(),
|
|
1480
|
+
// "000000000000000000089b270eb99f75107d6a9cde37ec944cb80a2998df7b43"
|
|
1481
|
+
blockHeight: z6.number().optional().nullable()
|
|
1482
|
+
// 643159
|
|
1483
|
+
});
|
|
1484
|
+
|
|
1485
|
+
// src/parsers/otc.ts
|
|
1486
|
+
import * as z7 from "zod";
|
|
1487
|
+
var otcOrderResponseParser = z7.object({
|
|
1488
|
+
success: z7.boolean(),
|
|
1489
|
+
transaction_id: z7.string(),
|
|
1490
|
+
errormsg: z7.string().optional()
|
|
1491
|
+
});
|
|
1492
|
+
var otcQuoteBodyParser = z7.object({
|
|
1493
|
+
baseAmount: z7.number(),
|
|
1494
|
+
baseSymbol: z7.string(),
|
|
1495
|
+
quoteSymbol: z7.string()
|
|
1496
|
+
});
|
|
1497
|
+
var otcQuoteResponseParser = z7.object({
|
|
1498
|
+
success: z7.boolean(),
|
|
1499
|
+
token: z7.string(),
|
|
1500
|
+
qty: z7.number(),
|
|
1501
|
+
errormsg: z7.string().optional()
|
|
1502
|
+
});
|
|
1503
|
+
|
|
1504
|
+
// src/parsers/withdraw.ts
|
|
1505
|
+
import * as z8 from "zod";
|
|
1506
|
+
var withdrawData = {
|
|
1507
|
+
from: z8.string().refine((val) => val !== WRAP_CONTRACT, {
|
|
1508
|
+
message: `${WRAP_CONTRACT} must be receiver`
|
|
1509
|
+
}),
|
|
1510
|
+
to: z8.literal(WRAP_CONTRACT),
|
|
1511
|
+
quantity: z8.string(),
|
|
1512
|
+
memo: z8.string()
|
|
1513
|
+
};
|
|
1514
|
+
var withdrawBodyBaseAction = baseActionParser("*", "transfer", withdrawData);
|
|
1515
|
+
var withdrawBodyParser = z8.object({
|
|
1516
|
+
signer: authorizationParser,
|
|
1517
|
+
signatures: z8.array(z8.string()).length(1),
|
|
1518
|
+
transaction: singleActionTransactionParser("*", "transfer", withdrawData),
|
|
1519
|
+
quoteId: z8.string(),
|
|
1520
|
+
provider: z8.string().optional()
|
|
1521
|
+
});
|
|
1522
|
+
var withdrawMetalResponseParser = z8.object({
|
|
1523
|
+
success: z8.boolean(),
|
|
1524
|
+
id: z8.string()
|
|
1525
|
+
});
|
|
1526
|
+
var withdrawalFeeQuoteParser = z8.object({
|
|
1527
|
+
quoteId: z8.string(),
|
|
1528
|
+
estimatedFee: z8.string(),
|
|
1529
|
+
currency: z8.string(),
|
|
1530
|
+
network: z8.string()
|
|
1531
|
+
});
|
|
1532
|
+
|
|
1533
|
+
// src/parsers/withdrawalHistory.ts
|
|
1534
|
+
import * as z9 from "zod";
|
|
1535
|
+
var withdrawHistoryMetalSwapParser = z9.object({
|
|
1536
|
+
id: z9.string(),
|
|
1537
|
+
status: z9.string(),
|
|
1538
|
+
amount: z9.string(),
|
|
1539
|
+
currency: z9.string(),
|
|
1540
|
+
network: z9.string(),
|
|
1541
|
+
created: z9.string(),
|
|
1542
|
+
withdrawalAddress: z9.string(),
|
|
1543
|
+
withdrawalHash: z9.string().optional()
|
|
1544
|
+
});
|
|
1545
|
+
var withdrawHistoryMetalResponseParser = z9.object({
|
|
1546
|
+
swaps: z9.array(withdrawHistoryMetalSwapParser),
|
|
1547
|
+
page: z9.number(),
|
|
1548
|
+
pageSize: z9.number(),
|
|
1549
|
+
numberOfElements: z9.number(),
|
|
1550
|
+
totalPages: z9.number(),
|
|
1551
|
+
totalElements: z9.number()
|
|
1552
|
+
});
|
|
1553
|
+
|
|
1554
|
+
// src/parsers/wrap.ts
|
|
1555
|
+
import * as z10 from "zod";
|
|
1556
|
+
var Status = /* @__PURE__ */ ((Status2) => {
|
|
1557
|
+
Status2["PENDING"] = "pending";
|
|
1558
|
+
Status2["SUCCESS"] = "success";
|
|
1559
|
+
Status2["FAIL"] = "fail";
|
|
1560
|
+
Status2["PROCESSING"] = "processing";
|
|
1561
|
+
return Status2;
|
|
1562
|
+
})(Status || {});
|
|
1563
|
+
var wrapStartParser = z10.object({
|
|
1564
|
+
balance: ExtendedAssetParser,
|
|
1565
|
+
id: z10.string(),
|
|
1566
|
+
txid: z10.string(),
|
|
1567
|
+
chain: z10.string(),
|
|
1568
|
+
deposit_address: z10.string(),
|
|
1569
|
+
confirmations: z10.number()
|
|
1570
|
+
});
|
|
1571
|
+
var wrapSetConfParser = z10.object({
|
|
1572
|
+
wrap_hash: z10.string(),
|
|
1573
|
+
confirmations: z10.number()
|
|
1574
|
+
});
|
|
1575
|
+
var wrapParser = z10.object({
|
|
1576
|
+
index: z10.number(),
|
|
1577
|
+
proton_account: z10.string(),
|
|
1578
|
+
balance: ExtendedAssetParser,
|
|
1579
|
+
id: z10.string(),
|
|
1580
|
+
txid: z10.string(),
|
|
1581
|
+
chain: z10.string(),
|
|
1582
|
+
deposit_address: z10.string(),
|
|
1583
|
+
status: z10.nativeEnum(Status),
|
|
1584
|
+
finish_txid: z10.string(),
|
|
1585
|
+
wrap_hash: z10.string(),
|
|
1586
|
+
confirmations: z10.number()
|
|
1587
|
+
});
|
|
1588
|
+
|
|
1589
|
+
// src/parsers/dex.ts
|
|
1590
|
+
import * as z11 from "zod";
|
|
1591
|
+
var ohlcvParser = z11.object({
|
|
1592
|
+
time: z11.number(),
|
|
1593
|
+
open: z11.number(),
|
|
1594
|
+
high: z11.number(),
|
|
1595
|
+
low: z11.number(),
|
|
1596
|
+
close: z11.number(),
|
|
1597
|
+
volume: z11.number(),
|
|
1598
|
+
volume_bid: z11.number(),
|
|
1599
|
+
count: z11.number()
|
|
1600
|
+
});
|
|
1601
|
+
var getOhlcvParser = z11.object({
|
|
1602
|
+
interval: z11.string(),
|
|
1603
|
+
from: z11.string(),
|
|
1604
|
+
to: z11.string(),
|
|
1605
|
+
symbol: z11.string(),
|
|
1606
|
+
limit: z11.string().default("500").refine((n) => +n <= 1e3, "Max limit is 1000")
|
|
1607
|
+
});
|
|
1608
|
+
var getOhlcvResponseParser = z11.object({
|
|
1609
|
+
sync: z11.number(),
|
|
1610
|
+
data: z11.array(ohlcvParser)
|
|
1611
|
+
});
|
|
1612
|
+
var orderHistoryParser = z11.object({
|
|
1613
|
+
seq: z11.number(),
|
|
1614
|
+
block_num: z11.number(),
|
|
1615
|
+
block_time: z11.string(),
|
|
1616
|
+
order_id: z11.number(),
|
|
1617
|
+
market_id: z11.number(),
|
|
1618
|
+
quantity_init: z11.number().optional(),
|
|
1619
|
+
quantity_curr: z11.number(),
|
|
1620
|
+
price: z11.number(),
|
|
1621
|
+
account_name: z11.string(),
|
|
1622
|
+
order_side: z11.number(),
|
|
1623
|
+
order_type: z11.number(),
|
|
1624
|
+
trigger_price: z11.number(),
|
|
1625
|
+
fill_type: z11.number(),
|
|
1626
|
+
status: z11.string(),
|
|
1627
|
+
quantity_change: z11.number(),
|
|
1628
|
+
trx_id: z11.string()
|
|
1629
|
+
});
|
|
1630
|
+
var getOpenOrdersParser = z11.object({
|
|
1631
|
+
account: z11.string(),
|
|
1632
|
+
symbol: z11.string().optional(),
|
|
1633
|
+
offset: z11.string().default("0"),
|
|
1634
|
+
limit: z11.string().default("100").refine((n) => +n <= 250, "Max limit is 250")
|
|
1635
|
+
});
|
|
1636
|
+
var getOpenOrdersResponseParser = z11.object({
|
|
1637
|
+
sync: z11.number(),
|
|
1638
|
+
count: z11.number(),
|
|
1639
|
+
data: z11.array(orderHistoryParser)
|
|
1640
|
+
});
|
|
1641
|
+
var getOrderHistoryParser = z11.object({
|
|
1642
|
+
account: z11.string(),
|
|
1643
|
+
symbol: z11.string().optional(),
|
|
1644
|
+
offset: z11.string().default("0"),
|
|
1645
|
+
limit: z11.string().default("100").refine((n) => +n <= 250, "Max limit is 250"),
|
|
1646
|
+
trx_id: z11.string().optional(),
|
|
1647
|
+
status: z11.string().optional()
|
|
1648
|
+
});
|
|
1649
|
+
var getOrderHistoryResponseParser = z11.object({
|
|
1650
|
+
sync: z11.number(),
|
|
1651
|
+
count: z11.number(),
|
|
1652
|
+
data: z11.array(orderHistoryParser)
|
|
1653
|
+
});
|
|
1654
|
+
var getOrderParser = z11.object({
|
|
1655
|
+
order_id: z11.string()
|
|
1656
|
+
});
|
|
1657
|
+
var getOrderResponseParser = z11.object({
|
|
1658
|
+
sync: z11.number(),
|
|
1659
|
+
data: z11.array(orderHistoryParser)
|
|
1660
|
+
});
|
|
1661
|
+
var depthParser = z11.object({
|
|
1662
|
+
level: z11.number(),
|
|
1663
|
+
ask: z11.number(),
|
|
1664
|
+
bid: z11.number(),
|
|
1665
|
+
count: z11.number()
|
|
1666
|
+
});
|
|
1667
|
+
var getDepthParser = z11.object({
|
|
1668
|
+
symbol: z11.string(),
|
|
1669
|
+
step: z11.string(),
|
|
1670
|
+
limit: z11.string().default("100").refine((n) => +n <= 250, "Max limit is 250")
|
|
1671
|
+
});
|
|
1672
|
+
var getDepthResponseParser = z11.object({
|
|
1673
|
+
sync: z11.number(),
|
|
1674
|
+
data: z11.object({
|
|
1675
|
+
bids: z11.array(depthParser),
|
|
1676
|
+
asks: z11.array(depthParser)
|
|
1677
|
+
})
|
|
1678
|
+
});
|
|
1679
|
+
var dailyParser = z11.object({
|
|
1680
|
+
market_id: z11.number(),
|
|
1681
|
+
first: z11.number(),
|
|
1682
|
+
last: z11.number(),
|
|
1683
|
+
bid: z11.number(),
|
|
1684
|
+
ask: z11.number(),
|
|
1685
|
+
change_percentage_24hr: z11.number(),
|
|
1686
|
+
high: z11.number(),
|
|
1687
|
+
low: z11.number()
|
|
1688
|
+
});
|
|
1689
|
+
var getDailyResponseParser = z11.object({
|
|
1690
|
+
sync: z11.number(),
|
|
1691
|
+
data: z11.array(dailyParser)
|
|
1692
|
+
});
|
|
1693
|
+
var marketParser = z11.object({
|
|
1694
|
+
market_id: z11.number(),
|
|
1695
|
+
symbol: z11.string(),
|
|
1696
|
+
status_code: z11.number(),
|
|
1697
|
+
type: z11.string(),
|
|
1698
|
+
maker_fee: z11.number(),
|
|
1699
|
+
taker_fee: z11.number(),
|
|
1700
|
+
order_min: z11.number(),
|
|
1701
|
+
bid_token: z11.object({
|
|
1702
|
+
code: z11.string(),
|
|
1703
|
+
precision: z11.number(),
|
|
1704
|
+
contract: z11.string(),
|
|
1705
|
+
multiplier: z11.number()
|
|
1706
|
+
}),
|
|
1707
|
+
ask_token: z11.object({
|
|
1708
|
+
code: z11.string(),
|
|
1709
|
+
precision: z11.number(),
|
|
1710
|
+
contract: z11.string(),
|
|
1711
|
+
multiplier: z11.number()
|
|
1712
|
+
})
|
|
1713
|
+
});
|
|
1714
|
+
var getMarketsResponseParser = z11.object({
|
|
1715
|
+
sync: z11.number(),
|
|
1716
|
+
data: z11.array(marketParser)
|
|
1717
|
+
});
|
|
1718
|
+
var tradeParser = z11.object({
|
|
1719
|
+
block_num: z11.number(),
|
|
1720
|
+
block_time: z11.string(),
|
|
1721
|
+
trade_id: z11.number(),
|
|
1722
|
+
market_id: z11.number(),
|
|
1723
|
+
price: z11.number(),
|
|
1724
|
+
bid_user: z11.string(),
|
|
1725
|
+
bid_user_order_id: z11.number(),
|
|
1726
|
+
bid_total: z11.number(),
|
|
1727
|
+
bid_amount: z11.number(),
|
|
1728
|
+
bid_fee: z11.number(),
|
|
1729
|
+
ask_user: z11.string(),
|
|
1730
|
+
ask_user_order_id: z11.number(),
|
|
1731
|
+
ask_total: z11.number(),
|
|
1732
|
+
ask_amount: z11.number(),
|
|
1733
|
+
ask_fee: z11.number(),
|
|
1734
|
+
order_side: z11.number(),
|
|
1735
|
+
trx_id: z11.string()
|
|
1736
|
+
});
|
|
1737
|
+
var getTradesParser = z11.object({
|
|
1738
|
+
symbol: z11.string(),
|
|
1739
|
+
offset: z11.string().default("0"),
|
|
1740
|
+
limit: z11.string().default("100").refine((n) => +n <= 250, "Max limit is 250")
|
|
1741
|
+
});
|
|
1742
|
+
var getTradesResponseParser = z11.object({
|
|
1743
|
+
sync: z11.number(),
|
|
1744
|
+
data: z11.array(tradeParser)
|
|
1745
|
+
});
|
|
1746
|
+
var getTradeHistoryParser = z11.object({
|
|
1747
|
+
account: z11.string(),
|
|
1748
|
+
symbol: z11.string().optional(),
|
|
1749
|
+
offset: z11.string().default("0"),
|
|
1750
|
+
limit: z11.string().default("100").refine((n) => +n <= 250, "Max limit is 250")
|
|
1751
|
+
});
|
|
1752
|
+
var getTradeHistoryResponseParser = z11.object({
|
|
1753
|
+
sync: z11.number(),
|
|
1754
|
+
count: z11.number(),
|
|
1755
|
+
data: z11.array(tradeParser)
|
|
1756
|
+
});
|
|
1757
|
+
var syncParser = z11.object({
|
|
1758
|
+
sourceid: z11.number(),
|
|
1759
|
+
block_num: z11.string(),
|
|
1760
|
+
block_time: z11.string(),
|
|
1761
|
+
irreversible: z11.string(),
|
|
1762
|
+
is_master: z11.number(),
|
|
1763
|
+
last_updated: z11.string()
|
|
1764
|
+
});
|
|
1765
|
+
var getSyncResponseParser = z11.object({
|
|
1766
|
+
dbSecondsBehind: z11.number(),
|
|
1767
|
+
chronicleSecondsBehind: z11.number(),
|
|
1768
|
+
maxSecondsBehind: z11.number()
|
|
1769
|
+
});
|
|
1770
|
+
var refferalTotalParser = z11.object({
|
|
1771
|
+
referrer: z11.string(),
|
|
1772
|
+
market_id: z11.number(),
|
|
1773
|
+
bid_fee: z11.number(),
|
|
1774
|
+
bid_total: z11.number(),
|
|
1775
|
+
ask_fee: z11.number(),
|
|
1776
|
+
ask_total: z11.number()
|
|
1777
|
+
});
|
|
1778
|
+
var getReferralTotalsParser = z11.object({
|
|
1779
|
+
referrer: z11.string()
|
|
1780
|
+
});
|
|
1781
|
+
var getReferralTotalsResponseParser = z11.object({
|
|
1782
|
+
sync: z11.number(),
|
|
1783
|
+
data: z11.array(refferalTotalParser)
|
|
1784
|
+
});
|
|
1785
|
+
var refferalParser = z11.object({
|
|
1786
|
+
referred_user: z11.string()
|
|
1787
|
+
});
|
|
1788
|
+
var getReferralsParser = z11.object({
|
|
1789
|
+
referrer: z11.string()
|
|
1790
|
+
});
|
|
1791
|
+
var getReferralsResponseParser = z11.object({
|
|
1792
|
+
sync: z11.number(),
|
|
1793
|
+
data: z11.array(refferalParser)
|
|
1794
|
+
});
|
|
1795
|
+
var leaderboardParser = z11.object({
|
|
1796
|
+
user: z11.string(),
|
|
1797
|
+
total: z11.number()
|
|
1798
|
+
});
|
|
1799
|
+
var getLeaderboardParser = z11.object({
|
|
1800
|
+
market_ids: z11.array(z11.string()),
|
|
1801
|
+
from: z11.string(),
|
|
1802
|
+
to: z11.string()
|
|
1803
|
+
});
|
|
1804
|
+
var getLeaderboardResponseParser = z11.object({
|
|
1805
|
+
sync: z11.number(),
|
|
1806
|
+
data: z11.array(leaderboardParser)
|
|
1807
|
+
});
|
|
1808
|
+
var orderType = /* @__PURE__ */ ((orderType2) => {
|
|
1809
|
+
orderType2[orderType2["ORDERBOOK"] = 0] = "ORDERBOOK";
|
|
1810
|
+
orderType2[orderType2["LIMIT"] = 1] = "LIMIT";
|
|
1811
|
+
orderType2[orderType2["STOPLOSS"] = 2] = "STOPLOSS";
|
|
1812
|
+
orderType2[orderType2["TAKEPROFIT"] = 3] = "TAKEPROFIT";
|
|
1813
|
+
return orderType2;
|
|
1814
|
+
})(orderType || {});
|
|
1815
|
+
var orderSide = /* @__PURE__ */ ((orderSide2) => {
|
|
1816
|
+
orderSide2[orderSide2["INVALID"] = 0] = "INVALID";
|
|
1817
|
+
orderSide2[orderSide2["BUY"] = 1] = "BUY";
|
|
1818
|
+
orderSide2[orderSide2["SELL"] = 2] = "SELL";
|
|
1819
|
+
return orderSide2;
|
|
1820
|
+
})(orderSide || {});
|
|
1821
|
+
var fillType = /* @__PURE__ */ ((fillType2) => {
|
|
1822
|
+
fillType2[fillType2["GTC"] = 0] = "GTC";
|
|
1823
|
+
fillType2[fillType2["IOC"] = 1] = "IOC";
|
|
1824
|
+
fillType2[fillType2["POST_ONLY"] = 2] = "POST_ONLY";
|
|
1825
|
+
return fillType2;
|
|
1826
|
+
})(fillType || {});
|
|
1827
|
+
var logStatus = /* @__PURE__ */ ((logStatus2) => {
|
|
1828
|
+
logStatus2["CREATE"] = "create";
|
|
1829
|
+
logStatus2["UPDATE"] = "update";
|
|
1830
|
+
logStatus2["TRANSFER"] = "transfer";
|
|
1831
|
+
logStatus2["CANCEL"] = "cancel";
|
|
1832
|
+
logStatus2["DELETE"] = "delete";
|
|
1833
|
+
return logStatus2;
|
|
1834
|
+
})(logStatus || {});
|
|
1835
|
+
var ITopics = /* @__PURE__ */ ((ITopics2) => {
|
|
1836
|
+
ITopics2["TRADES"] = "TRADES";
|
|
1837
|
+
ITopics2["ORDERS"] = "ORDERS";
|
|
1838
|
+
return ITopics2;
|
|
1839
|
+
})(ITopics || {});
|
|
1840
|
+
var TOPICS = {
|
|
1841
|
+
["TRADES" /* TRADES */]: {
|
|
1842
|
+
topic: "TRADES" /* TRADES */
|
|
1843
|
+
},
|
|
1844
|
+
["ORDERS" /* ORDERS */]: {
|
|
1845
|
+
topic: "ORDERS" /* ORDERS */
|
|
1846
|
+
}
|
|
1847
|
+
};
|
|
1848
|
+
|
|
1849
|
+
// src/parsers/login.ts
|
|
1850
|
+
import * as z12 from "zod";
|
|
1851
|
+
var loginAccountParamsV3Parser = z12.object({
|
|
1852
|
+
email: z12.string().optional(),
|
|
1853
|
+
verificationCode: z12.string().optional()
|
|
1854
|
+
}).merge(generateAuthParser);
|
|
1855
|
+
|
|
1856
|
+
// src/utils.ts
|
|
1857
|
+
var isSameToken = (token1, token2) => {
|
|
1858
|
+
return token1.xtokenSymbol === token2.xtokenSymbol && token1.xtokenPrecision === token2.xtokenPrecision && token1.xtokenContract === token2.xtokenContract;
|
|
1859
|
+
};
|
|
1860
|
+
var median = (numbers) => {
|
|
1861
|
+
const sorted = numbers.slice().sort((a, b) => a - b);
|
|
1862
|
+
const middle = Math.floor(sorted.length / 2);
|
|
1863
|
+
if (sorted.length % 2 === 0) {
|
|
1864
|
+
return (sorted[middle - 1] + sorted[middle]) / 2;
|
|
1865
|
+
}
|
|
1866
|
+
return sorted[middle];
|
|
1867
|
+
};
|
|
1868
|
+
|
|
1869
|
+
// src/graph.ts
|
|
1870
|
+
import cloneDeep from "lodash.clonedeep";
|
|
1871
|
+
var INode = class {
|
|
1872
|
+
constructor(key, data) {
|
|
1873
|
+
this.key = key;
|
|
1874
|
+
this.data = {};
|
|
1875
|
+
if (data) {
|
|
1876
|
+
this.data = data;
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
};
|
|
1880
|
+
var ILink = class {
|
|
1881
|
+
constructor(from, to, data) {
|
|
1882
|
+
this.from = from;
|
|
1883
|
+
this.to = to;
|
|
1884
|
+
this.data = {};
|
|
1885
|
+
if (data) {
|
|
1886
|
+
this.data = data;
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
};
|
|
1890
|
+
var Graph = class {
|
|
1891
|
+
constructor() {
|
|
1892
|
+
this.nodes = [];
|
|
1893
|
+
this.links = [];
|
|
1894
|
+
this.lastPathFound = [];
|
|
1895
|
+
this.isEquals = (a, b) => a.key === b.key;
|
|
1896
|
+
}
|
|
1897
|
+
addNode(k, v) {
|
|
1898
|
+
const node = this.findNode(k);
|
|
1899
|
+
if (!node) {
|
|
1900
|
+
this.nodes.push(new INode(k, v));
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
addNodes(...nodes) {
|
|
1904
|
+
nodes.forEach((node) => typeof node === "string" ? this.addNode(node) : this.addNode(node[0], node[1]));
|
|
1905
|
+
}
|
|
1906
|
+
findNode(k) {
|
|
1907
|
+
const inode = new INode(k);
|
|
1908
|
+
return this.nodes.find((node) => this.isEquals(node, inode));
|
|
1909
|
+
}
|
|
1910
|
+
findNodes(...keys) {
|
|
1911
|
+
return keys.map((k) => this.findNode(k));
|
|
1912
|
+
}
|
|
1913
|
+
requireFindNodes(...keys) {
|
|
1914
|
+
const nodes = this.findNodes(...keys);
|
|
1915
|
+
if (nodes.some((n) => n === void 0)) {
|
|
1916
|
+
throw new Error("One of the nodes does not exist");
|
|
1917
|
+
}
|
|
1918
|
+
return nodes;
|
|
1919
|
+
}
|
|
1920
|
+
addLink(nodeA, nodeB, data) {
|
|
1921
|
+
const [inodeA, inodeB] = this.requireFindNodes(nodeA, nodeB);
|
|
1922
|
+
this.links.push(new ILink(inodeA, inodeB, data));
|
|
1923
|
+
}
|
|
1924
|
+
addLinks(...links) {
|
|
1925
|
+
links.forEach((link) => this.addLink(...link));
|
|
1926
|
+
}
|
|
1927
|
+
/**
|
|
1928
|
+
* Get all nodes linked
|
|
1929
|
+
* to from `node`.
|
|
1930
|
+
*/
|
|
1931
|
+
findLinkedNodes(node) {
|
|
1932
|
+
return this.links.reduce((acc, link) => {
|
|
1933
|
+
if (this.isEquals(link.from, node)) {
|
|
1934
|
+
acc.push(link.to);
|
|
1935
|
+
}
|
|
1936
|
+
return acc;
|
|
1937
|
+
}, []);
|
|
1938
|
+
}
|
|
1939
|
+
findAllPaths(from, to) {
|
|
1940
|
+
const allPaths = [];
|
|
1941
|
+
const [fromNode, toNode] = this.requireFindNodes(from, to);
|
|
1942
|
+
const path = [fromNode];
|
|
1943
|
+
let seen = /* @__PURE__ */ new Set();
|
|
1944
|
+
const stuck = (x) => {
|
|
1945
|
+
if (this.isEquals(x, toNode)) {
|
|
1946
|
+
return false;
|
|
1947
|
+
}
|
|
1948
|
+
for (const y of this.findLinkedNodes(x)) {
|
|
1949
|
+
if (!seen.has(y.key)) {
|
|
1950
|
+
seen.add(y.key);
|
|
1951
|
+
if (!stuck(y)) {
|
|
1952
|
+
return false;
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
return true;
|
|
1957
|
+
};
|
|
1958
|
+
const search = (x) => {
|
|
1959
|
+
if (this.isEquals(x, toNode)) {
|
|
1960
|
+
allPaths.push(cloneDeep(path));
|
|
1961
|
+
return;
|
|
1962
|
+
}
|
|
1963
|
+
seen = new Set(path.map((p) => p.key));
|
|
1964
|
+
if (stuck(x)) {
|
|
1965
|
+
return;
|
|
1966
|
+
}
|
|
1967
|
+
for (const y of this.findLinkedNodes(x)) {
|
|
1968
|
+
if (!path.includes(y)) {
|
|
1969
|
+
path.push(y);
|
|
1970
|
+
search(y);
|
|
1971
|
+
path.pop();
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
};
|
|
1975
|
+
search(fromNode);
|
|
1976
|
+
return allPaths;
|
|
1977
|
+
}
|
|
1978
|
+
};
|
|
1979
|
+
|
|
1980
|
+
// node_modules/bignumber.js/bignumber.mjs
|
|
1981
|
+
var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
1982
|
+
var mathceil = Math.ceil;
|
|
1983
|
+
var mathfloor = Math.floor;
|
|
1984
|
+
var bignumberError = "[BigNumber Error] ";
|
|
1985
|
+
var tooManyDigits = bignumberError + "Number primitive has more than 15 significant digits: ";
|
|
1986
|
+
var BASE = 1e14;
|
|
1987
|
+
var LOG_BASE = 14;
|
|
1988
|
+
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
1989
|
+
var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
|
|
1990
|
+
var SQRT_BASE = 1e7;
|
|
1991
|
+
var MAX = 1e9;
|
|
1992
|
+
function clone(configObject) {
|
|
1993
|
+
var div, convertBase, parseNumeric, P = BigNumber2.prototype = { constructor: BigNumber2, toString: null, valueOf: null }, ONE = new BigNumber2(1), DECIMAL_PLACES = 20, ROUNDING_MODE = 4, TO_EXP_NEG = -7, TO_EXP_POS = 21, MIN_EXP = -1e7, MAX_EXP = 1e7, CRYPTO = false, MODULO_MODE = 1, POW_PRECISION = 0, FORMAT = {
|
|
1994
|
+
prefix: "",
|
|
1995
|
+
groupSize: 3,
|
|
1996
|
+
secondaryGroupSize: 0,
|
|
1997
|
+
groupSeparator: ",",
|
|
1998
|
+
decimalSeparator: ".",
|
|
1999
|
+
fractionGroupSize: 0,
|
|
2000
|
+
fractionGroupSeparator: "\xA0",
|
|
2001
|
+
// non-breaking space
|
|
2002
|
+
suffix: ""
|
|
2003
|
+
}, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz", alphabetHasNormalDecimalDigits = true;
|
|
2004
|
+
function BigNumber2(v, b) {
|
|
2005
|
+
var alphabet, c, caseChanged, e, i, isNum, len, str, x = this;
|
|
2006
|
+
if (!(x instanceof BigNumber2))
|
|
2007
|
+
return new BigNumber2(v, b);
|
|
2008
|
+
if (b == null) {
|
|
2009
|
+
if (v && v._isBigNumber === true) {
|
|
2010
|
+
x.s = v.s;
|
|
2011
|
+
if (!v.c || v.e > MAX_EXP) {
|
|
2012
|
+
x.c = x.e = null;
|
|
2013
|
+
} else if (v.e < MIN_EXP) {
|
|
2014
|
+
x.c = [x.e = 0];
|
|
2015
|
+
} else {
|
|
2016
|
+
x.e = v.e;
|
|
2017
|
+
x.c = v.c.slice();
|
|
2018
|
+
}
|
|
2019
|
+
return;
|
|
2020
|
+
}
|
|
2021
|
+
if ((isNum = typeof v == "number") && v * 0 == 0) {
|
|
2022
|
+
x.s = 1 / v < 0 ? (v = -v, -1) : 1;
|
|
2023
|
+
if (v === ~~v) {
|
|
2024
|
+
for (e = 0, i = v; i >= 10; i /= 10, e++)
|
|
2025
|
+
;
|
|
2026
|
+
if (e > MAX_EXP) {
|
|
2027
|
+
x.c = x.e = null;
|
|
2028
|
+
} else {
|
|
2029
|
+
x.e = e;
|
|
2030
|
+
x.c = [v];
|
|
2031
|
+
}
|
|
2032
|
+
return;
|
|
2033
|
+
}
|
|
2034
|
+
str = String(v);
|
|
2035
|
+
} else {
|
|
2036
|
+
if (!isNumeric.test(str = String(v)))
|
|
2037
|
+
return parseNumeric(x, str, isNum);
|
|
2038
|
+
x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
|
|
2039
|
+
}
|
|
2040
|
+
if ((e = str.indexOf(".")) > -1)
|
|
2041
|
+
str = str.replace(".", "");
|
|
2042
|
+
if ((i = str.search(/e/i)) > 0) {
|
|
2043
|
+
if (e < 0)
|
|
2044
|
+
e = i;
|
|
2045
|
+
e += +str.slice(i + 1);
|
|
2046
|
+
str = str.substring(0, i);
|
|
2047
|
+
} else if (e < 0) {
|
|
2048
|
+
e = str.length;
|
|
2049
|
+
}
|
|
2050
|
+
} else {
|
|
2051
|
+
intCheck(b, 2, ALPHABET.length, "Base");
|
|
2052
|
+
if (b == 10 && alphabetHasNormalDecimalDigits) {
|
|
2053
|
+
x = new BigNumber2(v);
|
|
2054
|
+
return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
|
|
2055
|
+
}
|
|
2056
|
+
str = String(v);
|
|
2057
|
+
if (isNum = typeof v == "number") {
|
|
2058
|
+
if (v * 0 != 0)
|
|
2059
|
+
return parseNumeric(x, str, isNum, b);
|
|
2060
|
+
x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
|
|
2061
|
+
if (BigNumber2.DEBUG && str.replace(/^0\.0*|\./, "").length > 15) {
|
|
2062
|
+
throw Error(tooManyDigits + v);
|
|
2063
|
+
}
|
|
2064
|
+
} else {
|
|
2065
|
+
x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
|
|
2066
|
+
}
|
|
2067
|
+
alphabet = ALPHABET.slice(0, b);
|
|
2068
|
+
e = i = 0;
|
|
2069
|
+
for (len = str.length; i < len; i++) {
|
|
2070
|
+
if (alphabet.indexOf(c = str.charAt(i)) < 0) {
|
|
2071
|
+
if (c == ".") {
|
|
2072
|
+
if (i > e) {
|
|
2073
|
+
e = len;
|
|
2074
|
+
continue;
|
|
2075
|
+
}
|
|
2076
|
+
} else if (!caseChanged) {
|
|
2077
|
+
if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
|
|
2078
|
+
caseChanged = true;
|
|
2079
|
+
i = -1;
|
|
2080
|
+
e = 0;
|
|
2081
|
+
continue;
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
return parseNumeric(x, String(v), isNum, b);
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
isNum = false;
|
|
2088
|
+
str = convertBase(str, b, 10, x.s);
|
|
2089
|
+
if ((e = str.indexOf(".")) > -1)
|
|
2090
|
+
str = str.replace(".", "");
|
|
2091
|
+
else
|
|
2092
|
+
e = str.length;
|
|
2093
|
+
}
|
|
2094
|
+
for (i = 0; str.charCodeAt(i) === 48; i++)
|
|
2095
|
+
;
|
|
2096
|
+
for (len = str.length; str.charCodeAt(--len) === 48; )
|
|
2097
|
+
;
|
|
2098
|
+
if (str = str.slice(i, ++len)) {
|
|
2099
|
+
len -= i;
|
|
2100
|
+
if (isNum && BigNumber2.DEBUG && len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) {
|
|
2101
|
+
throw Error(tooManyDigits + x.s * v);
|
|
2102
|
+
}
|
|
2103
|
+
if ((e = e - i - 1) > MAX_EXP) {
|
|
2104
|
+
x.c = x.e = null;
|
|
2105
|
+
} else if (e < MIN_EXP) {
|
|
2106
|
+
x.c = [x.e = 0];
|
|
2107
|
+
} else {
|
|
2108
|
+
x.e = e;
|
|
2109
|
+
x.c = [];
|
|
2110
|
+
i = (e + 1) % LOG_BASE;
|
|
2111
|
+
if (e < 0)
|
|
2112
|
+
i += LOG_BASE;
|
|
2113
|
+
if (i < len) {
|
|
2114
|
+
if (i)
|
|
2115
|
+
x.c.push(+str.slice(0, i));
|
|
2116
|
+
for (len -= LOG_BASE; i < len; ) {
|
|
2117
|
+
x.c.push(+str.slice(i, i += LOG_BASE));
|
|
2118
|
+
}
|
|
2119
|
+
i = LOG_BASE - (str = str.slice(i)).length;
|
|
2120
|
+
} else {
|
|
2121
|
+
i -= len;
|
|
2122
|
+
}
|
|
2123
|
+
for (; i--; str += "0")
|
|
2124
|
+
;
|
|
2125
|
+
x.c.push(+str);
|
|
2126
|
+
}
|
|
2127
|
+
} else {
|
|
2128
|
+
x.c = [x.e = 0];
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
BigNumber2.clone = clone;
|
|
2132
|
+
BigNumber2.ROUND_UP = 0;
|
|
2133
|
+
BigNumber2.ROUND_DOWN = 1;
|
|
2134
|
+
BigNumber2.ROUND_CEIL = 2;
|
|
2135
|
+
BigNumber2.ROUND_FLOOR = 3;
|
|
2136
|
+
BigNumber2.ROUND_HALF_UP = 4;
|
|
2137
|
+
BigNumber2.ROUND_HALF_DOWN = 5;
|
|
2138
|
+
BigNumber2.ROUND_HALF_EVEN = 6;
|
|
2139
|
+
BigNumber2.ROUND_HALF_CEIL = 7;
|
|
2140
|
+
BigNumber2.ROUND_HALF_FLOOR = 8;
|
|
2141
|
+
BigNumber2.EUCLID = 9;
|
|
2142
|
+
BigNumber2.config = BigNumber2.set = function(obj) {
|
|
2143
|
+
var p, v;
|
|
2144
|
+
if (obj != null) {
|
|
2145
|
+
if (typeof obj == "object") {
|
|
2146
|
+
if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
|
|
2147
|
+
v = obj[p];
|
|
2148
|
+
intCheck(v, 0, MAX, p);
|
|
2149
|
+
DECIMAL_PLACES = v;
|
|
2150
|
+
}
|
|
2151
|
+
if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
|
|
2152
|
+
v = obj[p];
|
|
2153
|
+
intCheck(v, 0, 8, p);
|
|
2154
|
+
ROUNDING_MODE = v;
|
|
2155
|
+
}
|
|
2156
|
+
if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
|
|
2157
|
+
v = obj[p];
|
|
2158
|
+
if (v && v.pop) {
|
|
2159
|
+
intCheck(v[0], -MAX, 0, p);
|
|
2160
|
+
intCheck(v[1], 0, MAX, p);
|
|
2161
|
+
TO_EXP_NEG = v[0];
|
|
2162
|
+
TO_EXP_POS = v[1];
|
|
2163
|
+
} else {
|
|
2164
|
+
intCheck(v, -MAX, MAX, p);
|
|
2165
|
+
TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
if (obj.hasOwnProperty(p = "RANGE")) {
|
|
2169
|
+
v = obj[p];
|
|
2170
|
+
if (v && v.pop) {
|
|
2171
|
+
intCheck(v[0], -MAX, -1, p);
|
|
2172
|
+
intCheck(v[1], 1, MAX, p);
|
|
2173
|
+
MIN_EXP = v[0];
|
|
2174
|
+
MAX_EXP = v[1];
|
|
2175
|
+
} else {
|
|
2176
|
+
intCheck(v, -MAX, MAX, p);
|
|
2177
|
+
if (v) {
|
|
2178
|
+
MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
|
|
2179
|
+
} else {
|
|
2180
|
+
throw Error(bignumberError + p + " cannot be zero: " + v);
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
if (obj.hasOwnProperty(p = "CRYPTO")) {
|
|
2185
|
+
v = obj[p];
|
|
2186
|
+
if (v === !!v) {
|
|
2187
|
+
if (v) {
|
|
2188
|
+
if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
|
|
2189
|
+
CRYPTO = v;
|
|
2190
|
+
} else {
|
|
2191
|
+
CRYPTO = !v;
|
|
2192
|
+
throw Error(bignumberError + "crypto unavailable");
|
|
2193
|
+
}
|
|
2194
|
+
} else {
|
|
2195
|
+
CRYPTO = v;
|
|
2196
|
+
}
|
|
2197
|
+
} else {
|
|
2198
|
+
throw Error(bignumberError + p + " not true or false: " + v);
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
if (obj.hasOwnProperty(p = "MODULO_MODE")) {
|
|
2202
|
+
v = obj[p];
|
|
2203
|
+
intCheck(v, 0, 9, p);
|
|
2204
|
+
MODULO_MODE = v;
|
|
2205
|
+
}
|
|
2206
|
+
if (obj.hasOwnProperty(p = "POW_PRECISION")) {
|
|
2207
|
+
v = obj[p];
|
|
2208
|
+
intCheck(v, 0, MAX, p);
|
|
2209
|
+
POW_PRECISION = v;
|
|
2210
|
+
}
|
|
2211
|
+
if (obj.hasOwnProperty(p = "FORMAT")) {
|
|
2212
|
+
v = obj[p];
|
|
2213
|
+
if (typeof v == "object")
|
|
2214
|
+
FORMAT = v;
|
|
2215
|
+
else
|
|
2216
|
+
throw Error(bignumberError + p + " not an object: " + v);
|
|
2217
|
+
}
|
|
2218
|
+
if (obj.hasOwnProperty(p = "ALPHABET")) {
|
|
2219
|
+
v = obj[p];
|
|
2220
|
+
if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
|
|
2221
|
+
alphabetHasNormalDecimalDigits = v.slice(0, 10) == "0123456789";
|
|
2222
|
+
ALPHABET = v;
|
|
2223
|
+
} else {
|
|
2224
|
+
throw Error(bignumberError + p + " invalid: " + v);
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
} else {
|
|
2228
|
+
throw Error(bignumberError + "Object expected: " + obj);
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
return {
|
|
2232
|
+
DECIMAL_PLACES,
|
|
2233
|
+
ROUNDING_MODE,
|
|
2234
|
+
EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
|
|
2235
|
+
RANGE: [MIN_EXP, MAX_EXP],
|
|
2236
|
+
CRYPTO,
|
|
2237
|
+
MODULO_MODE,
|
|
2238
|
+
POW_PRECISION,
|
|
2239
|
+
FORMAT,
|
|
2240
|
+
ALPHABET
|
|
2241
|
+
};
|
|
2242
|
+
};
|
|
2243
|
+
BigNumber2.isBigNumber = function(v) {
|
|
2244
|
+
if (!v || v._isBigNumber !== true)
|
|
2245
|
+
return false;
|
|
2246
|
+
if (!BigNumber2.DEBUG)
|
|
2247
|
+
return true;
|
|
2248
|
+
var i, n, c = v.c, e = v.e, s = v.s;
|
|
2249
|
+
out:
|
|
2250
|
+
if ({}.toString.call(c) == "[object Array]") {
|
|
2251
|
+
if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
|
|
2252
|
+
if (c[0] === 0) {
|
|
2253
|
+
if (e === 0 && c.length === 1)
|
|
2254
|
+
return true;
|
|
2255
|
+
break out;
|
|
2256
|
+
}
|
|
2257
|
+
i = (e + 1) % LOG_BASE;
|
|
2258
|
+
if (i < 1)
|
|
2259
|
+
i += LOG_BASE;
|
|
2260
|
+
if (String(c[0]).length == i) {
|
|
2261
|
+
for (i = 0; i < c.length; i++) {
|
|
2262
|
+
n = c[i];
|
|
2263
|
+
if (n < 0 || n >= BASE || n !== mathfloor(n))
|
|
2264
|
+
break out;
|
|
2265
|
+
}
|
|
2266
|
+
if (n !== 0)
|
|
2267
|
+
return true;
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
} else if (c === null && e === null && (s === null || s === 1 || s === -1)) {
|
|
2271
|
+
return true;
|
|
2272
|
+
}
|
|
2273
|
+
throw Error(bignumberError + "Invalid BigNumber: " + v);
|
|
2274
|
+
};
|
|
2275
|
+
BigNumber2.maximum = BigNumber2.max = function() {
|
|
2276
|
+
return maxOrMin(arguments, P.lt);
|
|
2277
|
+
};
|
|
2278
|
+
BigNumber2.minimum = BigNumber2.min = function() {
|
|
2279
|
+
return maxOrMin(arguments, P.gt);
|
|
2280
|
+
};
|
|
2281
|
+
BigNumber2.random = function() {
|
|
2282
|
+
var pow2_53 = 9007199254740992;
|
|
2283
|
+
var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
|
|
2284
|
+
return mathfloor(Math.random() * pow2_53);
|
|
2285
|
+
} : function() {
|
|
2286
|
+
return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
|
|
2287
|
+
};
|
|
2288
|
+
return function(dp) {
|
|
2289
|
+
var a, b, e, k, v, i = 0, c = [], rand = new BigNumber2(ONE);
|
|
2290
|
+
if (dp == null)
|
|
2291
|
+
dp = DECIMAL_PLACES;
|
|
2292
|
+
else
|
|
2293
|
+
intCheck(dp, 0, MAX);
|
|
2294
|
+
k = mathceil(dp / LOG_BASE);
|
|
2295
|
+
if (CRYPTO) {
|
|
2296
|
+
if (crypto.getRandomValues) {
|
|
2297
|
+
a = crypto.getRandomValues(new Uint32Array(k *= 2));
|
|
2298
|
+
for (; i < k; ) {
|
|
2299
|
+
v = a[i] * 131072 + (a[i + 1] >>> 11);
|
|
2300
|
+
if (v >= 9e15) {
|
|
2301
|
+
b = crypto.getRandomValues(new Uint32Array(2));
|
|
2302
|
+
a[i] = b[0];
|
|
2303
|
+
a[i + 1] = b[1];
|
|
2304
|
+
} else {
|
|
2305
|
+
c.push(v % 1e14);
|
|
2306
|
+
i += 2;
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
i = k / 2;
|
|
2310
|
+
} else if (crypto.randomBytes) {
|
|
2311
|
+
a = crypto.randomBytes(k *= 7);
|
|
2312
|
+
for (; i < k; ) {
|
|
2313
|
+
v = (a[i] & 31) * 281474976710656 + a[i + 1] * 1099511627776 + a[i + 2] * 4294967296 + a[i + 3] * 16777216 + (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];
|
|
2314
|
+
if (v >= 9e15) {
|
|
2315
|
+
crypto.randomBytes(7).copy(a, i);
|
|
2316
|
+
} else {
|
|
2317
|
+
c.push(v % 1e14);
|
|
2318
|
+
i += 7;
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
i = k / 7;
|
|
2322
|
+
} else {
|
|
2323
|
+
CRYPTO = false;
|
|
2324
|
+
throw Error(bignumberError + "crypto unavailable");
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
if (!CRYPTO) {
|
|
2328
|
+
for (; i < k; ) {
|
|
2329
|
+
v = random53bitInt();
|
|
2330
|
+
if (v < 9e15)
|
|
2331
|
+
c[i++] = v % 1e14;
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
k = c[--i];
|
|
2335
|
+
dp %= LOG_BASE;
|
|
2336
|
+
if (k && dp) {
|
|
2337
|
+
v = POWS_TEN[LOG_BASE - dp];
|
|
2338
|
+
c[i] = mathfloor(k / v) * v;
|
|
2339
|
+
}
|
|
2340
|
+
for (; c[i] === 0; c.pop(), i--)
|
|
2341
|
+
;
|
|
2342
|
+
if (i < 0) {
|
|
2343
|
+
c = [e = 0];
|
|
2344
|
+
} else {
|
|
2345
|
+
for (e = -1; c[0] === 0; c.splice(0, 1), e -= LOG_BASE)
|
|
2346
|
+
;
|
|
2347
|
+
for (i = 1, v = c[0]; v >= 10; v /= 10, i++)
|
|
2348
|
+
;
|
|
2349
|
+
if (i < LOG_BASE)
|
|
2350
|
+
e -= LOG_BASE - i;
|
|
2351
|
+
}
|
|
2352
|
+
rand.e = e;
|
|
2353
|
+
rand.c = c;
|
|
2354
|
+
return rand;
|
|
2355
|
+
};
|
|
2356
|
+
}();
|
|
2357
|
+
BigNumber2.sum = function() {
|
|
2358
|
+
var i = 1, args = arguments, sum = new BigNumber2(args[0]);
|
|
2359
|
+
for (; i < args.length; )
|
|
2360
|
+
sum = sum.plus(args[i++]);
|
|
2361
|
+
return sum;
|
|
2362
|
+
};
|
|
2363
|
+
convertBase = function() {
|
|
2364
|
+
var decimal = "0123456789";
|
|
2365
|
+
function toBaseOut(str, baseIn, baseOut, alphabet) {
|
|
2366
|
+
var j, arr = [0], arrL, i = 0, len = str.length;
|
|
2367
|
+
for (; i < len; ) {
|
|
2368
|
+
for (arrL = arr.length; arrL--; arr[arrL] *= baseIn)
|
|
2369
|
+
;
|
|
2370
|
+
arr[0] += alphabet.indexOf(str.charAt(i++));
|
|
2371
|
+
for (j = 0; j < arr.length; j++) {
|
|
2372
|
+
if (arr[j] > baseOut - 1) {
|
|
2373
|
+
if (arr[j + 1] == null)
|
|
2374
|
+
arr[j + 1] = 0;
|
|
2375
|
+
arr[j + 1] += arr[j] / baseOut | 0;
|
|
2376
|
+
arr[j] %= baseOut;
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
return arr.reverse();
|
|
2381
|
+
}
|
|
2382
|
+
return function(str, baseIn, baseOut, sign, callerIsToString) {
|
|
2383
|
+
var alphabet, d, e, k, r, x, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
|
|
2384
|
+
if (i >= 0) {
|
|
2385
|
+
k = POW_PRECISION;
|
|
2386
|
+
POW_PRECISION = 0;
|
|
2387
|
+
str = str.replace(".", "");
|
|
2388
|
+
y = new BigNumber2(baseIn);
|
|
2389
|
+
x = y.pow(str.length - i);
|
|
2390
|
+
POW_PRECISION = k;
|
|
2391
|
+
y.c = toBaseOut(
|
|
2392
|
+
toFixedPoint(coeffToString(x.c), x.e, "0"),
|
|
2393
|
+
10,
|
|
2394
|
+
baseOut,
|
|
2395
|
+
decimal
|
|
2396
|
+
);
|
|
2397
|
+
y.e = y.c.length;
|
|
2398
|
+
}
|
|
2399
|
+
xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet = ALPHABET, decimal) : (alphabet = decimal, ALPHABET));
|
|
2400
|
+
e = k = xc.length;
|
|
2401
|
+
for (; xc[--k] == 0; xc.pop())
|
|
2402
|
+
;
|
|
2403
|
+
if (!xc[0])
|
|
2404
|
+
return alphabet.charAt(0);
|
|
2405
|
+
if (i < 0) {
|
|
2406
|
+
--e;
|
|
2407
|
+
} else {
|
|
2408
|
+
x.c = xc;
|
|
2409
|
+
x.e = e;
|
|
2410
|
+
x.s = sign;
|
|
2411
|
+
x = div(x, y, dp, rm, baseOut);
|
|
2412
|
+
xc = x.c;
|
|
2413
|
+
r = x.r;
|
|
2414
|
+
e = x.e;
|
|
2415
|
+
}
|
|
2416
|
+
d = e + dp + 1;
|
|
2417
|
+
i = xc[d];
|
|
2418
|
+
k = baseOut / 2;
|
|
2419
|
+
r = r || d < 0 || xc[d + 1] != null;
|
|
2420
|
+
r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : i > k || i == k && (rm == 4 || r || rm == 6 && xc[d - 1] & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
2421
|
+
if (d < 1 || !xc[0]) {
|
|
2422
|
+
str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
|
|
2423
|
+
} else {
|
|
2424
|
+
xc.length = d;
|
|
2425
|
+
if (r) {
|
|
2426
|
+
for (--baseOut; ++xc[--d] > baseOut; ) {
|
|
2427
|
+
xc[d] = 0;
|
|
2428
|
+
if (!d) {
|
|
2429
|
+
++e;
|
|
2430
|
+
xc = [1].concat(xc);
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
for (k = xc.length; !xc[--k]; )
|
|
2435
|
+
;
|
|
2436
|
+
for (i = 0, str = ""; i <= k; str += alphabet.charAt(xc[i++]))
|
|
2437
|
+
;
|
|
2438
|
+
str = toFixedPoint(str, e, alphabet.charAt(0));
|
|
2439
|
+
}
|
|
2440
|
+
return str;
|
|
2441
|
+
};
|
|
2442
|
+
}();
|
|
2443
|
+
div = function() {
|
|
2444
|
+
function multiply(x, k, base) {
|
|
2445
|
+
var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
|
|
2446
|
+
for (x = x.slice(); i--; ) {
|
|
2447
|
+
xlo = x[i] % SQRT_BASE;
|
|
2448
|
+
xhi = x[i] / SQRT_BASE | 0;
|
|
2449
|
+
m = khi * xlo + xhi * klo;
|
|
2450
|
+
temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
|
|
2451
|
+
carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
|
|
2452
|
+
x[i] = temp % base;
|
|
2453
|
+
}
|
|
2454
|
+
if (carry)
|
|
2455
|
+
x = [carry].concat(x);
|
|
2456
|
+
return x;
|
|
2457
|
+
}
|
|
2458
|
+
function compare2(a, b, aL, bL) {
|
|
2459
|
+
var i, cmp;
|
|
2460
|
+
if (aL != bL) {
|
|
2461
|
+
cmp = aL > bL ? 1 : -1;
|
|
2462
|
+
} else {
|
|
2463
|
+
for (i = cmp = 0; i < aL; i++) {
|
|
2464
|
+
if (a[i] != b[i]) {
|
|
2465
|
+
cmp = a[i] > b[i] ? 1 : -1;
|
|
2466
|
+
break;
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
return cmp;
|
|
2471
|
+
}
|
|
2472
|
+
function subtract(a, b, aL, base) {
|
|
2473
|
+
var i = 0;
|
|
2474
|
+
for (; aL--; ) {
|
|
2475
|
+
a[aL] -= i;
|
|
2476
|
+
i = a[aL] < b[aL] ? 1 : 0;
|
|
2477
|
+
a[aL] = i * base + a[aL] - b[aL];
|
|
2478
|
+
}
|
|
2479
|
+
for (; !a[0] && a.length > 1; a.splice(0, 1))
|
|
2480
|
+
;
|
|
2481
|
+
}
|
|
2482
|
+
return function(x, y, dp, rm, base) {
|
|
2483
|
+
var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0, yL, yz, s = x.s == y.s ? 1 : -1, xc = x.c, yc = y.c;
|
|
2484
|
+
if (!xc || !xc[0] || !yc || !yc[0]) {
|
|
2485
|
+
return new BigNumber2(
|
|
2486
|
+
// Return NaN if either NaN, or both Infinity or 0.
|
|
2487
|
+
!x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN : (
|
|
2488
|
+
// Return ±0 if x is ±0 or y is ±Infinity, or return ±Infinity as y is ±0.
|
|
2489
|
+
xc && xc[0] == 0 || !yc ? s * 0 : s / 0
|
|
2490
|
+
)
|
|
2491
|
+
);
|
|
2492
|
+
}
|
|
2493
|
+
q = new BigNumber2(s);
|
|
2494
|
+
qc = q.c = [];
|
|
2495
|
+
e = x.e - y.e;
|
|
2496
|
+
s = dp + e + 1;
|
|
2497
|
+
if (!base) {
|
|
2498
|
+
base = BASE;
|
|
2499
|
+
e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
|
|
2500
|
+
s = s / LOG_BASE | 0;
|
|
2501
|
+
}
|
|
2502
|
+
for (i = 0; yc[i] == (xc[i] || 0); i++)
|
|
2503
|
+
;
|
|
2504
|
+
if (yc[i] > (xc[i] || 0))
|
|
2505
|
+
e--;
|
|
2506
|
+
if (s < 0) {
|
|
2507
|
+
qc.push(1);
|
|
2508
|
+
more = true;
|
|
2509
|
+
} else {
|
|
2510
|
+
xL = xc.length;
|
|
2511
|
+
yL = yc.length;
|
|
2512
|
+
i = 0;
|
|
2513
|
+
s += 2;
|
|
2514
|
+
n = mathfloor(base / (yc[0] + 1));
|
|
2515
|
+
if (n > 1) {
|
|
2516
|
+
yc = multiply(yc, n, base);
|
|
2517
|
+
xc = multiply(xc, n, base);
|
|
2518
|
+
yL = yc.length;
|
|
2519
|
+
xL = xc.length;
|
|
2520
|
+
}
|
|
2521
|
+
xi = yL;
|
|
2522
|
+
rem = xc.slice(0, yL);
|
|
2523
|
+
remL = rem.length;
|
|
2524
|
+
for (; remL < yL; rem[remL++] = 0)
|
|
2525
|
+
;
|
|
2526
|
+
yz = yc.slice();
|
|
2527
|
+
yz = [0].concat(yz);
|
|
2528
|
+
yc0 = yc[0];
|
|
2529
|
+
if (yc[1] >= base / 2)
|
|
2530
|
+
yc0++;
|
|
2531
|
+
do {
|
|
2532
|
+
n = 0;
|
|
2533
|
+
cmp = compare2(yc, rem, yL, remL);
|
|
2534
|
+
if (cmp < 0) {
|
|
2535
|
+
rem0 = rem[0];
|
|
2536
|
+
if (yL != remL)
|
|
2537
|
+
rem0 = rem0 * base + (rem[1] || 0);
|
|
2538
|
+
n = mathfloor(rem0 / yc0);
|
|
2539
|
+
if (n > 1) {
|
|
2540
|
+
if (n >= base)
|
|
2541
|
+
n = base - 1;
|
|
2542
|
+
prod = multiply(yc, n, base);
|
|
2543
|
+
prodL = prod.length;
|
|
2544
|
+
remL = rem.length;
|
|
2545
|
+
while (compare2(prod, rem, prodL, remL) == 1) {
|
|
2546
|
+
n--;
|
|
2547
|
+
subtract(prod, yL < prodL ? yz : yc, prodL, base);
|
|
2548
|
+
prodL = prod.length;
|
|
2549
|
+
cmp = 1;
|
|
2550
|
+
}
|
|
2551
|
+
} else {
|
|
2552
|
+
if (n == 0) {
|
|
2553
|
+
cmp = n = 1;
|
|
2554
|
+
}
|
|
2555
|
+
prod = yc.slice();
|
|
2556
|
+
prodL = prod.length;
|
|
2557
|
+
}
|
|
2558
|
+
if (prodL < remL)
|
|
2559
|
+
prod = [0].concat(prod);
|
|
2560
|
+
subtract(rem, prod, remL, base);
|
|
2561
|
+
remL = rem.length;
|
|
2562
|
+
if (cmp == -1) {
|
|
2563
|
+
while (compare2(yc, rem, yL, remL) < 1) {
|
|
2564
|
+
n++;
|
|
2565
|
+
subtract(rem, yL < remL ? yz : yc, remL, base);
|
|
2566
|
+
remL = rem.length;
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
} else if (cmp === 0) {
|
|
2570
|
+
n++;
|
|
2571
|
+
rem = [0];
|
|
2572
|
+
}
|
|
2573
|
+
qc[i++] = n;
|
|
2574
|
+
if (rem[0]) {
|
|
2575
|
+
rem[remL++] = xc[xi] || 0;
|
|
2576
|
+
} else {
|
|
2577
|
+
rem = [xc[xi]];
|
|
2578
|
+
remL = 1;
|
|
2579
|
+
}
|
|
2580
|
+
} while ((xi++ < xL || rem[0] != null) && s--);
|
|
2581
|
+
more = rem[0] != null;
|
|
2582
|
+
if (!qc[0])
|
|
2583
|
+
qc.splice(0, 1);
|
|
2584
|
+
}
|
|
2585
|
+
if (base == BASE) {
|
|
2586
|
+
for (i = 1, s = qc[0]; s >= 10; s /= 10, i++)
|
|
2587
|
+
;
|
|
2588
|
+
round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
|
|
2589
|
+
} else {
|
|
2590
|
+
q.e = e;
|
|
2591
|
+
q.r = +more;
|
|
2592
|
+
}
|
|
2593
|
+
return q;
|
|
2594
|
+
};
|
|
2595
|
+
}();
|
|
2596
|
+
function format(n, i, rm, id) {
|
|
2597
|
+
var c0, e, ne, len, str;
|
|
2598
|
+
if (rm == null)
|
|
2599
|
+
rm = ROUNDING_MODE;
|
|
2600
|
+
else
|
|
2601
|
+
intCheck(rm, 0, 8);
|
|
2602
|
+
if (!n.c)
|
|
2603
|
+
return n.toString();
|
|
2604
|
+
c0 = n.c[0];
|
|
2605
|
+
ne = n.e;
|
|
2606
|
+
if (i == null) {
|
|
2607
|
+
str = coeffToString(n.c);
|
|
2608
|
+
str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS) ? toExponential(str, ne) : toFixedPoint(str, ne, "0");
|
|
2609
|
+
} else {
|
|
2610
|
+
n = round(new BigNumber2(n), i, rm);
|
|
2611
|
+
e = n.e;
|
|
2612
|
+
str = coeffToString(n.c);
|
|
2613
|
+
len = str.length;
|
|
2614
|
+
if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
|
|
2615
|
+
for (; len < i; str += "0", len++)
|
|
2616
|
+
;
|
|
2617
|
+
str = toExponential(str, e);
|
|
2618
|
+
} else {
|
|
2619
|
+
i -= ne;
|
|
2620
|
+
str = toFixedPoint(str, e, "0");
|
|
2621
|
+
if (e + 1 > len) {
|
|
2622
|
+
if (--i > 0)
|
|
2623
|
+
for (str += "."; i--; str += "0")
|
|
2624
|
+
;
|
|
2625
|
+
} else {
|
|
2626
|
+
i += e - len;
|
|
2627
|
+
if (i > 0) {
|
|
2628
|
+
if (e + 1 == len)
|
|
2629
|
+
str += ".";
|
|
2630
|
+
for (; i--; str += "0")
|
|
2631
|
+
;
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
return n.s < 0 && c0 ? "-" + str : str;
|
|
2637
|
+
}
|
|
2638
|
+
function maxOrMin(args, method) {
|
|
2639
|
+
var n, i = 1, m = new BigNumber2(args[0]);
|
|
2640
|
+
for (; i < args.length; i++) {
|
|
2641
|
+
n = new BigNumber2(args[i]);
|
|
2642
|
+
if (!n.s) {
|
|
2643
|
+
m = n;
|
|
2644
|
+
break;
|
|
2645
|
+
} else if (method.call(m, n)) {
|
|
2646
|
+
m = n;
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
return m;
|
|
2650
|
+
}
|
|
2651
|
+
function normalise(n, c, e) {
|
|
2652
|
+
var i = 1, j = c.length;
|
|
2653
|
+
for (; !c[--j]; c.pop())
|
|
2654
|
+
;
|
|
2655
|
+
for (j = c[0]; j >= 10; j /= 10, i++)
|
|
2656
|
+
;
|
|
2657
|
+
if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
|
|
2658
|
+
n.c = n.e = null;
|
|
2659
|
+
} else if (e < MIN_EXP) {
|
|
2660
|
+
n.c = [n.e = 0];
|
|
2661
|
+
} else {
|
|
2662
|
+
n.e = e;
|
|
2663
|
+
n.c = c;
|
|
2664
|
+
}
|
|
2665
|
+
return n;
|
|
2666
|
+
}
|
|
2667
|
+
parseNumeric = function() {
|
|
2668
|
+
var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
|
|
2669
|
+
return function(x, str, isNum, b) {
|
|
2670
|
+
var base, s = isNum ? str : str.replace(whitespaceOrPlus, "");
|
|
2671
|
+
if (isInfinityOrNaN.test(s)) {
|
|
2672
|
+
x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
|
|
2673
|
+
} else {
|
|
2674
|
+
if (!isNum) {
|
|
2675
|
+
s = s.replace(basePrefix, function(m, p1, p2) {
|
|
2676
|
+
base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
|
|
2677
|
+
return !b || b == base ? p1 : m;
|
|
2678
|
+
});
|
|
2679
|
+
if (b) {
|
|
2680
|
+
base = b;
|
|
2681
|
+
s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
|
|
2682
|
+
}
|
|
2683
|
+
if (str != s)
|
|
2684
|
+
return new BigNumber2(s, base);
|
|
2685
|
+
}
|
|
2686
|
+
if (BigNumber2.DEBUG) {
|
|
2687
|
+
throw Error(bignumberError + "Not a" + (b ? " base " + b : "") + " number: " + str);
|
|
2688
|
+
}
|
|
2689
|
+
x.s = null;
|
|
2690
|
+
}
|
|
2691
|
+
x.c = x.e = null;
|
|
2692
|
+
};
|
|
2693
|
+
}();
|
|
2694
|
+
function round(x, sd, rm, r) {
|
|
2695
|
+
var d, i, j, k, n, ni, rd, xc = x.c, pows10 = POWS_TEN;
|
|
2696
|
+
if (xc) {
|
|
2697
|
+
out: {
|
|
2698
|
+
for (d = 1, k = xc[0]; k >= 10; k /= 10, d++)
|
|
2699
|
+
;
|
|
2700
|
+
i = sd - d;
|
|
2701
|
+
if (i < 0) {
|
|
2702
|
+
i += LOG_BASE;
|
|
2703
|
+
j = sd;
|
|
2704
|
+
n = xc[ni = 0];
|
|
2705
|
+
rd = n / pows10[d - j - 1] % 10 | 0;
|
|
2706
|
+
} else {
|
|
2707
|
+
ni = mathceil((i + 1) / LOG_BASE);
|
|
2708
|
+
if (ni >= xc.length) {
|
|
2709
|
+
if (r) {
|
|
2710
|
+
for (; xc.length <= ni; xc.push(0))
|
|
2711
|
+
;
|
|
2712
|
+
n = rd = 0;
|
|
2713
|
+
d = 1;
|
|
2714
|
+
i %= LOG_BASE;
|
|
2715
|
+
j = i - LOG_BASE + 1;
|
|
2716
|
+
} else {
|
|
2717
|
+
break out;
|
|
2718
|
+
}
|
|
2719
|
+
} else {
|
|
2720
|
+
n = k = xc[ni];
|
|
2721
|
+
for (d = 1; k >= 10; k /= 10, d++)
|
|
2722
|
+
;
|
|
2723
|
+
i %= LOG_BASE;
|
|
2724
|
+
j = i - LOG_BASE + d;
|
|
2725
|
+
rd = j < 0 ? 0 : n / pows10[d - j - 1] % 10 | 0;
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
r = r || sd < 0 || // Are there any non-zero digits after the rounding digit?
|
|
2729
|
+
// The expression n % pows10[d - j - 1] returns all digits of n to the right
|
|
2730
|
+
// of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
|
|
2731
|
+
xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
|
|
2732
|
+
r = rm < 4 ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 && // Check whether the digit to the left of the rounding digit is odd.
|
|
2733
|
+
(i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
2734
|
+
if (sd < 1 || !xc[0]) {
|
|
2735
|
+
xc.length = 0;
|
|
2736
|
+
if (r) {
|
|
2737
|
+
sd -= x.e + 1;
|
|
2738
|
+
xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
|
|
2739
|
+
x.e = -sd || 0;
|
|
2740
|
+
} else {
|
|
2741
|
+
xc[0] = x.e = 0;
|
|
2742
|
+
}
|
|
2743
|
+
return x;
|
|
2744
|
+
}
|
|
2745
|
+
if (i == 0) {
|
|
2746
|
+
xc.length = ni;
|
|
2747
|
+
k = 1;
|
|
2748
|
+
ni--;
|
|
2749
|
+
} else {
|
|
2750
|
+
xc.length = ni + 1;
|
|
2751
|
+
k = pows10[LOG_BASE - i];
|
|
2752
|
+
xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
|
|
2753
|
+
}
|
|
2754
|
+
if (r) {
|
|
2755
|
+
for (; ; ) {
|
|
2756
|
+
if (ni == 0) {
|
|
2757
|
+
for (i = 1, j = xc[0]; j >= 10; j /= 10, i++)
|
|
2758
|
+
;
|
|
2759
|
+
j = xc[0] += k;
|
|
2760
|
+
for (k = 1; j >= 10; j /= 10, k++)
|
|
2761
|
+
;
|
|
2762
|
+
if (i != k) {
|
|
2763
|
+
x.e++;
|
|
2764
|
+
if (xc[0] == BASE)
|
|
2765
|
+
xc[0] = 1;
|
|
2766
|
+
}
|
|
2767
|
+
break;
|
|
2768
|
+
} else {
|
|
2769
|
+
xc[ni] += k;
|
|
2770
|
+
if (xc[ni] != BASE)
|
|
2771
|
+
break;
|
|
2772
|
+
xc[ni--] = 0;
|
|
2773
|
+
k = 1;
|
|
2774
|
+
}
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
for (i = xc.length; xc[--i] === 0; xc.pop())
|
|
2778
|
+
;
|
|
2779
|
+
}
|
|
2780
|
+
if (x.e > MAX_EXP) {
|
|
2781
|
+
x.c = x.e = null;
|
|
2782
|
+
} else if (x.e < MIN_EXP) {
|
|
2783
|
+
x.c = [x.e = 0];
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
return x;
|
|
2787
|
+
}
|
|
2788
|
+
function valueOf(n) {
|
|
2789
|
+
var str, e = n.e;
|
|
2790
|
+
if (e === null)
|
|
2791
|
+
return n.toString();
|
|
2792
|
+
str = coeffToString(n.c);
|
|
2793
|
+
str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
|
|
2794
|
+
return n.s < 0 ? "-" + str : str;
|
|
2795
|
+
}
|
|
2796
|
+
P.absoluteValue = P.abs = function() {
|
|
2797
|
+
var x = new BigNumber2(this);
|
|
2798
|
+
if (x.s < 0)
|
|
2799
|
+
x.s = 1;
|
|
2800
|
+
return x;
|
|
2801
|
+
};
|
|
2802
|
+
P.comparedTo = function(y, b) {
|
|
2803
|
+
return compare(this, new BigNumber2(y, b));
|
|
2804
|
+
};
|
|
2805
|
+
P.decimalPlaces = P.dp = function(dp, rm) {
|
|
2806
|
+
var c, n, v, x = this;
|
|
2807
|
+
if (dp != null) {
|
|
2808
|
+
intCheck(dp, 0, MAX);
|
|
2809
|
+
if (rm == null)
|
|
2810
|
+
rm = ROUNDING_MODE;
|
|
2811
|
+
else
|
|
2812
|
+
intCheck(rm, 0, 8);
|
|
2813
|
+
return round(new BigNumber2(x), dp + x.e + 1, rm);
|
|
2814
|
+
}
|
|
2815
|
+
if (!(c = x.c))
|
|
2816
|
+
return null;
|
|
2817
|
+
n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
2818
|
+
if (v = c[v])
|
|
2819
|
+
for (; v % 10 == 0; v /= 10, n--)
|
|
2820
|
+
;
|
|
2821
|
+
if (n < 0)
|
|
2822
|
+
n = 0;
|
|
2823
|
+
return n;
|
|
2824
|
+
};
|
|
2825
|
+
P.dividedBy = P.div = function(y, b) {
|
|
2826
|
+
return div(this, new BigNumber2(y, b), DECIMAL_PLACES, ROUNDING_MODE);
|
|
2827
|
+
};
|
|
2828
|
+
P.dividedToIntegerBy = P.idiv = function(y, b) {
|
|
2829
|
+
return div(this, new BigNumber2(y, b), 0, 1);
|
|
2830
|
+
};
|
|
2831
|
+
P.exponentiatedBy = P.pow = function(n, m) {
|
|
2832
|
+
var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y, x = this;
|
|
2833
|
+
n = new BigNumber2(n);
|
|
2834
|
+
if (n.c && !n.isInteger()) {
|
|
2835
|
+
throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
|
|
2836
|
+
}
|
|
2837
|
+
if (m != null)
|
|
2838
|
+
m = new BigNumber2(m);
|
|
2839
|
+
nIsBig = n.e > 14;
|
|
2840
|
+
if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
|
|
2841
|
+
y = new BigNumber2(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
|
|
2842
|
+
return m ? y.mod(m) : y;
|
|
2843
|
+
}
|
|
2844
|
+
nIsNeg = n.s < 0;
|
|
2845
|
+
if (m) {
|
|
2846
|
+
if (m.c ? !m.c[0] : !m.s)
|
|
2847
|
+
return new BigNumber2(NaN);
|
|
2848
|
+
isModExp = !nIsNeg && x.isInteger() && m.isInteger();
|
|
2849
|
+
if (isModExp)
|
|
2850
|
+
x = x.mod(m);
|
|
2851
|
+
} else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0 ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7 : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {
|
|
2852
|
+
k = x.s < 0 && isOdd(n) ? -0 : 0;
|
|
2853
|
+
if (x.e > -1)
|
|
2854
|
+
k = 1 / k;
|
|
2855
|
+
return new BigNumber2(nIsNeg ? 1 / k : k);
|
|
2856
|
+
} else if (POW_PRECISION) {
|
|
2857
|
+
k = mathceil(POW_PRECISION / LOG_BASE + 2);
|
|
2858
|
+
}
|
|
2859
|
+
if (nIsBig) {
|
|
2860
|
+
half = new BigNumber2(0.5);
|
|
2861
|
+
if (nIsNeg)
|
|
2862
|
+
n.s = 1;
|
|
2863
|
+
nIsOdd = isOdd(n);
|
|
2864
|
+
} else {
|
|
2865
|
+
i = Math.abs(+valueOf(n));
|
|
2866
|
+
nIsOdd = i % 2;
|
|
2867
|
+
}
|
|
2868
|
+
y = new BigNumber2(ONE);
|
|
2869
|
+
for (; ; ) {
|
|
2870
|
+
if (nIsOdd) {
|
|
2871
|
+
y = y.times(x);
|
|
2872
|
+
if (!y.c)
|
|
2873
|
+
break;
|
|
2874
|
+
if (k) {
|
|
2875
|
+
if (y.c.length > k)
|
|
2876
|
+
y.c.length = k;
|
|
2877
|
+
} else if (isModExp) {
|
|
2878
|
+
y = y.mod(m);
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
if (i) {
|
|
2882
|
+
i = mathfloor(i / 2);
|
|
2883
|
+
if (i === 0)
|
|
2884
|
+
break;
|
|
2885
|
+
nIsOdd = i % 2;
|
|
2886
|
+
} else {
|
|
2887
|
+
n = n.times(half);
|
|
2888
|
+
round(n, n.e + 1, 1);
|
|
2889
|
+
if (n.e > 14) {
|
|
2890
|
+
nIsOdd = isOdd(n);
|
|
2891
|
+
} else {
|
|
2892
|
+
i = +valueOf(n);
|
|
2893
|
+
if (i === 0)
|
|
2894
|
+
break;
|
|
2895
|
+
nIsOdd = i % 2;
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
x = x.times(x);
|
|
2899
|
+
if (k) {
|
|
2900
|
+
if (x.c && x.c.length > k)
|
|
2901
|
+
x.c.length = k;
|
|
2902
|
+
} else if (isModExp) {
|
|
2903
|
+
x = x.mod(m);
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
if (isModExp)
|
|
2907
|
+
return y;
|
|
2908
|
+
if (nIsNeg)
|
|
2909
|
+
y = ONE.div(y);
|
|
2910
|
+
return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
|
|
2911
|
+
};
|
|
2912
|
+
P.integerValue = function(rm) {
|
|
2913
|
+
var n = new BigNumber2(this);
|
|
2914
|
+
if (rm == null)
|
|
2915
|
+
rm = ROUNDING_MODE;
|
|
2916
|
+
else
|
|
2917
|
+
intCheck(rm, 0, 8);
|
|
2918
|
+
return round(n, n.e + 1, rm);
|
|
2919
|
+
};
|
|
2920
|
+
P.isEqualTo = P.eq = function(y, b) {
|
|
2921
|
+
return compare(this, new BigNumber2(y, b)) === 0;
|
|
2922
|
+
};
|
|
2923
|
+
P.isFinite = function() {
|
|
2924
|
+
return !!this.c;
|
|
2925
|
+
};
|
|
2926
|
+
P.isGreaterThan = P.gt = function(y, b) {
|
|
2927
|
+
return compare(this, new BigNumber2(y, b)) > 0;
|
|
2928
|
+
};
|
|
2929
|
+
P.isGreaterThanOrEqualTo = P.gte = function(y, b) {
|
|
2930
|
+
return (b = compare(this, new BigNumber2(y, b))) === 1 || b === 0;
|
|
2931
|
+
};
|
|
2932
|
+
P.isInteger = function() {
|
|
2933
|
+
return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
|
|
2934
|
+
};
|
|
2935
|
+
P.isLessThan = P.lt = function(y, b) {
|
|
2936
|
+
return compare(this, new BigNumber2(y, b)) < 0;
|
|
2937
|
+
};
|
|
2938
|
+
P.isLessThanOrEqualTo = P.lte = function(y, b) {
|
|
2939
|
+
return (b = compare(this, new BigNumber2(y, b))) === -1 || b === 0;
|
|
2940
|
+
};
|
|
2941
|
+
P.isNaN = function() {
|
|
2942
|
+
return !this.s;
|
|
2943
|
+
};
|
|
2944
|
+
P.isNegative = function() {
|
|
2945
|
+
return this.s < 0;
|
|
2946
|
+
};
|
|
2947
|
+
P.isPositive = function() {
|
|
2948
|
+
return this.s > 0;
|
|
2949
|
+
};
|
|
2950
|
+
P.isZero = function() {
|
|
2951
|
+
return !!this.c && this.c[0] == 0;
|
|
2952
|
+
};
|
|
2953
|
+
P.minus = function(y, b) {
|
|
2954
|
+
var i, j, t, xLTy, x = this, a = x.s;
|
|
2955
|
+
y = new BigNumber2(y, b);
|
|
2956
|
+
b = y.s;
|
|
2957
|
+
if (!a || !b)
|
|
2958
|
+
return new BigNumber2(NaN);
|
|
2959
|
+
if (a != b) {
|
|
2960
|
+
y.s = -b;
|
|
2961
|
+
return x.plus(y);
|
|
2962
|
+
}
|
|
2963
|
+
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
|
|
2964
|
+
if (!xe || !ye) {
|
|
2965
|
+
if (!xc || !yc)
|
|
2966
|
+
return xc ? (y.s = -b, y) : new BigNumber2(yc ? x : NaN);
|
|
2967
|
+
if (!xc[0] || !yc[0]) {
|
|
2968
|
+
return yc[0] ? (y.s = -b, y) : new BigNumber2(xc[0] ? x : (
|
|
2969
|
+
// IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
|
|
2970
|
+
ROUNDING_MODE == 3 ? -0 : 0
|
|
2971
|
+
));
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
xe = bitFloor(xe);
|
|
2975
|
+
ye = bitFloor(ye);
|
|
2976
|
+
xc = xc.slice();
|
|
2977
|
+
if (a = xe - ye) {
|
|
2978
|
+
if (xLTy = a < 0) {
|
|
2979
|
+
a = -a;
|
|
2980
|
+
t = xc;
|
|
2981
|
+
} else {
|
|
2982
|
+
ye = xe;
|
|
2983
|
+
t = yc;
|
|
2984
|
+
}
|
|
2985
|
+
t.reverse();
|
|
2986
|
+
for (b = a; b--; t.push(0))
|
|
2987
|
+
;
|
|
2988
|
+
t.reverse();
|
|
2989
|
+
} else {
|
|
2990
|
+
j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
|
|
2991
|
+
for (a = b = 0; b < j; b++) {
|
|
2992
|
+
if (xc[b] != yc[b]) {
|
|
2993
|
+
xLTy = xc[b] < yc[b];
|
|
2994
|
+
break;
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
if (xLTy)
|
|
2999
|
+
t = xc, xc = yc, yc = t, y.s = -y.s;
|
|
3000
|
+
b = (j = yc.length) - (i = xc.length);
|
|
3001
|
+
if (b > 0)
|
|
3002
|
+
for (; b--; xc[i++] = 0)
|
|
3003
|
+
;
|
|
3004
|
+
b = BASE - 1;
|
|
3005
|
+
for (; j > a; ) {
|
|
3006
|
+
if (xc[--j] < yc[j]) {
|
|
3007
|
+
for (i = j; i && !xc[--i]; xc[i] = b)
|
|
3008
|
+
;
|
|
3009
|
+
--xc[i];
|
|
3010
|
+
xc[j] += BASE;
|
|
3011
|
+
}
|
|
3012
|
+
xc[j] -= yc[j];
|
|
3013
|
+
}
|
|
3014
|
+
for (; xc[0] == 0; xc.splice(0, 1), --ye)
|
|
3015
|
+
;
|
|
3016
|
+
if (!xc[0]) {
|
|
3017
|
+
y.s = ROUNDING_MODE == 3 ? -1 : 1;
|
|
3018
|
+
y.c = [y.e = 0];
|
|
3019
|
+
return y;
|
|
3020
|
+
}
|
|
3021
|
+
return normalise(y, xc, ye);
|
|
3022
|
+
};
|
|
3023
|
+
P.modulo = P.mod = function(y, b) {
|
|
3024
|
+
var q, s, x = this;
|
|
3025
|
+
y = new BigNumber2(y, b);
|
|
3026
|
+
if (!x.c || !y.s || y.c && !y.c[0]) {
|
|
3027
|
+
return new BigNumber2(NaN);
|
|
3028
|
+
} else if (!y.c || x.c && !x.c[0]) {
|
|
3029
|
+
return new BigNumber2(x);
|
|
3030
|
+
}
|
|
3031
|
+
if (MODULO_MODE == 9) {
|
|
3032
|
+
s = y.s;
|
|
3033
|
+
y.s = 1;
|
|
3034
|
+
q = div(x, y, 0, 3);
|
|
3035
|
+
y.s = s;
|
|
3036
|
+
q.s *= s;
|
|
3037
|
+
} else {
|
|
3038
|
+
q = div(x, y, 0, MODULO_MODE);
|
|
3039
|
+
}
|
|
3040
|
+
y = x.minus(q.times(y));
|
|
3041
|
+
if (!y.c[0] && MODULO_MODE == 1)
|
|
3042
|
+
y.s = x.s;
|
|
3043
|
+
return y;
|
|
3044
|
+
};
|
|
3045
|
+
P.multipliedBy = P.times = function(y, b) {
|
|
3046
|
+
var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc, base, sqrtBase, x = this, xc = x.c, yc = (y = new BigNumber2(y, b)).c;
|
|
3047
|
+
if (!xc || !yc || !xc[0] || !yc[0]) {
|
|
3048
|
+
if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
|
|
3049
|
+
y.c = y.e = y.s = null;
|
|
3050
|
+
} else {
|
|
3051
|
+
y.s *= x.s;
|
|
3052
|
+
if (!xc || !yc) {
|
|
3053
|
+
y.c = y.e = null;
|
|
3054
|
+
} else {
|
|
3055
|
+
y.c = [0];
|
|
3056
|
+
y.e = 0;
|
|
3057
|
+
}
|
|
3058
|
+
}
|
|
3059
|
+
return y;
|
|
3060
|
+
}
|
|
3061
|
+
e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
|
|
3062
|
+
y.s *= x.s;
|
|
3063
|
+
xcL = xc.length;
|
|
3064
|
+
ycL = yc.length;
|
|
3065
|
+
if (xcL < ycL)
|
|
3066
|
+
zc = xc, xc = yc, yc = zc, i = xcL, xcL = ycL, ycL = i;
|
|
3067
|
+
for (i = xcL + ycL, zc = []; i--; zc.push(0))
|
|
3068
|
+
;
|
|
3069
|
+
base = BASE;
|
|
3070
|
+
sqrtBase = SQRT_BASE;
|
|
3071
|
+
for (i = ycL; --i >= 0; ) {
|
|
3072
|
+
c = 0;
|
|
3073
|
+
ylo = yc[i] % sqrtBase;
|
|
3074
|
+
yhi = yc[i] / sqrtBase | 0;
|
|
3075
|
+
for (k = xcL, j = i + k; j > i; ) {
|
|
3076
|
+
xlo = xc[--k] % sqrtBase;
|
|
3077
|
+
xhi = xc[k] / sqrtBase | 0;
|
|
3078
|
+
m = yhi * xlo + xhi * ylo;
|
|
3079
|
+
xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
|
|
3080
|
+
c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
|
|
3081
|
+
zc[j--] = xlo % base;
|
|
3082
|
+
}
|
|
3083
|
+
zc[j] = c;
|
|
3084
|
+
}
|
|
3085
|
+
if (c) {
|
|
3086
|
+
++e;
|
|
3087
|
+
} else {
|
|
3088
|
+
zc.splice(0, 1);
|
|
3089
|
+
}
|
|
3090
|
+
return normalise(y, zc, e);
|
|
3091
|
+
};
|
|
3092
|
+
P.negated = function() {
|
|
3093
|
+
var x = new BigNumber2(this);
|
|
3094
|
+
x.s = -x.s || null;
|
|
3095
|
+
return x;
|
|
3096
|
+
};
|
|
3097
|
+
P.plus = function(y, b) {
|
|
3098
|
+
var t, x = this, a = x.s;
|
|
3099
|
+
y = new BigNumber2(y, b);
|
|
3100
|
+
b = y.s;
|
|
3101
|
+
if (!a || !b)
|
|
3102
|
+
return new BigNumber2(NaN);
|
|
3103
|
+
if (a != b) {
|
|
3104
|
+
y.s = -b;
|
|
3105
|
+
return x.minus(y);
|
|
3106
|
+
}
|
|
3107
|
+
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
|
|
3108
|
+
if (!xe || !ye) {
|
|
3109
|
+
if (!xc || !yc)
|
|
3110
|
+
return new BigNumber2(a / 0);
|
|
3111
|
+
if (!xc[0] || !yc[0])
|
|
3112
|
+
return yc[0] ? y : new BigNumber2(xc[0] ? x : a * 0);
|
|
3113
|
+
}
|
|
3114
|
+
xe = bitFloor(xe);
|
|
3115
|
+
ye = bitFloor(ye);
|
|
3116
|
+
xc = xc.slice();
|
|
3117
|
+
if (a = xe - ye) {
|
|
3118
|
+
if (a > 0) {
|
|
3119
|
+
ye = xe;
|
|
3120
|
+
t = yc;
|
|
3121
|
+
} else {
|
|
3122
|
+
a = -a;
|
|
3123
|
+
t = xc;
|
|
3124
|
+
}
|
|
3125
|
+
t.reverse();
|
|
3126
|
+
for (; a--; t.push(0))
|
|
3127
|
+
;
|
|
3128
|
+
t.reverse();
|
|
3129
|
+
}
|
|
3130
|
+
a = xc.length;
|
|
3131
|
+
b = yc.length;
|
|
3132
|
+
if (a - b < 0)
|
|
3133
|
+
t = yc, yc = xc, xc = t, b = a;
|
|
3134
|
+
for (a = 0; b; ) {
|
|
3135
|
+
a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
|
|
3136
|
+
xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
|
|
3137
|
+
}
|
|
3138
|
+
if (a) {
|
|
3139
|
+
xc = [a].concat(xc);
|
|
3140
|
+
++ye;
|
|
3141
|
+
}
|
|
3142
|
+
return normalise(y, xc, ye);
|
|
3143
|
+
};
|
|
3144
|
+
P.precision = P.sd = function(sd, rm) {
|
|
3145
|
+
var c, n, v, x = this;
|
|
3146
|
+
if (sd != null && sd !== !!sd) {
|
|
3147
|
+
intCheck(sd, 1, MAX);
|
|
3148
|
+
if (rm == null)
|
|
3149
|
+
rm = ROUNDING_MODE;
|
|
3150
|
+
else
|
|
3151
|
+
intCheck(rm, 0, 8);
|
|
3152
|
+
return round(new BigNumber2(x), sd, rm);
|
|
3153
|
+
}
|
|
3154
|
+
if (!(c = x.c))
|
|
3155
|
+
return null;
|
|
3156
|
+
v = c.length - 1;
|
|
3157
|
+
n = v * LOG_BASE + 1;
|
|
3158
|
+
if (v = c[v]) {
|
|
3159
|
+
for (; v % 10 == 0; v /= 10, n--)
|
|
3160
|
+
;
|
|
3161
|
+
for (v = c[0]; v >= 10; v /= 10, n++)
|
|
3162
|
+
;
|
|
3163
|
+
}
|
|
3164
|
+
if (sd && x.e + 1 > n)
|
|
3165
|
+
n = x.e + 1;
|
|
3166
|
+
return n;
|
|
3167
|
+
};
|
|
3168
|
+
P.shiftedBy = function(k) {
|
|
3169
|
+
intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
|
|
3170
|
+
return this.times("1e" + k);
|
|
3171
|
+
};
|
|
3172
|
+
P.squareRoot = P.sqrt = function() {
|
|
3173
|
+
var m, n, r, rep, t, x = this, c = x.c, s = x.s, e = x.e, dp = DECIMAL_PLACES + 4, half = new BigNumber2("0.5");
|
|
3174
|
+
if (s !== 1 || !c || !c[0]) {
|
|
3175
|
+
return new BigNumber2(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
|
|
3176
|
+
}
|
|
3177
|
+
s = Math.sqrt(+valueOf(x));
|
|
3178
|
+
if (s == 0 || s == 1 / 0) {
|
|
3179
|
+
n = coeffToString(c);
|
|
3180
|
+
if ((n.length + e) % 2 == 0)
|
|
3181
|
+
n += "0";
|
|
3182
|
+
s = Math.sqrt(+n);
|
|
3183
|
+
e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
3184
|
+
if (s == 1 / 0) {
|
|
3185
|
+
n = "5e" + e;
|
|
3186
|
+
} else {
|
|
3187
|
+
n = s.toExponential();
|
|
3188
|
+
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
3189
|
+
}
|
|
3190
|
+
r = new BigNumber2(n);
|
|
3191
|
+
} else {
|
|
3192
|
+
r = new BigNumber2(s + "");
|
|
3193
|
+
}
|
|
3194
|
+
if (r.c[0]) {
|
|
3195
|
+
e = r.e;
|
|
3196
|
+
s = e + dp;
|
|
3197
|
+
if (s < 3)
|
|
3198
|
+
s = 0;
|
|
3199
|
+
for (; ; ) {
|
|
3200
|
+
t = r;
|
|
3201
|
+
r = half.times(t.plus(div(x, t, dp, 1)));
|
|
3202
|
+
if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
|
|
3203
|
+
if (r.e < e)
|
|
3204
|
+
--s;
|
|
3205
|
+
n = n.slice(s - 3, s + 1);
|
|
3206
|
+
if (n == "9999" || !rep && n == "4999") {
|
|
3207
|
+
if (!rep) {
|
|
3208
|
+
round(t, t.e + DECIMAL_PLACES + 2, 0);
|
|
3209
|
+
if (t.times(t).eq(x)) {
|
|
3210
|
+
r = t;
|
|
3211
|
+
break;
|
|
3212
|
+
}
|
|
3213
|
+
}
|
|
3214
|
+
dp += 4;
|
|
3215
|
+
s += 4;
|
|
3216
|
+
rep = 1;
|
|
3217
|
+
} else {
|
|
3218
|
+
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
3219
|
+
round(r, r.e + DECIMAL_PLACES + 2, 1);
|
|
3220
|
+
m = !r.times(r).eq(x);
|
|
3221
|
+
}
|
|
3222
|
+
break;
|
|
3223
|
+
}
|
|
3224
|
+
}
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
|
|
3228
|
+
};
|
|
3229
|
+
P.toExponential = function(dp, rm) {
|
|
3230
|
+
if (dp != null) {
|
|
3231
|
+
intCheck(dp, 0, MAX);
|
|
3232
|
+
dp++;
|
|
3233
|
+
}
|
|
3234
|
+
return format(this, dp, rm, 1);
|
|
3235
|
+
};
|
|
3236
|
+
P.toFixed = function(dp, rm) {
|
|
3237
|
+
if (dp != null) {
|
|
3238
|
+
intCheck(dp, 0, MAX);
|
|
3239
|
+
dp = dp + this.e + 1;
|
|
3240
|
+
}
|
|
3241
|
+
return format(this, dp, rm);
|
|
3242
|
+
};
|
|
3243
|
+
P.toFormat = function(dp, rm, format2) {
|
|
3244
|
+
var str, x = this;
|
|
3245
|
+
if (format2 == null) {
|
|
3246
|
+
if (dp != null && rm && typeof rm == "object") {
|
|
3247
|
+
format2 = rm;
|
|
3248
|
+
rm = null;
|
|
3249
|
+
} else if (dp && typeof dp == "object") {
|
|
3250
|
+
format2 = dp;
|
|
3251
|
+
dp = rm = null;
|
|
3252
|
+
} else {
|
|
3253
|
+
format2 = FORMAT;
|
|
3254
|
+
}
|
|
3255
|
+
} else if (typeof format2 != "object") {
|
|
3256
|
+
throw Error(bignumberError + "Argument not an object: " + format2);
|
|
3257
|
+
}
|
|
3258
|
+
str = x.toFixed(dp, rm);
|
|
3259
|
+
if (x.c) {
|
|
3260
|
+
var i, arr = str.split("."), g1 = +format2.groupSize, g2 = +format2.secondaryGroupSize, groupSeparator = format2.groupSeparator || "", intPart = arr[0], fractionPart = arr[1], isNeg = x.s < 0, intDigits = isNeg ? intPart.slice(1) : intPart, len = intDigits.length;
|
|
3261
|
+
if (g2)
|
|
3262
|
+
i = g1, g1 = g2, g2 = i, len -= i;
|
|
3263
|
+
if (g1 > 0 && len > 0) {
|
|
3264
|
+
i = len % g1 || g1;
|
|
3265
|
+
intPart = intDigits.substr(0, i);
|
|
3266
|
+
for (; i < len; i += g1)
|
|
3267
|
+
intPart += groupSeparator + intDigits.substr(i, g1);
|
|
3268
|
+
if (g2 > 0)
|
|
3269
|
+
intPart += groupSeparator + intDigits.slice(i);
|
|
3270
|
+
if (isNeg)
|
|
3271
|
+
intPart = "-" + intPart;
|
|
3272
|
+
}
|
|
3273
|
+
str = fractionPart ? intPart + (format2.decimalSeparator || "") + ((g2 = +format2.fractionGroupSize) ? fractionPart.replace(
|
|
3274
|
+
new RegExp("\\d{" + g2 + "}\\B", "g"),
|
|
3275
|
+
"$&" + (format2.fractionGroupSeparator || "")
|
|
3276
|
+
) : fractionPart) : intPart;
|
|
3277
|
+
}
|
|
3278
|
+
return (format2.prefix || "") + str + (format2.suffix || "");
|
|
3279
|
+
};
|
|
3280
|
+
P.toFraction = function(md) {
|
|
3281
|
+
var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s, x = this, xc = x.c;
|
|
3282
|
+
if (md != null) {
|
|
3283
|
+
n = new BigNumber2(md);
|
|
3284
|
+
if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
|
|
3285
|
+
throw Error(bignumberError + "Argument " + (n.isInteger() ? "out of range: " : "not an integer: ") + valueOf(n));
|
|
3286
|
+
}
|
|
3287
|
+
}
|
|
3288
|
+
if (!xc)
|
|
3289
|
+
return new BigNumber2(x);
|
|
3290
|
+
d = new BigNumber2(ONE);
|
|
3291
|
+
n1 = d0 = new BigNumber2(ONE);
|
|
3292
|
+
d1 = n0 = new BigNumber2(ONE);
|
|
3293
|
+
s = coeffToString(xc);
|
|
3294
|
+
e = d.e = s.length - x.e - 1;
|
|
3295
|
+
d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
|
|
3296
|
+
md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
|
|
3297
|
+
exp = MAX_EXP;
|
|
3298
|
+
MAX_EXP = 1 / 0;
|
|
3299
|
+
n = new BigNumber2(s);
|
|
3300
|
+
n0.c[0] = 0;
|
|
3301
|
+
for (; ; ) {
|
|
3302
|
+
q = div(n, d, 0, 1);
|
|
3303
|
+
d2 = d0.plus(q.times(d1));
|
|
3304
|
+
if (d2.comparedTo(md) == 1)
|
|
3305
|
+
break;
|
|
3306
|
+
d0 = d1;
|
|
3307
|
+
d1 = d2;
|
|
3308
|
+
n1 = n0.plus(q.times(d2 = n1));
|
|
3309
|
+
n0 = d2;
|
|
3310
|
+
d = n.minus(q.times(d2 = d));
|
|
3311
|
+
n = d2;
|
|
3312
|
+
}
|
|
3313
|
+
d2 = div(md.minus(d0), d1, 0, 1);
|
|
3314
|
+
n0 = n0.plus(d2.times(n1));
|
|
3315
|
+
d0 = d0.plus(d2.times(d1));
|
|
3316
|
+
n0.s = n1.s = x.s;
|
|
3317
|
+
e = e * 2;
|
|
3318
|
+
r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(
|
|
3319
|
+
div(n0, d0, e, ROUNDING_MODE).minus(x).abs()
|
|
3320
|
+
) < 1 ? [n1, d1] : [n0, d0];
|
|
3321
|
+
MAX_EXP = exp;
|
|
3322
|
+
return r;
|
|
3323
|
+
};
|
|
3324
|
+
P.toNumber = function() {
|
|
3325
|
+
return +valueOf(this);
|
|
3326
|
+
};
|
|
3327
|
+
P.toPrecision = function(sd, rm) {
|
|
3328
|
+
if (sd != null)
|
|
3329
|
+
intCheck(sd, 1, MAX);
|
|
3330
|
+
return format(this, sd, rm, 2);
|
|
3331
|
+
};
|
|
3332
|
+
P.toString = function(b) {
|
|
3333
|
+
var str, n = this, s = n.s, e = n.e;
|
|
3334
|
+
if (e === null) {
|
|
3335
|
+
if (s) {
|
|
3336
|
+
str = "Infinity";
|
|
3337
|
+
if (s < 0)
|
|
3338
|
+
str = "-" + str;
|
|
3339
|
+
} else {
|
|
3340
|
+
str = "NaN";
|
|
3341
|
+
}
|
|
3342
|
+
} else {
|
|
3343
|
+
if (b == null) {
|
|
3344
|
+
str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
|
|
3345
|
+
} else if (b === 10 && alphabetHasNormalDecimalDigits) {
|
|
3346
|
+
n = round(new BigNumber2(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
|
|
3347
|
+
str = toFixedPoint(coeffToString(n.c), n.e, "0");
|
|
3348
|
+
} else {
|
|
3349
|
+
intCheck(b, 2, ALPHABET.length, "Base");
|
|
3350
|
+
str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b, s, true);
|
|
3351
|
+
}
|
|
3352
|
+
if (s < 0 && n.c[0])
|
|
3353
|
+
str = "-" + str;
|
|
3354
|
+
}
|
|
3355
|
+
return str;
|
|
3356
|
+
};
|
|
3357
|
+
P.valueOf = P.toJSON = function() {
|
|
3358
|
+
return valueOf(this);
|
|
3359
|
+
};
|
|
3360
|
+
P._isBigNumber = true;
|
|
3361
|
+
P[Symbol.toStringTag] = "BigNumber";
|
|
3362
|
+
P[Symbol.for("nodejs.util.inspect.custom")] = P.valueOf;
|
|
3363
|
+
if (configObject != null)
|
|
3364
|
+
BigNumber2.set(configObject);
|
|
3365
|
+
return BigNumber2;
|
|
3366
|
+
}
|
|
3367
|
+
function bitFloor(n) {
|
|
3368
|
+
var i = n | 0;
|
|
3369
|
+
return n > 0 || n === i ? i : i - 1;
|
|
3370
|
+
}
|
|
3371
|
+
function coeffToString(a) {
|
|
3372
|
+
var s, z13, i = 1, j = a.length, r = a[0] + "";
|
|
3373
|
+
for (; i < j; ) {
|
|
3374
|
+
s = a[i++] + "";
|
|
3375
|
+
z13 = LOG_BASE - s.length;
|
|
3376
|
+
for (; z13--; s = "0" + s)
|
|
3377
|
+
;
|
|
3378
|
+
r += s;
|
|
3379
|
+
}
|
|
3380
|
+
for (j = r.length; r.charCodeAt(--j) === 48; )
|
|
3381
|
+
;
|
|
3382
|
+
return r.slice(0, j + 1 || 1);
|
|
3383
|
+
}
|
|
3384
|
+
function compare(x, y) {
|
|
3385
|
+
var a, b, xc = x.c, yc = y.c, i = x.s, j = y.s, k = x.e, l = y.e;
|
|
3386
|
+
if (!i || !j)
|
|
3387
|
+
return null;
|
|
3388
|
+
a = xc && !xc[0];
|
|
3389
|
+
b = yc && !yc[0];
|
|
3390
|
+
if (a || b)
|
|
3391
|
+
return a ? b ? 0 : -j : i;
|
|
3392
|
+
if (i != j)
|
|
3393
|
+
return i;
|
|
3394
|
+
a = i < 0;
|
|
3395
|
+
b = k == l;
|
|
3396
|
+
if (!xc || !yc)
|
|
3397
|
+
return b ? 0 : !xc ^ a ? 1 : -1;
|
|
3398
|
+
if (!b)
|
|
3399
|
+
return k > l ^ a ? 1 : -1;
|
|
3400
|
+
j = (k = xc.length) < (l = yc.length) ? k : l;
|
|
3401
|
+
for (i = 0; i < j; i++)
|
|
3402
|
+
if (xc[i] != yc[i])
|
|
3403
|
+
return xc[i] > yc[i] ^ a ? 1 : -1;
|
|
3404
|
+
return k == l ? 0 : k > l ^ a ? 1 : -1;
|
|
3405
|
+
}
|
|
3406
|
+
function intCheck(n, min, max, name) {
|
|
3407
|
+
if (n < min || n > max || n !== mathfloor(n)) {
|
|
3408
|
+
throw Error(bignumberError + (name || "Argument") + (typeof n == "number" ? n < min || n > max ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(n));
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
function isOdd(n) {
|
|
3412
|
+
var k = n.c.length - 1;
|
|
3413
|
+
return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
|
|
3414
|
+
}
|
|
3415
|
+
function toExponential(str, e) {
|
|
3416
|
+
return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
|
|
3417
|
+
}
|
|
3418
|
+
function toFixedPoint(str, e, z13) {
|
|
3419
|
+
var len, zs;
|
|
3420
|
+
if (e < 0) {
|
|
3421
|
+
for (zs = z13 + "."; ++e; zs += z13)
|
|
3422
|
+
;
|
|
3423
|
+
str = zs + str;
|
|
3424
|
+
} else {
|
|
3425
|
+
len = str.length;
|
|
3426
|
+
if (++e > len) {
|
|
3427
|
+
for (zs = z13, e -= len; --e; zs += z13)
|
|
3428
|
+
;
|
|
3429
|
+
str += zs;
|
|
3430
|
+
} else if (e < len) {
|
|
3431
|
+
str = str.slice(0, e) + "." + str.slice(e);
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
return str;
|
|
3435
|
+
}
|
|
3436
|
+
var BigNumber = clone();
|
|
3437
|
+
|
|
3438
|
+
// src/math.ts
|
|
3439
|
+
var compute_transfer = (pool1, pool2, swap, exchange_fee, precision) => {
|
|
3440
|
+
const term1 = pool2;
|
|
3441
|
+
const term2over = pool1.times(pool2);
|
|
3442
|
+
const term2under = pool1.plus(swap);
|
|
3443
|
+
const term2 = term2over.div(term2under).integerValue(BigNumber.ROUND_DOWN);
|
|
3444
|
+
const term = term1.minus(term2);
|
|
3445
|
+
const fee = new BigNumber(exchange_fee).div(FEE_FACTOR);
|
|
3446
|
+
const result = term.minus(term.times(fee));
|
|
3447
|
+
return result.integerValue(BigNumber.ROUND_DOWN).shiftedBy(-precision);
|
|
3448
|
+
};
|
|
3449
|
+
var compute_transfer_curve = (reserve_in, reserve_out, amount_in, exchange_fee, precision, amplifier) => {
|
|
3450
|
+
if (amplifier === 0) {
|
|
3451
|
+
return compute_transfer(new BigNumber(reserve_in), new BigNumber(reserve_out), new BigNumber(amount_in), exchange_fee, precision);
|
|
3452
|
+
}
|
|
3453
|
+
const MAX_ITERATIONS = 10;
|
|
3454
|
+
const sum = reserve_in + reserve_out;
|
|
3455
|
+
let D = sum;
|
|
3456
|
+
let D_prev = 0;
|
|
3457
|
+
const F = (v) => {
|
|
3458
|
+
return (v >= 0 ? 1 : -1) * Math.floor(Math.abs(v));
|
|
3459
|
+
};
|
|
3460
|
+
let i = MAX_ITERATIONS;
|
|
3461
|
+
while (D != D_prev && i--) {
|
|
3462
|
+
const prod1 = F(F(D * D / (reserve_in * 2)) * D / (reserve_out * 2));
|
|
3463
|
+
D_prev = D;
|
|
3464
|
+
D = F(2 * D * (amplifier * sum + prod1) / ((2 * amplifier - 1) * D + 3 * prod1));
|
|
3465
|
+
}
|
|
3466
|
+
const b = reserve_in + amount_in + F(D / (amplifier * 2)) - D;
|
|
3467
|
+
const c = F(F(D * D / ((reserve_in + amount_in) * 2)) * D / (amplifier * 4));
|
|
3468
|
+
let x = D, x_prev = 0;
|
|
3469
|
+
i = MAX_ITERATIONS;
|
|
3470
|
+
while (x != x_prev && i--) {
|
|
3471
|
+
x_prev = F(x);
|
|
3472
|
+
x = +new BigNumber(x * x + c).div(2 * x + b).toFixed(0, BigNumber.ROUND_DOWN);
|
|
3473
|
+
}
|
|
3474
|
+
if (reserve_out <= x) {
|
|
3475
|
+
throw new Error("curve: insufficient reserve out");
|
|
3476
|
+
}
|
|
3477
|
+
const amount_out_with_fee = new BigNumber(reserve_out - x);
|
|
3478
|
+
const fee = amount_out_with_fee.times(exchange_fee).div(FEE_FACTOR).plus(1).toFixed(0, BigNumber.ROUND_DOWN);
|
|
3479
|
+
const amount_out = amount_out_with_fee.minus(fee);
|
|
3480
|
+
return amount_out.integerValue(BigNumber.ROUND_DOWN).shiftedBy(-precision);
|
|
3481
|
+
};
|
|
3482
|
+
var compute_liquidity = (amount_lt, pool, lt_supply, precision) => {
|
|
3483
|
+
const over = amount_lt.times(pool);
|
|
3484
|
+
const under = lt_supply;
|
|
3485
|
+
const result = over.div(under).integerValue(BigNumber.ROUND_DOWN);
|
|
3486
|
+
return +result.shiftedBy(-precision).toFixed(precision, BigNumber.ROUND_DOWN);
|
|
3487
|
+
};
|
|
3488
|
+
var isInputInvalid = (data, value, pool) => {
|
|
3489
|
+
value = String(value);
|
|
3490
|
+
const isBackspace = data === null;
|
|
3491
|
+
const isNumber = !/[0-9]|\./.test(data);
|
|
3492
|
+
const isDoubleDot = data === "." && value.indexOf(".") !== value.length - 1;
|
|
3493
|
+
const isPrecisionTooHigh = value && value.indexOf(".") !== -1 && value.split(".")[1].length > pool.xtokenPrecision;
|
|
3494
|
+
const isInvalid = !isBackspace && Boolean(isNumber || isDoubleDot || isPrecisionTooHigh);
|
|
3495
|
+
return isInvalid;
|
|
3496
|
+
};
|
|
3497
|
+
var applyDiscountToFee = (fee, staked) => {
|
|
3498
|
+
if (staked >= 1e7) {
|
|
3499
|
+
return fee * 0;
|
|
3500
|
+
} else if (staked >= 1e6) {
|
|
3501
|
+
return fee * 0.33;
|
|
3502
|
+
} else if (staked >= 1e5) {
|
|
3503
|
+
return fee * 0.66;
|
|
3504
|
+
} else {
|
|
3505
|
+
return fee;
|
|
3506
|
+
}
|
|
3507
|
+
};
|
|
3508
|
+
export {
|
|
3509
|
+
Chains,
|
|
3510
|
+
ExtendedAssetParser,
|
|
3511
|
+
FEE_FACTOR,
|
|
3512
|
+
Graph,
|
|
3513
|
+
ILink,
|
|
3514
|
+
INode,
|
|
3515
|
+
ITopics,
|
|
3516
|
+
Networks,
|
|
3517
|
+
Providers,
|
|
3518
|
+
Status,
|
|
3519
|
+
TOPICS,
|
|
3520
|
+
Type,
|
|
3521
|
+
WRAP_AUTH_ACTION,
|
|
3522
|
+
WRAP_CONTRACT,
|
|
3523
|
+
accountParser,
|
|
3524
|
+
addressParser,
|
|
3525
|
+
applyDiscountToFee,
|
|
3526
|
+
authorizationParser,
|
|
3527
|
+
authorizationsParser,
|
|
3528
|
+
baseActionParser,
|
|
3529
|
+
baseActionSerializedParser,
|
|
3530
|
+
bloksRatesParser,
|
|
3531
|
+
compute_liquidity,
|
|
3532
|
+
compute_transfer,
|
|
3533
|
+
compute_transfer_curve,
|
|
3534
|
+
createAbstractAuthParser,
|
|
3535
|
+
dailyParser,
|
|
3536
|
+
depositBodyParser,
|
|
3537
|
+
depthParser,
|
|
3538
|
+
exchangeRateParser,
|
|
3539
|
+
exchangeRatesParser,
|
|
3540
|
+
explorerLinkByChain,
|
|
3541
|
+
fillType,
|
|
3542
|
+
generateAddressBodyParser,
|
|
3543
|
+
generateAddressResponse,
|
|
3544
|
+
generateAuthParser,
|
|
3545
|
+
getDailyResponseParser,
|
|
3546
|
+
getDepthParser,
|
|
3547
|
+
getDepthResponseParser,
|
|
3548
|
+
getLeaderboardParser,
|
|
3549
|
+
getLeaderboardResponseParser,
|
|
3550
|
+
getMarketsResponseParser,
|
|
3551
|
+
getOhlcvParser,
|
|
3552
|
+
getOhlcvResponseParser,
|
|
3553
|
+
getOpenOrdersParser,
|
|
3554
|
+
getOpenOrdersResponseParser,
|
|
3555
|
+
getOrderHistoryParser,
|
|
3556
|
+
getOrderHistoryResponseParser,
|
|
3557
|
+
getOrderParser,
|
|
3558
|
+
getOrderResponseParser,
|
|
3559
|
+
getReferralTotalsParser,
|
|
3560
|
+
getReferralTotalsResponseParser,
|
|
3561
|
+
getReferralsParser,
|
|
3562
|
+
getReferralsResponseParser,
|
|
3563
|
+
getSyncResponseParser,
|
|
3564
|
+
getTradeHistoryParser,
|
|
3565
|
+
getTradeHistoryResponseParser,
|
|
3566
|
+
getTradesParser,
|
|
3567
|
+
getTradesResponseParser,
|
|
3568
|
+
initializeCoins,
|
|
3569
|
+
initializeConstants,
|
|
3570
|
+
isInputInvalid,
|
|
3571
|
+
isSameToken,
|
|
3572
|
+
leaderboardParser,
|
|
3573
|
+
logStatus,
|
|
3574
|
+
loginAccountParamsV3Parser,
|
|
3575
|
+
marketParser,
|
|
3576
|
+
median,
|
|
3577
|
+
ohlcvParser,
|
|
3578
|
+
orderHistoryParser,
|
|
3579
|
+
orderSide,
|
|
3580
|
+
orderType,
|
|
3581
|
+
otcOrderResponseParser,
|
|
3582
|
+
otcQuoteBodyParser,
|
|
3583
|
+
otcQuoteResponseParser,
|
|
3584
|
+
protonExplorerTxUrl,
|
|
3585
|
+
rateParser,
|
|
3586
|
+
refferalParser,
|
|
3587
|
+
refferalTotalParser,
|
|
3588
|
+
similarChains,
|
|
3589
|
+
singleActionTransactionParser,
|
|
3590
|
+
syncParser,
|
|
3591
|
+
tradeParser,
|
|
3592
|
+
transactionParser,
|
|
3593
|
+
webauthActionParser,
|
|
3594
|
+
withdrawBodyParser,
|
|
3595
|
+
withdrawHistoryMetalResponseParser,
|
|
3596
|
+
withdrawHistoryMetalSwapParser,
|
|
3597
|
+
withdrawMetalResponseParser,
|
|
3598
|
+
withdrawalFeeQuoteParser,
|
|
3599
|
+
wrapParser,
|
|
3600
|
+
wrapSetConfParser,
|
|
3601
|
+
wrapStartParser
|
|
3602
|
+
};
|