edge-currency-accountbased 2.2.4 → 2.4.0

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 (95) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/android/src/main/assets/edge-currency-accountbased/234.chunk.js +35 -0
  3. package/android/src/main/assets/edge-currency-accountbased/248.chunk.js +35 -0
  4. package/android/src/main/assets/edge-currency-accountbased/336.chunk.js +9 -0
  5. package/android/src/main/assets/edge-currency-accountbased/504.chunk.js +2 -0
  6. package/android/src/main/assets/edge-currency-accountbased/612.chunk.js +1 -0
  7. package/android/src/main/assets/edge-currency-accountbased/{945.chunk.js → 814.chunk.js} +8 -8
  8. package/android/src/main/assets/edge-currency-accountbased/935.chunk.js +1 -1
  9. package/android/src/main/assets/edge-currency-accountbased/94.chunk.js +8 -0
  10. package/android/src/main/assets/edge-currency-accountbased/algorand.chunk.js +2 -2
  11. package/android/src/main/assets/edge-currency-accountbased/bnb.chunk.js +4 -4
  12. package/android/src/main/assets/edge-currency-accountbased/edge-currency-accountbased.js +10 -10
  13. package/android/src/main/assets/edge-currency-accountbased/eos.chunk.js +12 -12
  14. package/android/src/main/assets/edge-currency-accountbased/ethereum.chunk.js +5 -5
  15. package/android/src/main/assets/edge-currency-accountbased/filecoin.chunk.js +1 -1
  16. package/android/src/main/assets/edge-currency-accountbased/fio.chunk.js +2 -2
  17. package/android/src/main/assets/edge-currency-accountbased/hedera.chunk.js +2 -2
  18. package/android/src/main/assets/edge-currency-accountbased/polkadot.chunk.js +2 -2
  19. package/android/src/main/assets/edge-currency-accountbased/ripple.chunk.js +5 -5
  20. package/android/src/main/assets/edge-currency-accountbased/solana.chunk.js +3 -3
  21. package/android/src/main/assets/edge-currency-accountbased/stellar.chunk.js +4 -4
  22. package/android/src/main/assets/edge-currency-accountbased/tezos.chunk.js +3 -3
  23. package/android/src/main/assets/edge-currency-accountbased/tron.chunk.js +1 -1
  24. package/android/src/main/assets/edge-currency-accountbased/zcash.chunk.js +2 -2
  25. package/lib/algorand/AlgorandEngine.js +46 -24
  26. package/lib/algorand/algorandInfo.js +8 -7
  27. package/lib/algorand/algorandTestnetInfo.js +8 -7
  28. package/lib/binance/BinanceEngine.js +19 -17
  29. package/lib/binance/binanceInfo.js +10 -7
  30. package/lib/common/types.js +10 -0
  31. package/lib/common/upgradeMemos.js +52 -0
  32. package/lib/common/utf8.js +32 -0
  33. package/lib/common/validateMemos.js +107 -0
  34. package/lib/eos/EosEngine.js +42 -41
  35. package/lib/eos/info/eosCommonInfo.js +10 -0
  36. package/lib/eos/info/eosInfo.js +15 -17
  37. package/lib/eos/info/telosInfo.js +15 -15
  38. package/lib/eos/info/waxInfo.js +15 -16
  39. package/lib/ethereum/EthereumEngine.js +13 -12
  40. package/lib/ethereum/EthereumNetwork.js +16 -14
  41. package/lib/ethereum/info/avalancheInfo.js +9 -7
  42. package/lib/ethereum/info/binancesmartchainInfo.js +9 -7
  43. package/lib/ethereum/info/celoInfo.js +9 -7
  44. package/lib/ethereum/info/ethDevInfo.js +9 -7
  45. package/lib/ethereum/info/ethereumCommonInfo.js +10 -0
  46. package/lib/ethereum/info/ethereumInfo.js +9 -7
  47. package/lib/ethereum/info/ethereumclassicInfo.js +9 -7
  48. package/lib/ethereum/info/ethereumpowInfo.js +9 -7
  49. package/lib/ethereum/info/fantomInfo.js +9 -7
  50. package/lib/ethereum/info/goerliInfo.js +9 -7
  51. package/lib/ethereum/info/kovanInfo.js +9 -7
  52. package/lib/ethereum/info/optimismInfo.js +9 -7
  53. package/lib/ethereum/info/polygonInfo.js +9 -7
  54. package/lib/ethereum/info/pulsechainInfo.js +11 -9
  55. package/lib/ethereum/info/rinkebyInfo.js +9 -7
  56. package/lib/ethereum/info/ropstenInfo.js +9 -7
  57. package/lib/ethereum/info/rskInfo.js +9 -7
  58. package/lib/ethereum/info/zksyncInfo.js +9 -7
  59. package/lib/filecoin/FilecoinEngine.js +21 -15
  60. package/lib/filecoin/filecoinInfo.js +5 -7
  61. package/lib/fio/FioEngine.js +25 -17
  62. package/lib/fio/fioInfo.js +8 -6
  63. package/lib/hedera/HederaEngine.js +22 -18
  64. package/lib/hedera/hederaInfo.js +11 -8
  65. package/lib/hedera/hederaTestnetInfo.js +6 -6
  66. package/lib/index.js +1 -1
  67. package/lib/piratechain/PiratechainEngine.js +469 -0
  68. package/lib/piratechain/PiratechainTools.js +239 -0
  69. package/lib/{zcash → piratechain}/piratechainInfo.js +13 -9
  70. package/lib/piratechain/piratechainTypes.js +177 -0
  71. package/lib/polkadot/PolkadotEngine.js +15 -9
  72. package/lib/polkadot/info/liberlandInfo.js +3 -2
  73. package/lib/polkadot/info/liberlandTestnetInfo.js +3 -2
  74. package/lib/polkadot/info/polkadotInfo.js +8 -5
  75. package/lib/react-native.js +93 -69
  76. package/lib/ripple/RippleEngine.js +53 -75
  77. package/lib/ripple/rippleInfo.js +16 -8
  78. package/lib/solana/SolanaEngine.js +17 -12
  79. package/lib/solana/solanaInfo.js +9 -5
  80. package/lib/stellar/StellarEngine.js +31 -22
  81. package/lib/stellar/stellarInfo.js +16 -7
  82. package/lib/tezos/TezosEngine.js +17 -11
  83. package/lib/tezos/tezosInfo.js +8 -5
  84. package/lib/tron/TronEngine.js +85 -68
  85. package/lib/tron/tronInfo.js +8 -7
  86. package/lib/zcash/ZcashEngine.js +86 -48
  87. package/lib/zcash/ZcashTools.js +10 -34
  88. package/lib/zcash/zcashInfo.js +8 -7
  89. package/lib/zcash/zcashTypes.js +2 -13
  90. package/package.json +4 -6
  91. package/android/src/main/assets/edge-currency-accountbased/124.chunk.js +0 -35
  92. package/android/src/main/assets/edge-currency-accountbased/223.chunk.js +0 -9
  93. package/android/src/main/assets/edge-currency-accountbased/650.chunk.js +0 -1
  94. package/android/src/main/assets/edge-currency-accountbased/689.chunk.js +0 -8
  95. package/android/src/main/assets/edge-currency-accountbased/826.chunk.js +0 -35
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _createNamedExportFrom(obj, localName, importedName) { Object.defineProperty(exports, localName, {enumerable: true, get: () => obj[importedName]}); } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _biggystring = require('biggystring');
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _createNamedExportFrom(obj, localName, importedName) { Object.defineProperty(exports, localName, {enumerable: true, get: () => obj[importedName]}); } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _biggystring = require('biggystring');
2
2
  var _bip39 = require('bip39');
3
3
  var _buffer = require('buffer');
4
4
 
@@ -15,9 +15,6 @@ var _buffer = require('buffer');
15
15
 
16
16
 
17
17
 
18
-
19
-
20
-
21
18
  var _types3 = require('../common/types');
22
19
  var _uriHelpers = require('../common/uriHelpers');
23
20
  var _utils = require('../common/utils');
@@ -34,8 +31,6 @@ var _zcashTypes = require('./zcashTypes');
34
31
 
35
32
 
36
33
 
37
-
38
-
39
34
 
40
35
 
41
36
  constructor(env) {
@@ -49,10 +44,9 @@ var _zcashTypes = require('./zcashTypes');
49
44
  if (RNAccountbased == null) {
50
45
  throw new Error('Need opts')
51
46
  }
52
- const { KeyTool, AddressTool } = RNAccountbased[this.networkInfo.nativeSdk]
47
+ const { Tools } = RNAccountbased.zcash
53
48
 
54
- this.KeyTool = KeyTool
55
- this.AddressTool = AddressTool
49
+ this.nativeTools = Tools
56
50
  }
57
51
 
58
52
  async getDisplayPrivateKey(
@@ -65,12 +59,12 @@ var _zcashTypes = require('./zcashTypes');
65
59
 
66
60
  async getDisplayPublicKey(publicWalletInfo) {
67
61
  const { keys } = _zcashTypes.asSafeZcashWalletInfo.call(void 0, publicWalletInfo)
68
- return _optionalChain([keys, 'access', _ => _.unifiedViewingKeys, 'optionalAccess', _2 => _2.extfvk])
62
+ return keys.publicKey
69
63
  }
70
64
 
71
65
  async getNewWalletBirthdayBlockheight() {
72
66
  try {
73
- return await this.KeyTool.getBirthdayHeight(
67
+ return await this.nativeTools.getBirthdayHeight(
74
68
  this.networkInfo.rpcNode.defaultHost,
75
69
  this.networkInfo.rpcNode.defaultPort
76
70
  )
@@ -80,10 +74,7 @@ var _zcashTypes = require('./zcashTypes');
80
74
  }
81
75
 
82
76
  async isValidAddress(address) {
83
- return (
84
- (await this.AddressTool.isValidShieldedAddress(address)) ||
85
- (await this.AddressTool.isValidTransparentAddress(address))
86
- )
77
+ return await this.nativeTools.isValidAddress(address)
87
78
  }
88
79
 
89
80
  // will actually use MNEMONIC version of private key
@@ -95,13 +86,6 @@ var _zcashTypes = require('./zcashTypes');
95
86
  const isValid = _bip39.validateMnemonic.call(void 0, userInput)
96
87
  if (!isValid)
97
88
  throw new Error(`Invalid ${this.currencyInfo.currencyCode} mnemonic`)
98
- const hexBuffer = await _bip39.mnemonicToSeed.call(void 0, userInput)
99
- const hex = hexBuffer.toString('hex')
100
- const spendKey = await this.KeyTool.deriveSpendingKey(
101
- hex,
102
- this.networkInfo.rpcNode.networkName
103
- )
104
- if (typeof spendKey !== 'string') throw new Error('Invalid spendKey type')
105
89
 
106
90
  // Get current network height for the birthday height
107
91
  const currentNetworkHeight = await this.getNewWalletBirthdayBlockheight()
@@ -122,7 +106,6 @@ var _zcashTypes = require('./zcashTypes');
122
106
 
123
107
  return {
124
108
  [`${pluginId}Mnemonic`]: userInput,
125
- [`${pluginId}SpendKey`]: spendKey,
126
109
  [`${pluginId}BirthdayHeight`]: height
127
110
  }
128
111
  }
@@ -157,21 +140,14 @@ var _zcashTypes = require('./zcashTypes');
157
140
  if (typeof mnemonic !== 'string') {
158
141
  throw new Error('InvalidMnemonic')
159
142
  }
160
- const hexBuffer = await _bip39.mnemonicToSeed.call(void 0, mnemonic)
161
- const hex = hexBuffer.toString('hex')
162
- const unifiedViewingKeys =
163
- await this.KeyTool.deriveViewingKey(
164
- hex,
143
+ const unifiedViewingKey =
144
+ await this.nativeTools.deriveViewingKey(
145
+ mnemonic,
165
146
  this.networkInfo.rpcNode.networkName
166
147
  )
167
- const shieldedAddress = await this.AddressTool.deriveShieldedAddress(
168
- unifiedViewingKeys.extfvk,
169
- this.networkInfo.rpcNode.networkName
170
- )
171
148
  return {
172
149
  birthdayHeight: zcashPrivateKeys.birthdayHeight,
173
- publicKey: shieldedAddress,
174
- unifiedViewingKeys
150
+ publicKey: unifiedViewingKey
175
151
  }
176
152
  }
177
153
 
@@ -12,26 +12,24 @@ const networkInfo = {
12
12
  },
13
13
  defaultBirthday: 1310000,
14
14
  defaultNetworkFee: '1000', // hardcoded default ZEC fee
15
- nativeSdk: 'zcash',
16
15
  transactionQueryLimit: 999
17
16
  }
18
17
 
19
18
  const currencyInfo = {
20
- // Basic currency information:
21
19
  currencyCode: 'ZEC',
22
20
  displayName: 'Zcash',
23
21
  pluginId: 'zcash',
24
22
  requiredConfirmations: 10,
23
+ unsafeBroadcastTx: true,
24
+ unsafeSyncNetwork: true,
25
25
  walletType: 'wallet:zcash',
26
26
 
27
- defaultSettings: {},
28
-
27
+ // Explorers:
29
28
  addressExplorer: 'https://blockchair.com/zcash/address/%s?from=edgeapp',
30
29
  transactionExplorer:
31
30
  'https://blockchair.com/zcash/transaction/%s?from=edgeapp',
32
31
 
33
32
  denominations: [
34
- // An array of Objects of the possible denominations for this currency
35
33
  {
36
34
  name: 'ZEC',
37
35
  multiplier: '100000000',
@@ -39,9 +37,12 @@ const networkInfo = {
39
37
  }
40
38
  ],
41
39
 
42
- metaTokens: [], // Deprecated
40
+ // https://zips.z.cash/zip-0302
41
+ memoOptions: [{ type: 'text', maxLength: 512 }],
43
42
 
44
- unsafeBroadcastTx: true
43
+ // Deprecated:
44
+ defaultSettings: {},
45
+ metaTokens: []
45
46
  }; exports.currencyInfo = currencyInfo
46
47
 
47
48
  const zcash = _innerPlugin.makeOuterPlugin({
@@ -80,10 +80,6 @@ var _types = require('../common/types');
80
80
 
81
81
 
82
82
 
83
-
84
-
85
-
86
-
87
83
 
88
84
 
89
85
 
@@ -123,14 +119,11 @@ var _types = require('../common/types');
123
119
 
124
120
 
125
121
 
122
+
126
123
 
127
124
  const asZecPublicKey = _cleaners.asObject.call(void 0, {
128
125
  birthdayHeight: _cleaners.asNumber,
129
- publicKey: _cleaners.asString,
130
- unifiedViewingKeys: _cleaners.asObject.call(void 0, {
131
- extfvk: _cleaners.asString,
132
- extpub: _cleaners.asString
133
- })
126
+ publicKey: _cleaners.asString
134
127
  }); exports.asZecPublicKey = asZecPublicKey
135
128
 
136
129
 
@@ -140,13 +133,11 @@ var _types = require('../common/types');
140
133
 
141
134
 
142
135
 
143
-
144
136
  const asZcashPrivateKeys = (
145
137
  pluginId
146
138
  ) => {
147
139
  const asKeys = _cleaners.asObject.call(void 0, {
148
140
  [`${pluginId}Mnemonic`]: _cleaners.asString,
149
- [`${pluginId}SpendKey`]: _cleaners.asString,
150
141
  [`${pluginId}BirthdayHeight`]: _cleaners.asNumber
151
142
  })
152
143
 
@@ -155,14 +146,12 @@ var _types = require('../common/types');
155
146
  const clean = asKeys(raw)
156
147
  return {
157
148
  mnemonic: clean[`${pluginId}Mnemonic`] ,
158
- spendKey: clean[`${pluginId}SpendKey`] ,
159
149
  birthdayHeight: clean[`${pluginId}BirthdayHeight`]
160
150
  }
161
151
  },
162
152
  clean => {
163
153
  return {
164
154
  [`${pluginId}Mnemonic`]: clean.mnemonic,
165
- [`${pluginId}SpendKey`]: clean.spendKey,
166
155
  [`${pluginId}BirthdayHeight`]: clean.birthdayHeight
167
156
  }
168
157
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-accountbased",
3
- "version": "2.2.4",
3
+ "version": "2.4.0",
4
4
  "description": "Edge currency plugin for account based currencies",
5
5
  "homepage": "https://edge.app/",
6
6
  "repository": {
@@ -118,7 +118,7 @@
118
118
  "babel-eslint": "^10.1.0",
119
119
  "chai": "^4.2.0",
120
120
  "crypto-browserify": "^3.12.0",
121
- "edge-core-js": "^1.3.7",
121
+ "edge-core-js": "^1.6.0",
122
122
  "esbuild-loader": "^2.20.0",
123
123
  "eslint": "^7.14.0",
124
124
  "eslint-config-standard-kit": "0.15.1",
@@ -140,8 +140,7 @@
140
140
  "path-browserify": "^1.0.1",
141
141
  "prettier": "^2.2.0",
142
142
  "process": "^0.11.10",
143
- "react-native-piratechain": "^0.3.2",
144
- "react-native-zcash": "^0.3.2",
143
+ "react-native-zcash": "0.4.1",
145
144
  "rimraf": "^3.0.2",
146
145
  "stream-browserify": "^2.0.2",
147
146
  "stream-http": "^3.2.0",
@@ -154,7 +153,6 @@
154
153
  "webpack-dev-server": "^4.11.1"
155
154
  },
156
155
  "peerDependencies": {
157
- "react-native-piratechain": "^0.3.2",
158
- "react-native-zcash": "^0.3.2"
156
+ "react-native-zcash": "^0.4.1"
159
157
  }
160
158
  }
@@ -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)}}}]);