edge-currency-accountbased 2.2.3 → 2.3.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.
- package/CHANGELOG.md +13 -0
- package/android/src/main/assets/edge-currency-accountbased/234.chunk.js +35 -0
- package/android/src/main/assets/edge-currency-accountbased/248.chunk.js +35 -0
- package/android/src/main/assets/edge-currency-accountbased/336.chunk.js +9 -0
- package/android/src/main/assets/edge-currency-accountbased/612.chunk.js +1 -0
- package/android/src/main/assets/edge-currency-accountbased/{945.chunk.js → 814.chunk.js} +8 -8
- package/android/src/main/assets/edge-currency-accountbased/935.chunk.js +1 -1
- package/android/src/main/assets/edge-currency-accountbased/94.chunk.js +8 -0
- package/android/src/main/assets/edge-currency-accountbased/algorand.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/bnb.chunk.js +4 -4
- package/android/src/main/assets/edge-currency-accountbased/edge-currency-accountbased.js +10 -10
- package/android/src/main/assets/edge-currency-accountbased/eos.chunk.js +12 -12
- package/android/src/main/assets/edge-currency-accountbased/ethereum.chunk.js +5 -5
- package/android/src/main/assets/edge-currency-accountbased/filecoin.chunk.js +1 -1
- package/android/src/main/assets/edge-currency-accountbased/fio.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/hedera.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/polkadot.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/ripple.chunk.js +5 -5
- package/android/src/main/assets/edge-currency-accountbased/solana.chunk.js +3 -3
- package/android/src/main/assets/edge-currency-accountbased/stellar.chunk.js +4 -4
- package/android/src/main/assets/edge-currency-accountbased/tezos.chunk.js +3 -3
- package/android/src/main/assets/edge-currency-accountbased/tron.chunk.js +1 -1
- package/android/src/main/assets/edge-currency-accountbased/zcash.chunk.js +2 -2
- package/lib/algorand/AlgorandEngine.js +46 -24
- package/lib/algorand/algorandInfo.js +8 -7
- package/lib/algorand/algorandTestnetInfo.js +8 -7
- package/lib/binance/BinanceEngine.js +19 -17
- package/lib/binance/binanceInfo.js +10 -7
- package/lib/common/types.js +10 -0
- package/lib/common/upgradeMemos.js +52 -0
- package/lib/common/utf8.js +32 -0
- package/lib/common/validateMemos.js +107 -0
- package/lib/eos/EosEngine.js +42 -41
- package/lib/eos/info/eosCommonInfo.js +10 -0
- package/lib/eos/info/eosInfo.js +15 -17
- package/lib/eos/info/telosInfo.js +15 -15
- package/lib/eos/info/waxInfo.js +15 -16
- package/lib/ethereum/EthereumEngine.js +13 -12
- package/lib/ethereum/EthereumNetwork.js +16 -14
- package/lib/ethereum/info/avalancheInfo.js +17 -7
- package/lib/ethereum/info/binancesmartchainInfo.js +9 -7
- package/lib/ethereum/info/celoInfo.js +9 -7
- package/lib/ethereum/info/ethDevInfo.js +9 -7
- package/lib/ethereum/info/ethereumCommonInfo.js +10 -0
- package/lib/ethereum/info/ethereumInfo.js +17 -7
- package/lib/ethereum/info/ethereumclassicInfo.js +9 -7
- package/lib/ethereum/info/ethereumpowInfo.js +9 -7
- package/lib/ethereum/info/fantomInfo.js +9 -7
- package/lib/ethereum/info/goerliInfo.js +9 -7
- package/lib/ethereum/info/kovanInfo.js +9 -7
- package/lib/ethereum/info/optimismInfo.js +9 -7
- package/lib/ethereum/info/polygonInfo.js +9 -7
- package/lib/ethereum/info/pulsechainInfo.js +9 -7
- package/lib/ethereum/info/rinkebyInfo.js +9 -7
- package/lib/ethereum/info/ropstenInfo.js +9 -7
- package/lib/ethereum/info/rskInfo.js +9 -7
- package/lib/ethereum/info/zksyncInfo.js +9 -7
- package/lib/filecoin/FilecoinEngine.js +125 -87
- package/lib/filecoin/Filfox.js +68 -1
- package/lib/filecoin/filecoinInfo.js +5 -7
- package/lib/fio/FioEngine.js +25 -17
- package/lib/fio/fioInfo.js +8 -6
- package/lib/hedera/HederaEngine.js +22 -18
- package/lib/hedera/hederaInfo.js +11 -8
- package/lib/hedera/hederaTestnetInfo.js +6 -6
- package/lib/polkadot/PolkadotEngine.js +15 -9
- package/lib/polkadot/info/liberlandInfo.js +3 -2
- package/lib/polkadot/info/liberlandTestnetInfo.js +3 -2
- package/lib/polkadot/info/polkadotInfo.js +8 -5
- package/lib/ripple/RippleEngine.js +53 -75
- package/lib/ripple/rippleInfo.js +16 -8
- package/lib/solana/SolanaEngine.js +17 -12
- package/lib/solana/solanaInfo.js +9 -5
- package/lib/stellar/StellarEngine.js +31 -22
- package/lib/stellar/stellarInfo.js +16 -7
- package/lib/tezos/TezosEngine.js +17 -11
- package/lib/tezos/tezosInfo.js +8 -5
- package/lib/tron/TronEngine.js +85 -68
- package/lib/tron/tronInfo.js +8 -7
- package/lib/zcash/ZcashEngine.js +23 -23
- package/lib/zcash/piratechainInfo.js +8 -6
- package/lib/zcash/zcashInfo.js +7 -6
- package/package.json +2 -2
- package/android/src/main/assets/edge-currency-accountbased/124.chunk.js +0 -35
- package/android/src/main/assets/edge-currency-accountbased/223.chunk.js +0 -9
- package/android/src/main/assets/edge-currency-accountbased/650.chunk.js +0 -1
- package/android/src/main/assets/edge-currency-accountbased/689.chunk.js +0 -8
- package/android/src/main/assets/edge-currency-accountbased/826.chunk.js +0 -35
package/lib/tron/tronInfo.js
CHANGED
|
@@ -110,21 +110,16 @@ const builtinTokens = {
|
|
|
110
110
|
}; exports.networkInfo = networkInfo
|
|
111
111
|
|
|
112
112
|
const currencyInfo = {
|
|
113
|
-
// Basic currency information:
|
|
114
113
|
currencyCode: 'TRX',
|
|
115
114
|
displayName: 'Tron',
|
|
116
115
|
pluginId: 'tron',
|
|
117
116
|
walletType: 'wallet:tron',
|
|
118
117
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
memoType: 'text',
|
|
122
|
-
|
|
118
|
+
// Explorers:
|
|
123
119
|
addressExplorer: 'https://tronscan.org/#/address/%s',
|
|
124
120
|
transactionExplorer: 'https://tronscan.org/#/transaction/%s',
|
|
125
121
|
|
|
126
122
|
denominations: [
|
|
127
|
-
// An array of Objects of the possible denominations for this currency
|
|
128
123
|
{
|
|
129
124
|
name: 'TRX',
|
|
130
125
|
multiplier: '1000000',
|
|
@@ -132,7 +127,13 @@ const builtinTokens = {
|
|
|
132
127
|
}
|
|
133
128
|
],
|
|
134
129
|
|
|
135
|
-
|
|
130
|
+
// https://developers.tron.network/v3.7/docs/how-to-build-a-transaction-locally
|
|
131
|
+
memoOptions: [{ type: 'text', memoName: 'data', maxLength: 10 }],
|
|
132
|
+
|
|
133
|
+
// Deprecated:
|
|
134
|
+
defaultSettings: {},
|
|
135
|
+
memoType: 'text',
|
|
136
|
+
metaTokens: _tokenHelpers.makeMetaTokens.call(void 0, builtinTokens)
|
|
136
137
|
}; exports.currencyInfo = currencyInfo
|
|
137
138
|
|
|
138
139
|
const tron = _innerPlugin.makeOuterPlugin({
|
package/lib/zcash/ZcashEngine.js
CHANGED
|
@@ -12,6 +12,7 @@ var _types = require('edge-core-js/types');
|
|
|
12
12
|
|
|
13
13
|
var _CurrencyEngine = require('../common/CurrencyEngine');
|
|
14
14
|
|
|
15
|
+
var _upgradeMemos = require('../common/upgradeMemos');
|
|
15
16
|
var _utils = require('../common/utils');
|
|
16
17
|
|
|
17
18
|
|
|
@@ -255,16 +256,17 @@ var _zcashTypes = require('./zcashTypes');
|
|
|
255
256
|
}
|
|
256
257
|
|
|
257
258
|
const edgeTransaction = {
|
|
258
|
-
txid: tx.rawTransactionId,
|
|
259
|
-
date: tx.blockTimeInSeconds,
|
|
260
|
-
currencyCode: this.currencyInfo.currencyCode,
|
|
261
259
|
blockHeight: tx.minedHeight,
|
|
262
|
-
|
|
260
|
+
currencyCode: this.currencyInfo.currencyCode,
|
|
261
|
+
date: tx.blockTimeInSeconds,
|
|
263
262
|
isSend: netNativeAmount.startsWith('-'),
|
|
263
|
+
memos: [],
|
|
264
|
+
nativeAmount: netNativeAmount,
|
|
264
265
|
networkFee: this.networkInfo.defaultNetworkFee,
|
|
266
|
+
otherParams: {},
|
|
265
267
|
ourReceiveAddresses, // blank if you sent money otherwise array of addresses that are yours in this transaction
|
|
266
268
|
signedTx: '',
|
|
267
|
-
|
|
269
|
+
txid: tx.rawTransactionId,
|
|
268
270
|
walletId: this.walletId
|
|
269
271
|
}
|
|
270
272
|
this.addTransaction(this.currencyInfo.currencyCode, edgeTransaction)
|
|
@@ -300,8 +302,10 @@ var _zcashTypes = require('./zcashTypes');
|
|
|
300
302
|
}
|
|
301
303
|
|
|
302
304
|
async makeSpend(edgeSpendInfoIn) {
|
|
305
|
+
edgeSpendInfoIn = _upgradeMemos.upgradeMemos.call(void 0, edgeSpendInfoIn, this.currencyInfo)
|
|
303
306
|
if (!this.isSynced()) throw new Error('Cannot spend until wallet is synced')
|
|
304
307
|
const { edgeSpendInfo, currencyCode } = this.makeSpendCheck(edgeSpendInfoIn)
|
|
308
|
+
const { memos = [] } = edgeSpendInfo
|
|
305
309
|
const spendTarget = edgeSpendInfo.spendTargets[0]
|
|
306
310
|
const { publicAddress, nativeAmount } = spendTarget
|
|
307
311
|
|
|
@@ -330,25 +334,19 @@ var _zcashTypes = require('./zcashTypes');
|
|
|
330
334
|
// **********************************
|
|
331
335
|
// Create the unsigned EdgeTransaction
|
|
332
336
|
|
|
333
|
-
const
|
|
334
|
-
uniqueIdentifier: si.uniqueIdentifier,
|
|
335
|
-
memo: si.memo,
|
|
336
|
-
nativeAmount: _nullishCoalesce(si.nativeAmount, () => ( '0')),
|
|
337
|
-
currencyCode,
|
|
338
|
-
publicAddress
|
|
339
|
-
}))
|
|
337
|
+
const txNativeAmount = _biggystring.mul.call(void 0, totalTxAmount, '-1')
|
|
340
338
|
|
|
341
339
|
const edgeTransaction = {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
networkFee: this.networkInfo.defaultNetworkFee,
|
|
349
|
-
ourReceiveAddresses: [],
|
|
350
|
-
signedTx: '',
|
|
351
|
-
|
|
340
|
+
blockHeight: 0,
|
|
341
|
+
currencyCode,
|
|
342
|
+
date: 0,
|
|
343
|
+
isSend: true,
|
|
344
|
+
memos,
|
|
345
|
+
nativeAmount: txNativeAmount,
|
|
346
|
+
networkFee: this.networkInfo.defaultNetworkFee,
|
|
347
|
+
ourReceiveAddresses: [],
|
|
348
|
+
signedTx: '',
|
|
349
|
+
txid: '',
|
|
352
350
|
walletId: this.walletId
|
|
353
351
|
}
|
|
354
352
|
|
|
@@ -364,6 +362,7 @@ var _zcashTypes = require('./zcashTypes');
|
|
|
364
362
|
edgeTransaction,
|
|
365
363
|
opts
|
|
366
364
|
) {
|
|
365
|
+
const { memos } = edgeTransaction
|
|
367
366
|
const zcashPrivateKeys = _zcashTypes.asZcashPrivateKeys.call(void 0, this.pluginId)(
|
|
368
367
|
_optionalChain([opts, 'optionalAccess', _ => _.privateKeys])
|
|
369
368
|
)
|
|
@@ -373,6 +372,7 @@ var _zcashTypes = require('./zcashTypes');
|
|
|
373
372
|
)
|
|
374
373
|
throw new Error('Invalid spend targets')
|
|
375
374
|
|
|
375
|
+
const memo = _optionalChain([memos, 'access', _2 => _2[0], 'optionalAccess', _3 => _3.type]) === 'text' ? memos[0].value : ''
|
|
376
376
|
const spendTarget = edgeTransaction.spendTargets[0]
|
|
377
377
|
const txParams = {
|
|
378
378
|
zatoshi: _biggystring.sub.call(void 0,
|
|
@@ -380,7 +380,7 @@ var _zcashTypes = require('./zcashTypes');
|
|
|
380
380
|
edgeTransaction.networkFee
|
|
381
381
|
),
|
|
382
382
|
toAddress: spendTarget.publicAddress,
|
|
383
|
-
memo
|
|
383
|
+
memo,
|
|
384
384
|
fromAccountIndex: 0,
|
|
385
385
|
spendingKey: zcashPrivateKeys.spendKey
|
|
386
386
|
}
|
|
@@ -19,29 +19,31 @@ const networkInfo = {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const currencyInfo = {
|
|
22
|
-
// Basic currency information:
|
|
23
22
|
currencyCode: 'ARRR',
|
|
24
23
|
displayName: 'Pirate Chain',
|
|
25
24
|
pluginId: 'piratechain',
|
|
26
25
|
requiredConfirmations: 10,
|
|
26
|
+
unsafeBroadcastTx: true,
|
|
27
27
|
walletType: 'wallet:piratechain',
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
// Explorers:
|
|
31
30
|
addressExplorer: '',
|
|
32
31
|
transactionExplorer: 'https://explorer.pirate.black/tx/%s',
|
|
33
32
|
|
|
34
33
|
denominations: [
|
|
35
|
-
// An array of Objects of the possible denominations for this currency
|
|
36
34
|
{
|
|
37
35
|
name: 'ARRR',
|
|
38
36
|
multiplier: '100000000',
|
|
39
37
|
symbol: 'P'
|
|
40
38
|
}
|
|
41
39
|
],
|
|
42
|
-
metaTokens: [], // Deprecated
|
|
43
40
|
|
|
44
|
-
|
|
41
|
+
// Copied from Zcash:
|
|
42
|
+
memoOptions: [{ type: 'text', maxLength: 512 }],
|
|
43
|
+
|
|
44
|
+
// Deprecated:
|
|
45
|
+
defaultSettings: {},
|
|
46
|
+
metaTokens: []
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
const piratechain = _innerPlugin.makeOuterPlugin({
|
package/lib/zcash/zcashInfo.js
CHANGED
|
@@ -17,21 +17,19 @@ const networkInfo = {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const currencyInfo = {
|
|
20
|
-
// Basic currency information:
|
|
21
20
|
currencyCode: 'ZEC',
|
|
22
21
|
displayName: 'Zcash',
|
|
23
22
|
pluginId: 'zcash',
|
|
24
23
|
requiredConfirmations: 10,
|
|
24
|
+
unsafeBroadcastTx: true,
|
|
25
25
|
walletType: 'wallet:zcash',
|
|
26
26
|
|
|
27
|
-
|
|
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
|
-
|
|
40
|
+
// https://zips.z.cash/zip-0302
|
|
41
|
+
memoOptions: [{ type: 'text', maxLength: 512 }],
|
|
43
42
|
|
|
44
|
-
|
|
43
|
+
// Deprecated:
|
|
44
|
+
defaultSettings: {},
|
|
45
|
+
metaTokens: []
|
|
45
46
|
}; exports.currencyInfo = currencyInfo
|
|
46
47
|
|
|
47
48
|
const zcash = _innerPlugin.makeOuterPlugin({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edge-currency-accountbased",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.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.
|
|
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",
|
|
@@ -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)}}}]);
|