edge-currency-accountbased 2.2.3 → 2.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/android/src/main/assets/edge-currency-accountbased/1944.chunk.js +4 -0
  3. package/android/src/main/assets/edge-currency-accountbased/2153.chunk.js +2 -0
  4. package/android/src/main/assets/edge-currency-accountbased/2821.chunk.js +2 -0
  5. package/android/src/main/assets/edge-currency-accountbased/2896.chunk.js +35 -0
  6. package/android/src/main/assets/edge-currency-accountbased/2945.chunk.js +25 -0
  7. package/android/src/main/assets/edge-currency-accountbased/3491.chunk.js +1 -0
  8. package/android/src/main/assets/edge-currency-accountbased/{620.chunk.js → 3620.chunk.js} +1 -1
  9. package/android/src/main/assets/edge-currency-accountbased/{666.chunk.js → 3666.chunk.js} +1 -1
  10. package/android/src/main/assets/edge-currency-accountbased/3720.chunk.js +1 -0
  11. package/android/src/main/assets/edge-currency-accountbased/{978.chunk.js → 3978.chunk.js} +1 -1
  12. package/android/src/main/assets/edge-currency-accountbased/4251.chunk.js +4 -0
  13. package/android/src/main/assets/edge-currency-accountbased/4431.chunk.js +1 -0
  14. package/android/src/main/assets/edge-currency-accountbased/4618.chunk.js +20 -0
  15. package/android/src/main/assets/edge-currency-accountbased/{627.chunk.js → 4627.chunk.js} +1 -1
  16. package/android/src/main/assets/edge-currency-accountbased/4650.chunk.js +1 -0
  17. package/android/src/main/assets/edge-currency-accountbased/{826.chunk.js → 5179.chunk.js} +1 -1
  18. package/android/src/main/assets/edge-currency-accountbased/{835.chunk.js → 5835.chunk.js} +1 -1
  19. package/android/src/main/assets/edge-currency-accountbased/5836.chunk.js +1 -0
  20. package/android/src/main/assets/edge-currency-accountbased/6266.chunk.js +1 -0
  21. package/android/src/main/assets/edge-currency-accountbased/6291.chunk.js +58 -0
  22. package/android/src/main/assets/edge-currency-accountbased/6341.chunk.js +44 -0
  23. package/android/src/main/assets/edge-currency-accountbased/7221.chunk.js +1 -0
  24. package/android/src/main/assets/edge-currency-accountbased/7428.chunk.js +6 -0
  25. package/android/src/main/assets/edge-currency-accountbased/{481.chunk.js → 7481.chunk.js} +1 -1
  26. package/android/src/main/assets/edge-currency-accountbased/7542.chunk.js +1 -0
  27. package/android/src/main/assets/edge-currency-accountbased/7786.chunk.js +2 -0
  28. package/android/src/main/assets/edge-currency-accountbased/8190.chunk.js +1 -0
  29. package/android/src/main/assets/edge-currency-accountbased/{689.chunk.js → 8689.chunk.js} +1 -1
  30. package/android/src/main/assets/edge-currency-accountbased/{726.chunk.js → 8726.chunk.js} +1 -1
  31. package/android/src/main/assets/edge-currency-accountbased/9068.chunk.js +1 -0
  32. package/android/src/main/assets/edge-currency-accountbased/{223.chunk.js → 9223.chunk.js} +2 -2
  33. package/android/src/main/assets/edge-currency-accountbased/9539.chunk.js +10 -0
  34. package/android/src/main/assets/edge-currency-accountbased/{645.chunk.js → 9645.chunk.js} +6 -6
  35. package/android/src/main/assets/edge-currency-accountbased/9669.chunk.js +7 -0
  36. package/android/src/main/assets/edge-currency-accountbased/algorand.chunk.js +1 -1
  37. package/android/src/main/assets/edge-currency-accountbased/bnb.chunk.js +2 -2
  38. package/android/src/main/assets/edge-currency-accountbased/edge-currency-accountbased.js +2 -18
  39. package/android/src/main/assets/edge-currency-accountbased/eos.chunk.js +5 -5
  40. package/android/src/main/assets/edge-currency-accountbased/ethereum.chunk.js +2 -2
  41. package/android/src/main/assets/edge-currency-accountbased/filecoin.chunk.js +1 -1
  42. package/android/src/main/assets/edge-currency-accountbased/fio.chunk.js +2 -2
  43. package/android/src/main/assets/edge-currency-accountbased/hedera.chunk.js +2 -2
  44. package/android/src/main/assets/edge-currency-accountbased/polkadot.chunk.js +2 -2
  45. package/android/src/main/assets/edge-currency-accountbased/ripple.chunk.js +2 -2
  46. package/android/src/main/assets/edge-currency-accountbased/solana.chunk.js +2 -2
  47. package/android/src/main/assets/edge-currency-accountbased/stellar.chunk.js +2 -2
  48. package/android/src/main/assets/edge-currency-accountbased/tezos.chunk.js +2 -2
  49. package/android/src/main/assets/edge-currency-accountbased/tron.chunk.js +1 -1
  50. package/android/src/main/assets/edge-currency-accountbased/zcash.chunk.js +2 -2
  51. package/lib/ethereum/info/avalancheInfo.js +8 -0
  52. package/lib/ethereum/info/ethereumInfo.js +8 -0
  53. package/lib/filecoin/FilecoinEngine.js +112 -79
  54. package/lib/filecoin/Filfox.js +68 -1
  55. package/lib/filecoin/filecoinInfo.js +8 -3
  56. package/lib/filecoin/filecoinTypes.js +1 -6
  57. package/lib/zcash/ZcashEngine.js +11 -9
  58. package/package.json +1 -1
  59. package/android/src/main/assets/edge-currency-accountbased/124.chunk.js +0 -35
  60. package/android/src/main/assets/edge-currency-accountbased/17.chunk.js +0 -58
  61. package/android/src/main/assets/edge-currency-accountbased/190.chunk.js +0 -1
  62. package/android/src/main/assets/edge-currency-accountbased/221.chunk.js +0 -1
  63. package/android/src/main/assets/edge-currency-accountbased/298.chunk.js +0 -44
  64. package/android/src/main/assets/edge-currency-accountbased/431.chunk.js +0 -1
  65. package/android/src/main/assets/edge-currency-accountbased/491.chunk.js +0 -1
  66. package/android/src/main/assets/edge-currency-accountbased/539.chunk.js +0 -10
  67. package/android/src/main/assets/edge-currency-accountbased/542.chunk.js +0 -1
  68. package/android/src/main/assets/edge-currency-accountbased/618.chunk.js +0 -20
  69. package/android/src/main/assets/edge-currency-accountbased/650.chunk.js +0 -1
  70. package/android/src/main/assets/edge-currency-accountbased/68.chunk.js +0 -1
  71. package/android/src/main/assets/edge-currency-accountbased/720.chunk.js +0 -1
  72. package/android/src/main/assets/edge-currency-accountbased/786.chunk.js +0 -2
  73. package/android/src/main/assets/edge-currency-accountbased/836.chunk.js +0 -1
  74. package/android/src/main/assets/edge-currency-accountbased/935.chunk.js +0 -1
  75. package/android/src/main/assets/edge-currency-accountbased/944.chunk.js +0 -4
  76. package/android/src/main/assets/edge-currency-accountbased/945.chunk.js +0 -25
@@ -6,6 +6,7 @@
6
6
 
7
7
 
8
8
 
9
+
9
10
  var _izarifilecoin = require('@zondax/izari-filecoin');
10
11
  var _biggystring = require('biggystring');
11
12
 
@@ -51,6 +52,7 @@ const CHECK_TRANSACTION_INTERVAL = 15000
51
52
 
52
53
 
53
54
 
55
+
54
56
 
55
57
  // Backends:
56
58
 
@@ -68,16 +70,17 @@ const CHECK_TRANSACTION_INTERVAL = 15000
68
70
  const { networkInfo } = env
69
71
  this.address = _izarifilecoin.Address.fromString(walletInfo.keys.address)
70
72
  this.availableAttoFil = '0'
71
- this.filRpc = new (0, _izarifilecoin.RPC)(env.networkInfo.rpcNode.networkName, {
73
+ this.isScanning = false
74
+ this.networkInfo = networkInfo
75
+ this.pluginId = this.currencyInfo.pluginId
76
+
77
+ this.filRpc = new (0, _izarifilecoin.RPC)(_izarifilecoin.Network[env.networkInfo.rpcNode.networkName], {
72
78
  url: env.networkInfo.rpcNode.url,
73
79
  token: env.currencyInfo.currencyCode
74
80
  })
75
81
  this.filfoxApi = new (0, _Filfox.Filfox)(env.networkInfo.filfoxUrl, env.io.fetchCors)
76
82
  this.filscanApi = new (0, _Filscan.Filscan)(env.networkInfo.filscanUrl, env.io.fetchCors)
77
83
  this.rpcExtra = new (0, _RpcExtra.RpcExtra)(env.networkInfo.rpcNode.url, env.io.fetchCors)
78
-
79
- this.networkInfo = networkInfo
80
- this.pluginId = this.currencyInfo.pluginId
81
84
  }
82
85
 
83
86
  setOtherData(raw) {
@@ -85,9 +88,7 @@ const CHECK_TRANSACTION_INTERVAL = 15000
85
88
  }
86
89
 
87
90
  initData() {
88
- // Initialize walletLocalData:
89
- // ...
90
-
91
+ this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode] = 0
91
92
  // Engine variables
92
93
  this.availableAttoFil = '0'
93
94
  }
@@ -189,15 +190,15 @@ const CHECK_TRANSACTION_INTERVAL = 15000
189
190
  }
190
191
 
191
192
  const networkFee = _biggystring.mul.call(void 0, txJson.GasLimit.toString(), txJson.GasPremium) // TODO: Include base fee and burn fee somehow?
192
- const totalTxAmount = _biggystring.add.call(void 0, nativeAmount, networkFee)
193
+ const txNativeAmount = _biggystring.mul.call(void 0, _biggystring.add.call(void 0, nativeAmount, networkFee), '-1')
193
194
 
194
195
  const edgeTransaction = {
195
196
  txid: '',
196
197
  date: 0,
197
198
  currencyCode,
198
199
  blockHeight: 0,
199
- nativeAmount: `-${totalTxAmount}`,
200
- isSend: nativeAmount.startsWith('-'),
200
+ nativeAmount: txNativeAmount,
201
+ isSend: true,
201
202
  networkFee,
202
203
  ourReceiveAddresses: [],
203
204
  otherParams,
@@ -230,6 +231,8 @@ const CHECK_TRANSACTION_INTERVAL = 15000
230
231
  sigJson: signature.toJSON()
231
232
  }
232
233
 
234
+ edgeTransaction.date = Date.now() / 1000
235
+
233
236
  return edgeTransaction
234
237
  }
235
238
 
@@ -297,52 +300,71 @@ const CHECK_TRANSACTION_INTERVAL = 15000
297
300
  }
298
301
 
299
302
  async checkTransactions() {
300
- const addressString = this.address.toString()
301
-
302
- const handleScanProgress = (progress) => {
303
- const currentProgress =
304
- this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]
305
- const newProgress = progress
306
-
307
- if (
308
- // Only send event if we haven't completed sync
309
- currentProgress < 1 &&
310
- // Avoid thrashing
311
- (newProgress >= 1 || newProgress > currentProgress * 1.1)
312
- ) {
313
- this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode] =
314
- newProgress
315
- this.updateOnAddressesChecked()
303
+ // We shouldn't start scanning if scanning is already happening:
304
+ if (this.isScanning) return
305
+ try {
306
+ this.isScanning = true
307
+
308
+ const addressString = this.address.toString()
309
+
310
+ const handleScanProgress = (progress) => {
311
+ const currentProgress =
312
+ this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]
313
+ const newProgress = progress
314
+
315
+ if (
316
+ // Only send event if we haven't completed sync
317
+ currentProgress < 1 &&
318
+ // Avoid thrashing
319
+ (newProgress >= 1 || newProgress > currentProgress * 1.1)
320
+ ) {
321
+ this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode] =
322
+ newProgress
323
+ this.updateOnAddressesChecked()
324
+ }
316
325
  }
317
- }
318
326
 
319
- const handleScan = ({
320
- tx,
321
- progress
322
- }
327
+ const handleScan = ({
328
+ tx,
329
+ progress
330
+ }
323
331
 
324
332
 
325
333
  ) => {
326
- this.addTransaction(this.currencyInfo.currencyCode, tx)
327
- this.onUpdateTransactions()
334
+ this.addTransaction(this.currencyInfo.currencyCode, tx)
335
+ this.onUpdateTransactions()
328
336
 
329
- // Progress the block-height if the message's height is greater than
330
- // last poll for block-height.
331
- if (this.walletLocalData.blockHeight < tx.blockHeight) {
332
- this.onUpdateBlockHeight(tx.blockHeight)
337
+ // Progress the block-height if the message's height is greater than
338
+ // last poll for block-height.
339
+ if (this.walletLocalData.blockHeight < tx.blockHeight) {
340
+ this.onUpdateBlockHeight(tx.blockHeight)
341
+ }
342
+
343
+ handleScanProgress(progress)
333
344
  }
334
345
 
335
- handleScanProgress(progress)
336
- }
346
+ const scanners = [
347
+ // this.scanTransactionsFromFilscan(addressString, handleScan),
348
+ this.scanTransactionsFromFilfox(addressString, handleScan)
349
+ ]
337
350
 
338
- const scanners = [
339
- this.scanTransactionsFromFilscan(addressString, handleScan),
340
- this.scanTransactionsFromFilfox(addressString, handleScan)
341
- ]
351
+ const startingNetworkHeight = this.walletLocalData.blockHeight
342
352
 
343
- await Promise.all(scanners)
353
+ // Run scanners:
354
+ await Promise.all(scanners)
344
355
 
345
- handleScanProgress(1)
356
+ // Save the network height at the start of the scanning
357
+ this.walletLocalData.lastAddressQueryHeight = startingNetworkHeight
358
+ this.walletLocalDataDirty = true
359
+
360
+ // Make sure the sync progress is 100%
361
+ handleScanProgress(1)
362
+ } catch (error) {
363
+ console.error(error)
364
+ throw error
365
+ } finally {
366
+ this.isScanning = false
367
+ }
346
368
  }
347
369
 
348
370
  async scanTransactionsFromFilfox(
@@ -367,17 +389,14 @@ const CHECK_TRANSACTION_INTERVAL = 15000
367
389
 
368
390
  const messages = messagesResponse.messages
369
391
  for (const message of messages) {
370
- const txid = message.cid
371
- const idx = this.findTransaction(this.currencyInfo.currencyCode, txid)
372
-
373
- if (idx >= 0) {
374
- // Exit early because we reached transaction history from previous
375
- // check
376
- return
377
- }
392
+ // Exit when we reach a transaction we may already have saved
393
+ if (message.height < this.walletLocalData.lastAddressQueryHeight) return
378
394
 
379
395
  // Process message into a transaction
380
- const tx = this.filfoxMessageToEdgeTransaction(message)
396
+ const messageDetails = await this.filfoxApi.getMessageDetails(
397
+ message.cid
398
+ )
399
+ const tx = this.filfoxMessageToEdgeTransaction(messageDetails)
381
400
 
382
401
  // Calculate the progress
383
402
  const progress =
@@ -410,14 +429,8 @@ const CHECK_TRANSACTION_INTERVAL = 15000
410
429
 
411
430
  const messages = messagesResponse.messages_by_account_id_list
412
431
  for (const message of messages) {
413
- const txid = message.cid
414
- const idx = this.findTransaction(this.currencyInfo.currencyCode, txid)
415
-
416
- if (idx >= 0) {
417
- // Exit early because we reached transaction history from previous
418
- // check
419
- return
420
- }
432
+ // Exit when we reach a transaction we may already have saved
433
+ if (message.height < this.walletLocalData.lastAddressQueryHeight) return
421
434
 
422
435
  // Process message into a transaction
423
436
  const tx = this.filscanMessageToEdgeTransaction(message)
@@ -432,27 +445,41 @@ const CHECK_TRANSACTION_INTERVAL = 15000
432
445
  }
433
446
 
434
447
  __init() {this.filfoxMessageToEdgeTransaction = (
435
- message
448
+ messageDetails
436
449
  ) => {
437
450
  const addressString = this.address.toString()
438
- let netNativeAmount = message.value
439
451
  const ourReceiveAddresses = []
440
452
 
441
- const networkFee = '0' // TODO: calculate transaction fee from onchain gas fields
442
- if (message.to !== addressString) {
443
- // check if tx is a spend
444
- netNativeAmount = `-${_biggystring.add.call(void 0, netNativeAmount, networkFee)}`
453
+ // Handle network fees:
454
+ const networkFee = messageDetails.transfers
455
+ .filter(
456
+ transfer =>
457
+ transfer.type === 'miner-fee' || transfer.type === 'burner-fee'
458
+ )
459
+ .reduce((sum, transfer) => _biggystring.add.call(void 0, sum, transfer.value), '0')
460
+
461
+ // Handle native amount:
462
+ let nativeAmount
463
+ if (messageDetails.from === addressString) {
464
+ // For spends, always include network fee
465
+ nativeAmount = `-${networkFee}`
466
+ if (messageDetails.to !== addressString) {
467
+ // For spends not to self, subtract tx value
468
+ nativeAmount = _biggystring.sub.call(void 0, nativeAmount, messageDetails.value)
469
+ }
445
470
  } else {
471
+ // For receives nativeAMount is always positively the value
472
+ nativeAmount = messageDetails.value
446
473
  ourReceiveAddresses.push(addressString)
447
474
  }
448
475
 
449
476
  const edgeTransaction = {
450
- txid: message.cid,
451
- date: message.timestamp,
477
+ txid: messageDetails.cid,
478
+ date: messageDetails.timestamp,
452
479
  currencyCode: this.currencyInfo.currencyCode,
453
- blockHeight: message.height,
454
- nativeAmount: netNativeAmount,
455
- isSend: netNativeAmount.startsWith('-'),
480
+ blockHeight: messageDetails.height,
481
+ nativeAmount,
482
+ isSend: nativeAmount.startsWith('-'),
456
483
  networkFee,
457
484
  ourReceiveAddresses, // blank if you sent money otherwise array of addresses that are yours in this transaction
458
485
  signedTx: '',
@@ -465,14 +492,20 @@ const CHECK_TRANSACTION_INTERVAL = 15000
465
492
 
466
493
  filscanMessageToEdgeTransaction(message) {
467
494
  const addressString = this.address.toString()
468
- let netNativeAmount = message.value
469
495
  const ourReceiveAddresses = []
470
496
 
471
497
  const networkFee = '0' // TODO: calculate transaction fee from onchain gas fields
472
- if (message.to !== addressString) {
473
- // check if tx is a spend
474
- netNativeAmount = `-${_biggystring.add.call(void 0, netNativeAmount, networkFee)}`
498
+ let nativeAmount
499
+ if (message.from === addressString) {
500
+ // For spends, always include network fee
501
+ nativeAmount = `-${networkFee}`
502
+ if (message.to !== addressString) {
503
+ // For spends not to self, subtract tx value
504
+ nativeAmount = _biggystring.sub.call(void 0, nativeAmount, message.value)
505
+ }
475
506
  } else {
507
+ // For receives nativeAMount is always positively the value
508
+ nativeAmount = message.value
476
509
  ourReceiveAddresses.push(addressString)
477
510
  }
478
511
 
@@ -481,8 +514,8 @@ const CHECK_TRANSACTION_INTERVAL = 15000
481
514
  date: message.block_time,
482
515
  currencyCode: this.currencyInfo.currencyCode,
483
516
  blockHeight: message.height,
484
- nativeAmount: netNativeAmount,
485
- isSend: netNativeAmount.startsWith('-'),
517
+ nativeAmount,
518
+ isSend: nativeAmount.startsWith('-'),
486
519
  networkFee,
487
520
  ourReceiveAddresses, // blank if you sent money otherwise array of addresses that are yours in this transaction
488
521
  signedTx: '',
@@ -40,7 +40,7 @@ var _cleaners = require('cleaners');
40
40
  height: _cleaners.asNumber,
41
41
  method: _cleaners.asString,
42
42
  nonce: _cleaners.asNumber,
43
- reciept: _cleaners.asObject.call(void 0, {
43
+ receipt: _cleaners.asObject.call(void 0, {
44
44
  exitCode: _cleaners.asNumber
45
45
  }),
46
46
  timestamp: _cleaners.asNumber,
@@ -48,6 +48,42 @@ var _cleaners = require('cleaners');
48
48
  value: _cleaners.asString
49
49
  }); exports.asFilfoxMessage = asFilfoxMessage
50
50
 
51
+
52
+ const asFilfoxMessageDetailed = _cleaners.asObject.call(void 0, {
53
+ cid: _cleaners.asString,
54
+ height: _cleaners.asNumber,
55
+ timestamp: _cleaners.asNumber,
56
+ from: _cleaners.asString,
57
+ to: _cleaners.asString,
58
+ value: _cleaners.asString,
59
+ gasLimit: _cleaners.asNumber,
60
+ gasFeeCap: _cleaners.asString,
61
+ gasPremium: _cleaners.asString,
62
+ receipt: _cleaners.asObject.call(void 0, {
63
+ exitCode: _cleaners.asNumber,
64
+ return: _cleaners.asString,
65
+ gasUsed: _cleaners.asNumber
66
+ }),
67
+ baseFee: _cleaners.asString,
68
+ fee: _cleaners.asObject.call(void 0, {
69
+ baseFeeBurn: _cleaners.asString,
70
+ overEstimationBurn: _cleaners.asString,
71
+ minerPenalty: _cleaners.asString,
72
+ minerTip: _cleaners.asString,
73
+ refund: _cleaners.asString
74
+ }),
75
+ transfers: _cleaners.asArray.call(void 0,
76
+ _cleaners.asObject.call(void 0, {
77
+ from: _cleaners.asString,
78
+ fromId: _cleaners.asString,
79
+ to: _cleaners.asString,
80
+ toId: _cleaners.asString,
81
+ value: _cleaners.asString,
82
+ type: _cleaners.asString
83
+ })
84
+ )
85
+ }); exports.asFilfoxMessageDetailed = asFilfoxMessageDetailed
86
+
51
87
  //
52
88
  // Messages
53
89
  //
@@ -58,6 +94,15 @@ var _cleaners = require('cleaners');
58
94
  totalCount: _cleaners.asNumber
59
95
  }); exports.asFilfoxMessagesResult = asFilfoxMessagesResult
60
96
 
97
+ //
98
+ // Message Details
99
+ //
100
+
101
+
102
+
103
+
104
+ const asFilfoxMessageDetailsResult = exports.asFilfoxMessageDetailed; exports.asFilfoxMessageDetailsResult = asFilfoxMessageDetailsResult
105
+
61
106
  // -----------------------------------------------------------------------------
62
107
  // Implementation
63
108
  // -----------------------------------------------------------------------------
@@ -98,4 +143,26 @@ var _cleaners = require('cleaners');
98
143
 
99
144
  return responseBody
100
145
  }
146
+
147
+ async getMessageDetails(
148
+ messageCid
149
+ ) {
150
+ const response = await this.fetch(`${this.baseUrl}/message/${messageCid}`, {
151
+ method: 'GET',
152
+ headers: {
153
+ 'content-type': 'application/json'
154
+ }
155
+ })
156
+ const responseText = await response.text()
157
+ const responseBody = exports.asFilfoxEnvelope.call(void 0, (0, exports.asFilfoxMessageDetailsResult))(
158
+ responseText
159
+ )
160
+
161
+ if ('error' in responseBody)
162
+ throw new Error(
163
+ `Error response code ${responseBody.statusCode}: ${responseBody.message} ${responseBody.error}`
164
+ )
165
+
166
+ return responseBody
167
+ }
101
168
  } exports.Filfox = Filfox;
@@ -1,5 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _izarifilecoin = require('@zondax/izari-filecoin');
2
-
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
3
2
 
4
3
  var _innerPlugin = require('../common/innerPlugin');
5
4
 
@@ -10,7 +9,7 @@ const networkInfo = {
10
9
  filscanUrl: 'https://api-v2.filscan.io/api/v1',
11
10
  hdPathCoinType: 461,
12
11
  rpcNode: {
13
- networkName: _izarifilecoin.Network.Mainnet,
12
+ networkName: 'Mainnet',
14
13
  url: 'https://api.node.glif.io/'
15
14
  }
16
15
  }
@@ -76,6 +75,12 @@ const networkInfo = {
76
75
  currencyInfo: exports.currencyInfo,
77
76
  networkInfo,
78
77
 
78
+ checkEnvironment: () => {
79
+ if (global.BigInt == null) {
80
+ throw new Error('Filecoin requires BigInt support')
81
+ }
82
+ },
83
+
79
84
  async getInnerPlugin() {
80
85
  return await Promise.resolve().then(() => require(
81
86
  /* webpackChunkName: "filecoin" */
@@ -6,16 +6,11 @@
6
6
 
7
7
 
8
8
 
9
+
9
10
  var _cleaners = require('cleaners');
10
11
 
11
12
  var _types = require('../common/types');
12
13
 
13
- // Copy of `import { Network } from '@zondax/izari-filecoin'`
14
-
15
-
16
-
17
-
18
-
19
14
 
20
15
 
21
16
 
@@ -338,16 +338,18 @@ var _zcashTypes = require('./zcashTypes');
338
338
  publicAddress
339
339
  }))
340
340
 
341
+ const txNativeAmount = _biggystring.mul.call(void 0, totalTxAmount, '-1')
342
+
341
343
  const edgeTransaction = {
342
- txid: '', // txid
343
- date: 0, // date
344
- currencyCode, // currencyCode
345
- blockHeight: 0, // blockHeight
346
- nativeAmount: `-${totalTxAmount}`, // nativeAmount
347
- isSend: nativeAmount.startsWith('-'),
348
- networkFee: this.networkInfo.defaultNetworkFee, // networkFee
349
- ourReceiveAddresses: [], // ourReceiveAddresses
350
- signedTx: '', // signedTx
344
+ txid: '',
345
+ date: 0,
346
+ currencyCode,
347
+ blockHeight: 0,
348
+ nativeAmount: txNativeAmount,
349
+ isSend: true,
350
+ networkFee: this.networkInfo.defaultNetworkFee,
351
+ ourReceiveAddresses: [],
352
+ signedTx: '',
351
353
  spendTargets,
352
354
  walletId: this.walletId
353
355
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-accountbased",
3
- "version": "2.2.3",
3
+ "version": "2.2.5",
4
4
  "description": "Edge currency plugin for account based currencies",
5
5
  "homepage": "https://edge.app/",
6
6
  "repository": {
@@ -1,35 +0,0 @@
1
- "use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[124],{51124:function(K,I,x){x.d(I,{_B:function(){return B}});var s=x(15179),k=x(13550),O=x.n(k),M=function(r,t){return M=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])},M(r,t)};function Q(r,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");M(r,t);function e(){this.constructor=r}r.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}var R=function(){return R=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++){e=arguments[n];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},R.apply(this,arguments)};function H(r,t){var e={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&t.indexOf(n)<0&&(e[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,n=Object.getOwnPropertySymbols(r);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(r,n[o])&&(e[n[o]]=r[n[o]]);return e}function l(r,t,e,n){var o=arguments.length,i=o<3?t:n===null?n=Object.getOwnPropertyDescriptor(t,e):n,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,t,e,n);else for(var u=r.length-1;u>=0;u--)(a=r[u])&&(i=(o<3?a(i):o>3?a(t,e,i):a(t,e))||i);return o>3&&i&&Object.defineProperty(t,e,i),i}function J(r,t){return function(e,n){t(e,n,r)}}function L(r,t,e,n,o,i){function a(j){if(j!==void 0&&typeof j!="function")throw new TypeError("Function expected");return j}for(var u=n.kind,p=u==="getter"?"get":u==="setter"?"set":"value",c=!t&&r?n.static?r:r.prototype:null,f=t||(c?Object.getOwnPropertyDescriptor(c,n.name):{}),d,_=!1,m=e.length-1;m>=0;m--){var w={};for(var v in n)w[v]=v==="access"?{}:n[v];for(var v in n.access)w.access[v]=n.access[v];w.addInitializer=function(j){if(_)throw new TypeError("Cannot add initializers after decoration has completed");i.push(a(j||null))};var A=(0,e[m])(u==="accessor"?{get:f.get,set:f.set}:f[p],w);if(u==="accessor"){if(A===void 0)continue;if(A===null||typeof A!="object")throw new TypeError("Object expected");(d=a(A.get))&&(f.get=d),(d=a(A.set))&&(f.set=d),(d=a(A.init))&&o.push(d)}else(d=a(A))&&(u==="field"?o.push(d):f[p]=d)}c&&Object.defineProperty(c,n.name,f),_=!0}function W(r,t,e){for(var n=arguments.length>2,o=0;o<t.length;o++)e=n?t[o].call(r,e):t[o].call(r);return n?e:void 0}function Y(r){return typeof r=="symbol"?r:"".concat(r)}function Z(r,t,e){return typeof t=="symbol"&&(t=t.description?"[".concat(t.description,"]"):""),Object.defineProperty(r,"name",{configurable:!0,value:e?"".concat(e," ",t):t})}function $(r,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,t)}function tt(r,t,e,n){function o(i){return i instanceof e?i:new e(function(a){a(i)})}return new(e||(e=Promise))(function(i,a){function u(f){try{c(n.next(f))}catch(d){a(d)}}function p(f){try{c(n.throw(f))}catch(d){a(d)}}function c(f){f.done?i(f.value):o(f.value).then(u,p)}c((n=n.apply(r,t||[])).next())})}function et(r,t){var e={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,a;return a={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function u(c){return function(f){return p([c,f])}}function p(c){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(e=0)),e;)try{if(n=1,o&&(i=c[0]&2?o.return:c[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,c[1])).done)return i;switch(o=0,i&&(c=[c[0]&2,i.value]),c[0]){case 0:case 1:i=c;break;case 4:return e.label++,{value:c[1],done:!1};case 5:e.label++,o=c[1],c=[0];continue;case 7:c=e.ops.pop(),e.trys.pop();continue;default:if(i=e.trys,!(i=i.length>0&&i[i.length-1])&&(c[0]===6||c[0]===2)){e=0;continue}if(c[0]===3&&(!i||c[1]>i[0]&&c[1]<i[3])){e.label=c[1];break}if(c[0]===6&&e.label<i[1]){e.label=i[1],i=c;break}if(i&&e.label<i[2]){e.label=i[2],e.ops.push(c);break}i[2]&&e.ops.pop(),e.trys.pop();continue}c=t.call(r,e)}catch(f){c=[6,f],o=0}finally{n=i=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}var T=Object.create?function(r,t,e,n){n===void 0&&(n=e);var o=Object.getOwnPropertyDescriptor(t,e);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(r,n,o)}:function(r,t,e,n){n===void 0&&(n=e),r[n]=t[e]};function rt(r,t){for(var e in r)e!=="default"&&!Object.prototype.hasOwnProperty.call(t,e)&&T(t,r,e)}function C(r){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&r[t],n=0;if(e)return e.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function F(r,t){var e=typeof Symbol=="function"&&r[Symbol.iterator];if(!e)return r;var n=e.call(r),o,i=[],a;try{for(;(t===void 0||t-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(u){a={error:u}}finally{try{o&&!o.done&&(e=n.return)&&e.call(n)}finally{if(a)throw a.error}}return i}function nt(){for(var r=[],t=0;t<arguments.length;t++)r=r.concat(F(arguments[t]));return r}function it(){for(var r=0,t=0,e=arguments.length;t<e;t++)r+=arguments[t].length;for(var n=Array(r),o=0,t=0;t<e;t++)for(var i=arguments[t],a=0,u=i.length;a<u;a++,o++)n[o]=i[a];return n}function ot(r,t,e){if(e||arguments.length===2)for(var n=0,o=t.length,i;n<o;n++)(i||!(n in t))&&(i||(i=Array.prototype.slice.call(t,0,n)),i[n]=t[n]);return r.concat(i||Array.prototype.slice.call(t))}function S(r){return this instanceof S?(this.v=r,this):new S(r)}function at(r,t,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=e.apply(r,t||[]),o,i=[];return o={},a("next"),a("throw"),a("return"),o[Symbol.asyncIterator]=function(){return this},o;function a(_){n[_]&&(o[_]=function(m){return new Promise(function(w,v){i.push([_,m,w,v])>1||u(_,m)})})}function u(_,m){try{p(n[_](m))}catch(w){d(i[0][3],w)}}function p(_){_.value instanceof S?Promise.resolve(_.value.v).then(c,f):d(i[0][2],_)}function c(_){u("next",_)}function f(_){u("throw",_)}function d(_,m){_(m),i.shift(),i.length&&u(i[0][0],i[0][1])}}function st(r){var t,e;return t={},n("next"),n("throw",function(o){throw o}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(o,i){t[o]=r[o]?function(a){return(e=!e)?{value:S(r[o](a)),done:!1}:i?i(a):a}:i}}function ct(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=r[Symbol.asyncIterator],e;return t?t.call(r):(r=typeof C=="function"?C(r):r[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(i){e[i]=r[i]&&function(a){return new Promise(function(u,p){a=r[i](a),o(u,p,a.done,a.value)})}}function o(i,a,u,p){Promise.resolve(p).then(function(c){i({value:c,done:u})},a)}}function ut(r,t){return Object.defineProperty?Object.defineProperty(r,"raw",{value:t}):r.raw=t,r}var G=Object.create?function(r,t){Object.defineProperty(r,"default",{enumerable:!0,value:t})}:function(r,t){r.default=t};function lt(r){if(r&&r.__esModule)return r;var t={};if(r!=null)for(var e in r)e!=="default"&&Object.prototype.hasOwnProperty.call(r,e)&&T(t,r,e);return G(t,r),t}function pt(r){return r&&r.__esModule?r:{default:r}}function ft(r,t,e,n){if(e==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?r!==t||!n:!t.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?n:e==="a"?n.call(r):n?n.value:t.get(r)}function _t(r,t,e,n,o){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!o)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?r!==t||!o:!t.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?o.call(r,e):o?o.value=e:t.set(r,e),e}function ht(r,t){if(t===null||typeof t!="object"&&typeof t!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof r=="function"?t===r:r.has(t)}/**
2
- * @greymass/eosio-resources v0.7.0
3
- * https://github.com/greymass/eosio-resources
4
- *
5
- * @license
6
- * Copyright (c) 2021 Greymass Inc. All Rights Reserved.
7
- *
8
- * Redistribution and use in source and binary forms, with or without modification,
9
- * are permitted provided that the following conditions are met:
10
- *
11
- * 1. Redistribution of source code must retain the above copyright notice, this
12
- * list of conditions and the following disclaimer.
13
- *
14
- * 2. Redistribution in binary form must reproduce the above copyright notice,
15
- * this list of conditions and the following disclaimer in the documentation
16
- * and/or other materials provided with the distribution.
17
- *
18
- * 3. Neither the name of the copyright holder nor the names of its contributors
19
- * may be used to endorse or promote products derived from this software without
20
- * specific prior written permission.
21
- *
22
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25
- * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
26
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31
- * OF THE POSSIBILITY OF SUCH DAMAGE.
32
- *
33
- * YOU ACKNOWLEDGE THAT THIS SOFTWARE IS NOT DESIGNED, LICENSED OR INTENDED FOR USE
34
- * IN THE DESIGN, CONSTRUCTION, OPERATION OR MAINTENANCE OF ANY MILITARY FACILITY.
35
- */class h extends s.AU{constructor(){super(...arguments),this.default_block_cpu_limit=s.zM.from(2e5),this.default_block_net_limit=s.zM.from(1048576e3)}get allocated(){return 1-Number(this.weight_ratio)/Number(this.target_weight_ratio)/100}get reserved(){return Number(this.utilization)/Number(this.weight)}get symbol(){return this.min_price.symbol}cast(){return{adjusted_utilization:Number(this.adjusted_utilization),decay_secs:Number(this.decay_secs.value),exponent:Number(this.exponent),utilization:Number(this.utilization),utilization_timestamp:Number(this.utilization_timestamp.value),weight:Number(this.weight),weight_ratio:Number(this.weight_ratio)}}utilization_increase(t,e){const{weight:n}=this,o=s.pB.from(e),i=new(O())(n.value.mul(new(O())(o.value)))/Math.pow(10,15);return Math.ceil(i)}price_function(t){const{exponent:e,weight:n}=this.cast(),o=this.max_price.value,i=this.min_price.value;let a=i;const u=e-1;return u<=0?o:(a+=(o-i)*Math.pow(t/n,u),a)}price_integral_delta(t,e){const{exponent:n,weight:o}=this.cast(),i=this.max_price.value,a=this.min_price.value,u=(i-a)/n,p=t/o,c=e/o;return a*c-a*p+u*Math.pow(c,n)-u*Math.pow(p,n)}fee(t,e){const{utilization:n,weight:o}=this.cast();let i=n;const a=i+t;let u=0;return i<e&&(u+=this.price_function(e)*Math.min(t,e-i)/o,i=e),i<a&&(u+=this.price_integral_delta(i,a)),u}determine_adjusted_utilization(t){const{decay_secs:e,utilization:n,utilization_timestamp:o}=this.cast();let{adjusted_utilization:i}=this.cast();if(n<i){const a=t&&t.timestamp?t.timestamp:new Date,u=s.AQ.from(a).toMilliseconds()/1e3,p=i-n;let c=p*Math.exp(-(u-o)/e);c=Math.min(Math.max(c,0),p),i=n+c}return i}}l([s.AU.field("uint8")],h.prototype,"version",void 0),l([s.AU.field("int64")],h.prototype,"weight",void 0),l([s.AU.field("int64")],h.prototype,"weight_ratio",void 0),l([s.AU.field("int64")],h.prototype,"assumed_stake_weight",void 0),l([s.AU.field("int64")],h.prototype,"initial_weight_ratio",void 0),l([s.AU.field("int64")],h.prototype,"target_weight_ratio",void 0),l([s.AU.field("time_point_sec")],h.prototype,"initial_timestamp",void 0),l([s.AU.field("time_point_sec")],h.prototype,"target_timestamp",void 0),l([s.AU.field("float64")],h.prototype,"exponent",void 0),l([s.AU.field("uint32")],h.prototype,"decay_secs",void 0),l([s.AU.field("asset")],h.prototype,"min_price",void 0),l([s.AU.field("asset")],h.prototype,"max_price",void 0),l([s.AU.field("int64")],h.prototype,"utilization",void 0),l([s.AU.field("int64")],h.prototype,"adjusted_utilization",void 0),l([s.AU.field("time_point_sec")],h.prototype,"utilization_timestamp",void 0);let N=class extends h{constructor(){super(...arguments),this.per_day=t=>this.us_per_day(t),this.frac=(t,e)=>this.frac_by_us(t,e),this.frac_by_ms=(t,e)=>this.frac_by_us(t,e*1e3),this.price_per=(t,e=1e3,n)=>this.price_per_us(t,e,n),this.price_per_ms=(t,e=1,n)=>this.price_per_us(t,e*1e3,n)}ms_per_day(t){return this.us_per_day(t)/1e3}us_per_day(t){const e=t&&t.virtual_block_cpu_limit?t.virtual_block_cpu_limit:this.default_block_cpu_limit;return Number(e)*2*60*60*24}weight_to_us(t,e){return Math.ceil(e*Number(t)/g)}us_to_weight(t,e){return Math.floor(e/Number(t)*g)}frac_by_us(t,e){const{weight:n}=this.cast(),o=this.us_to_weight(t.cpu,e)/n;return Math.floor(o*Math.pow(10,15))}price_per_us(t,e=1e3,n){const o=s.pB.from(this.frac(t,e)),i=this.utilization_increase(t.cpu,o),a=this.determine_adjusted_utilization(n),u=this.fee(i,a),p=Math.pow(10,4);return Math.ceil(u*p)/p}};N=l([s.AU.type("powerupstateresourcecpu")],N);let z=class extends h{constructor(){super(...arguments),this.per_day=t=>this.bytes_per_day(t),this.frac=(t,e)=>this.frac_by_bytes(t,e),this.frac_by_kb=(t,e)=>this.frac_by_bytes(t,e*1e3),this.price_per=(t,e=1e3,n)=>this.price_per_byte(t,e,n),this.price_per_kb=(t,e=1,n)=>this.price_per_byte(t,e*1e3,n)}kb_per_day(t){return this.bytes_per_day(t)/1e3}bytes_per_day(t){const e=t&&t.virtual_block_net_limit?t.virtual_block_net_limit:this.default_block_net_limit;return Number(e)*2*60*60*24}weight_to_bytes(t,e){return Math.ceil(e*Number(t)/g)}bytes_to_weight(t,e){return Math.floor(e/Number(t)*g)}frac_by_bytes(t,e){const{weight:n}=this.cast(),o=this.bytes_to_weight(t.net,e)/n;return Math.floor(o*Math.pow(10,15))}price_per_byte(t,e=1e3,n){const o=s.pB.from(this.frac(t,e)),i=this.utilization_increase(t.net,o),a=this.determine_adjusted_utilization(n),u=this.fee(i,a),p=Math.pow(10,4);return Math.ceil(u*p)/p}};z=l([s.AU.type("powerupstateresourcenet")],z);let b=class extends s.AU{};l([s.AU.field("uint8")],b.prototype,"version",void 0),l([s.AU.field(z)],b.prototype,"net",void 0),l([s.AU.field(N)],b.prototype,"cpu",void 0),l([s.AU.field("uint32")],b.prototype,"powerup_days",void 0),l([s.AU.field("asset")],b.prototype,"min_powerup_fee",void 0),b=l([s.AU.type("powerupstate")],b);class X{constructor(t){this.parent=t}async get_state(){return(await this.parent.api.v1.chain.get_table_rows({code:"eosio",scope:"",table:"powup.state",type:b})).rows[0]}}let U=class extends s.AU{};l([s.AU.field("asset")],U.prototype,"balance",void 0),l([s.AU.field("float64")],U.prototype,"weight",void 0),U=l([s.AU.type("connector")],U);let P=class extends s.AU{};l([s.AU.field("asset")],P.prototype,"supply",void 0),l([s.AU.field(U)],P.prototype,"base",void 0),l([s.AU.field(U)],P.prototype,"quote",void 0),P=l([s.AU.type("exchange_state")],P);let E=class extends P{price_per(t){const e=this.base.balance.units.toNumber(),n=this.quote.balance.value;return this.get_input(e,n,t)}price_per_kb(t){return this.price_per(t*1e3)}get_input(t,e,n){const o=e*n/(t-n);return o<0?0:o}};E=l([s.AU.type("ramstate")],E);class V{constructor(t){this.parent=t}async get_state(){return(await this.parent.api.v1.chain.get_table_rows({code:"eosio",scope:"eosio",table:"rammarket",type:E})).rows[0]}}let y=class extends s.AU{get reserved(){return Number(this.total_lent.units)/Number(this.total_lendable.units)}get symbol(){return this.total_lent.symbol}get precision(){return this.total_lent.symbol.precision}get value(){const t=10**this.total_unlent.symbol.precision;return Number(this.total_lent.units.adding(this.total_unlent.units).dividing(this.total_rex.units.dividing(t)))/t}price_per(t,e=1e3){const n=s.xR.fromUnits(1e4,this.symbol),i=Number(n.units)/(this.total_rent.value/this.total_unlent.value)*(Number(t.cpu)/g);return Number(n.units)/i*e/Math.pow(10,this.precision)}};l([s.AU.field("uint8")],y.prototype,"version",void 0),l([s.AU.field("asset")],y.prototype,"total_lent",void 0),l([s.AU.field("asset")],y.prototype,"total_unlent",void 0),l([s.AU.field("asset")],y.prototype,"total_rent",void 0),l([s.AU.field("asset")],y.prototype,"total_lendable",void 0),l([s.AU.field("asset")],y.prototype,"total_rex",void 0),l([s.AU.field("asset")],y.prototype,"namebid_proceeds",void 0),l([s.AU.field("uint64")],y.prototype,"loan_num",void 0),y=l([s.AU.type("rexstate")],y);class q{constructor(t){this.parent=t}async get_state(){return(await this.parent.api.v1.chain.get_table_rows({code:"eosio",scope:"eosio",table:"rexpool",type:y})).rows[0]}}const g=new(O())(1e3*1e3);class B{constructor(t){if(this.sampleAccount="b1",this.symbol="4,EOS",this.v1={powerup:new X(this),ram:new V(this),rex:new q(this)},t.sampleAccount&&(this.sampleAccount=t.sampleAccount),t.symbol&&(this.symbol=t.symbol),t.api)this.api=t.api;else if(t.url)this.api=new s.lP({provider:new s.c6(t.url,t)});else throw new Error("Missing url or api client")}async getSampledUsage(){const t=await this.api.v1.chain.get_account(this.sampleAccount),e=s.pB.from(t.cpu_limit.max.value.mul(g)),n=s.pB.from(t.net_limit.max.value.mul(g)),o=s.pB.from(t.cpu_weight.value),i=s.pB.from(t.net_weight.value);return{account:t,cpu:D(e.value,o.value),net:D(n.value,i.value)}}}B.__className="Resources";function D(r,t){let e=r.div(t);const n=new(O())(0),o=new(O())(1);return r.mod(t).gt(n)&&(e=e.sub(o)),s.pB.from(e)}}}]);