@xchainjs/xchain-bitcoin 0.18.2 → 0.20.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/lib/client.d.ts +5 -13
- package/lib/const.d.ts +2 -0
- package/lib/index.esm.js +42 -141
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +34 -131
- package/lib/index.js.map +1 -1
- package/lib/types/client-types.d.ts +2 -1
- package/lib/types/haskoin-api-types.d.ts +1 -1
- package/lib/utils.d.ts +2 -2
- package/package.json +5 -5
- package/CHANGELOG.md +0 -307
package/lib/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var stream = require('stream');
|
|
|
9
9
|
var string_decoder$1 = require('string_decoder');
|
|
10
10
|
var crypto$1$1 = require('crypto');
|
|
11
11
|
var readableStream = require('readable-stream');
|
|
12
|
-
var axios
|
|
12
|
+
var axios = require('axios');
|
|
13
13
|
|
|
14
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
15
|
|
|
@@ -19,7 +19,7 @@ var stream__default = /*#__PURE__*/_interopDefaultLegacy(stream);
|
|
|
19
19
|
var string_decoder$1__default = /*#__PURE__*/_interopDefaultLegacy(string_decoder$1);
|
|
20
20
|
var crypto$1__default = /*#__PURE__*/_interopDefaultLegacy(crypto$1$1);
|
|
21
21
|
var readableStream__default = /*#__PURE__*/_interopDefaultLegacy(readableStream);
|
|
22
|
-
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios
|
|
22
|
+
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
23
23
|
|
|
24
24
|
/*! *****************************************************************************
|
|
25
25
|
Copyright (c) Microsoft Corporation.
|
|
@@ -64863,27 +64863,29 @@ const fixedBN = (value, decimalPlaces = 2) => {
|
|
|
64863
64863
|
|
|
64864
64864
|
var Chain;
|
|
64865
64865
|
(function (Chain) {
|
|
64866
|
+
Chain["Avalanche"] = "AVAX";
|
|
64866
64867
|
Chain["Binance"] = "BNB";
|
|
64867
64868
|
Chain["Bitcoin"] = "BTC";
|
|
64868
64869
|
Chain["Ethereum"] = "ETH";
|
|
64869
64870
|
Chain["THORChain"] = "THOR";
|
|
64870
64871
|
Chain["Cosmos"] = "GAIA";
|
|
64871
|
-
Chain["Polkadot"] = "POLKA";
|
|
64872
64872
|
Chain["BitcoinCash"] = "BCH";
|
|
64873
64873
|
Chain["Litecoin"] = "LTC";
|
|
64874
64874
|
Chain["Terra"] = "TERRA";
|
|
64875
64875
|
Chain["Doge"] = "DOGE";
|
|
64876
|
+
Chain["Avax"] = "AVAX";
|
|
64876
64877
|
})(Chain || (Chain = {}));
|
|
64878
|
+
const AvalancheChain = Chain.Avalanche;
|
|
64877
64879
|
const BNBChain = Chain.Binance;
|
|
64878
64880
|
const BTCChain = Chain.Bitcoin;
|
|
64879
64881
|
const ETHChain = Chain.Ethereum;
|
|
64880
64882
|
const THORChain = Chain.THORChain;
|
|
64881
64883
|
const CosmosChain = Chain.Cosmos;
|
|
64882
|
-
const PolkadotChain = Chain.Polkadot;
|
|
64883
64884
|
const BCHChain = Chain.BitcoinCash;
|
|
64884
64885
|
const LTCChain = Chain.Litecoin;
|
|
64885
64886
|
const TerraChain = Chain.Terra;
|
|
64886
64887
|
const DOGEChain = Chain.Doge;
|
|
64888
|
+
const AVAXChain = Chain.Avax;
|
|
64887
64889
|
/**
|
|
64888
64890
|
* Convert chain to string.
|
|
64889
64891
|
*
|
|
@@ -64895,6 +64897,7 @@ const chainToString = Object.assign((chainId) => {
|
|
|
64895
64897
|
return 'unknown chain';
|
|
64896
64898
|
return chainToString[chainId];
|
|
64897
64899
|
}, {
|
|
64900
|
+
[Chain.Avalanche]: 'Avalanche',
|
|
64898
64901
|
[Chain.THORChain]: 'Thorchain',
|
|
64899
64902
|
[Chain.Bitcoin]: 'Bitcoin',
|
|
64900
64903
|
[Chain.BitcoinCash]: 'Bitcoin Cash',
|
|
@@ -64902,10 +64905,9 @@ const chainToString = Object.assign((chainId) => {
|
|
|
64902
64905
|
[Chain.Ethereum]: 'Ethereum',
|
|
64903
64906
|
[Chain.Binance]: 'Binance Chain',
|
|
64904
64907
|
[Chain.Cosmos]: 'Cosmos',
|
|
64905
|
-
[Chain.Polkadot]: 'Polkadot',
|
|
64906
64908
|
[Chain.Terra]: 'Terra',
|
|
64907
64909
|
[Chain.Doge]: 'Dogecoin',
|
|
64908
|
-
});
|
|
64910
|
+
});
|
|
64909
64911
|
|
|
64910
64912
|
var Denomination;
|
|
64911
64913
|
(function (Denomination) {
|
|
@@ -64928,7 +64930,7 @@ var Denomination;
|
|
|
64928
64930
|
const isBigNumberValue = (v) => typeof v === 'string' || typeof v === 'number' || v instanceof bignumber$1;
|
|
64929
64931
|
/**
|
|
64930
64932
|
* Default number of asset decimals
|
|
64931
|
-
* For history reason and by starting the project on Binance chain assets, it's 8 decimal.
|
|
64933
|
+
* For history reason and by starting the project on Binance chain assets, it's 8 decimal.F
|
|
64932
64934
|
*
|
|
64933
64935
|
* For example:
|
|
64934
64936
|
* ```
|
|
@@ -64999,6 +65001,11 @@ const assetToBase = (asset) => {
|
|
|
64999
65001
|
.integerValue();
|
|
65000
65002
|
return baseAmount(value, asset.decimal);
|
|
65001
65003
|
};
|
|
65004
|
+
/**
|
|
65005
|
+
* Base "chain" asset of Avalanche chain.
|
|
65006
|
+
*
|
|
65007
|
+
*/
|
|
65008
|
+
const AssetAVAX = { chain: Chain.Avalanche, symbol: 'AVAX', ticker: 'AVAX', synth: false };
|
|
65002
65009
|
/**
|
|
65003
65010
|
* Base "chain" asset of Binance chain.
|
|
65004
65011
|
*
|
|
@@ -65086,27 +65093,8 @@ const AssetRuneERC20Testnet = {
|
|
|
65086
65093
|
ticker: RUNE_TICKER,
|
|
65087
65094
|
synth: false,
|
|
65088
65095
|
};
|
|
65089
|
-
const
|
|
65090
|
-
const
|
|
65091
|
-
/**
|
|
65092
|
-
* Returns an `Asset` as a string using following naming convention:
|
|
65093
|
-
*
|
|
65094
|
-
* `AAA.BBB-CCC`
|
|
65095
|
-
* where
|
|
65096
|
-
* chain: `AAA`
|
|
65097
|
-
* ticker (optional): `BBB`
|
|
65098
|
-
* symbol: `BBB-CCC` or `CCC` (if no ticker available)
|
|
65099
|
-
* symbol (synth): `BBB/CCC` or `CCC` (if no ticker available)
|
|
65100
|
-
*
|
|
65101
|
-
* @see https://docs.thorchain.org/developers/transaction-memos#asset-notation
|
|
65102
|
-
*
|
|
65103
|
-
* @param {Asset} asset The given asset.
|
|
65104
|
-
* @returns {string} The string from the given asset.
|
|
65105
|
-
*/
|
|
65106
|
-
const assetToString = ({ chain, symbol, synth }) => {
|
|
65107
|
-
const delimiter = synth ? SYNTH_DELIMITER : NON_SYNTH_DELIMITER;
|
|
65108
|
-
return `${chain}${delimiter}${symbol}`;
|
|
65109
|
-
};
|
|
65096
|
+
const AssetAtom = { chain: Chain.Cosmos, symbol: 'ATOM', ticker: 'ATOM', synth: false };
|
|
65097
|
+
const AssetLUNA = { chain: Chain.Terra, symbol: 'LUNA', ticker: 'LUNA', synth: false };
|
|
65110
65098
|
/**
|
|
65111
65099
|
* Currency symbols currently supported
|
|
65112
65100
|
*/
|
|
@@ -65117,77 +65105,7 @@ var AssetCurrencySymbol;
|
|
|
65117
65105
|
AssetCurrencySymbol["SATOSHI"] = "\u26A1";
|
|
65118
65106
|
AssetCurrencySymbol["ETH"] = "\u039E";
|
|
65119
65107
|
AssetCurrencySymbol["USD"] = "$";
|
|
65120
|
-
})(AssetCurrencySymbol || (AssetCurrencySymbol = {}));
|
|
65121
|
-
|
|
65122
|
-
/*! *****************************************************************************
|
|
65123
|
-
Copyright (c) Microsoft Corporation.
|
|
65124
|
-
|
|
65125
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
65126
|
-
purpose with or without fee is hereby granted.
|
|
65127
|
-
|
|
65128
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
65129
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
65130
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
65131
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
65132
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
65133
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
65134
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
65135
|
-
***************************************************************************** */
|
|
65136
|
-
|
|
65137
|
-
function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
65138
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
65139
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
65140
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
65141
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
65142
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
65143
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
65144
|
-
});
|
|
65145
|
-
}
|
|
65146
|
-
|
|
65147
|
-
const axios = require('axios');
|
|
65148
|
-
const midgardBaseUrls = {
|
|
65149
|
-
[xchainClient.Network.Testnet]: ['https://testnet.midgard.thorchain.info'],
|
|
65150
|
-
[xchainClient.Network.Mainnet]: ['https://midgard.ninerealms.com', 'https://midgard.thorswap.net'],
|
|
65151
|
-
};
|
|
65152
|
-
const getMimirDetails = (network = xchainClient.Network.Mainnet) => __awaiter$1(void 0, void 0, void 0, function* () {
|
|
65153
|
-
const path = '/v2/thorchain/mimir';
|
|
65154
|
-
for (const baseUrl of midgardBaseUrls[network]) {
|
|
65155
|
-
try {
|
|
65156
|
-
const { data } = yield axios.get(`${baseUrl}${path}`);
|
|
65157
|
-
return data;
|
|
65158
|
-
}
|
|
65159
|
-
catch (e) {
|
|
65160
|
-
console.error(e);
|
|
65161
|
-
}
|
|
65162
|
-
}
|
|
65163
|
-
throw new Error('Midgard not responding');
|
|
65164
|
-
});
|
|
65165
|
-
const getAllInboundDetails = (network = xchainClient.Network.Mainnet) => __awaiter$1(void 0, void 0, void 0, function* () {
|
|
65166
|
-
const path = '/v2/thorchain/inbound_addresses';
|
|
65167
|
-
for (const baseUrl of midgardBaseUrls[network]) {
|
|
65168
|
-
try {
|
|
65169
|
-
const { data } = yield axios.get(`${baseUrl}${path}`);
|
|
65170
|
-
return data;
|
|
65171
|
-
}
|
|
65172
|
-
catch (e) {
|
|
65173
|
-
console.error(e);
|
|
65174
|
-
}
|
|
65175
|
-
}
|
|
65176
|
-
throw new Error('Midgard not responding');
|
|
65177
|
-
});
|
|
65178
|
-
const getInboundDetails = (chain, network = xchainClient.Network.Mainnet) => __awaiter$1(void 0, void 0, void 0, function* () {
|
|
65179
|
-
const [mimirDetails, allInboundDetails] = yield Promise.all([getMimirDetails(network), getAllInboundDetails(network)]);
|
|
65180
|
-
const inboundDetail = allInboundDetails === null || allInboundDetails === void 0 ? void 0 : allInboundDetails.find((item) => item.chain === chain);
|
|
65181
|
-
const details = {
|
|
65182
|
-
vault: (inboundDetail === null || inboundDetail === void 0 ? void 0 : inboundDetail.address) || '',
|
|
65183
|
-
haltedChain: (inboundDetail === null || inboundDetail === void 0 ? void 0 : inboundDetail.halted) || !!mimirDetails[`HALT${chain}CHAIN`] || !!mimirDetails['HALTCHAINGLOBAL'],
|
|
65184
|
-
haltedTrading: !!mimirDetails['HALTTRADING'] || !!mimirDetails[`HALT${chain}TRADING`],
|
|
65185
|
-
haltedLP: !!mimirDetails['PAUSELP'] || !!mimirDetails[`PAUSELP${chain}`],
|
|
65186
|
-
};
|
|
65187
|
-
if (inboundDetail === null || inboundDetail === void 0 ? void 0 : inboundDetail.router)
|
|
65188
|
-
details.router = inboundDetail.router;
|
|
65189
|
-
return details;
|
|
65190
|
-
});
|
|
65108
|
+
})(AssetCurrencySymbol || (AssetCurrencySymbol = {}));
|
|
65191
65109
|
|
|
65192
65110
|
var inherits_browser$1 = createCommonjsModule$1(function (module) {
|
|
65193
65111
|
if (typeof Object.create === 'function') {
|
|
@@ -85166,7 +85084,9 @@ var src_12 = src$3.TransactionBuilder;
|
|
|
85166
85084
|
* @see https://github.com/bitcoin/bitcoin/blob/db88db47278d2e7208c50d16ab10cb355067d071/src/validation.h#L56
|
|
85167
85085
|
*/
|
|
85168
85086
|
const MIN_TX_FEE = 1000;
|
|
85169
|
-
const BTC_DECIMAL = 8;
|
|
85087
|
+
const BTC_DECIMAL = 8;
|
|
85088
|
+
const LOWER_FEE_BOUND = 1;
|
|
85089
|
+
const UPPER_FEE_BOUND = 500;
|
|
85170
85090
|
|
|
85171
85091
|
const DEFAULT_SUGGESTED_TRANSACTION_FEE = 127;
|
|
85172
85092
|
const toSochainNetwork = (network) => {
|
|
@@ -85724,8 +85644,11 @@ withTxHex = false, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
85724
85644
|
// search only confirmed UTXOs if pending UTXO is not allowed
|
|
85725
85645
|
const confirmedOnly = !spendPendingUTXO;
|
|
85726
85646
|
const utxos = yield scanUTXOs({ sochainUrl, haskoinUrl, network, address: sender, confirmedOnly, withTxHex });
|
|
85647
|
+
if (memo && memo.length > 80) {
|
|
85648
|
+
throw new Error('memo too long, must not be longer than 80 chars.');
|
|
85649
|
+
}
|
|
85727
85650
|
if (utxos.length === 0)
|
|
85728
|
-
throw new Error('No
|
|
85651
|
+
throw new Error('No confirmed UTXOs. Please wait until your balance has been confirmed on-chain.');
|
|
85729
85652
|
if (!validateAddress(recipient, network))
|
|
85730
85653
|
throw new Error('Invalid address');
|
|
85731
85654
|
const feeRateWhole = Math.ceil(feeRate);
|
|
@@ -85839,7 +85762,10 @@ class Client extends xchainClient.UTXOClient {
|
|
|
85839
85762
|
*
|
|
85840
85763
|
* @param {BitcoinClientParams} params
|
|
85841
85764
|
*/
|
|
85842
|
-
constructor({ network = xchainClient.Network.Testnet,
|
|
85765
|
+
constructor({ network = xchainClient.Network.Testnet, feeBounds = {
|
|
85766
|
+
lower: LOWER_FEE_BOUND,
|
|
85767
|
+
upper: UPPER_FEE_BOUND,
|
|
85768
|
+
}, sochainUrl = 'https://sochain.com/api/v2', haskoinUrl = {
|
|
85843
85769
|
[xchainClient.Network.Testnet]: 'https://api.haskoin.com/btctest',
|
|
85844
85770
|
[xchainClient.Network.Mainnet]: 'https://api.haskoin.com/btc',
|
|
85845
85771
|
[xchainClient.Network.Stagenet]: 'https://api.haskoin.com/btc',
|
|
@@ -85848,7 +85774,7 @@ class Client extends xchainClient.UTXOClient {
|
|
|
85848
85774
|
[xchainClient.Network.Testnet]: `84'/1'/0'/0/`,
|
|
85849
85775
|
[xchainClient.Network.Stagenet]: `84'/0'/0'/0/`,
|
|
85850
85776
|
}, phrase = '', }) {
|
|
85851
|
-
super(Chain.Bitcoin, { network, rootDerivationPaths, phrase });
|
|
85777
|
+
super(Chain.Bitcoin, { network, rootDerivationPaths, phrase, feeBounds });
|
|
85852
85778
|
this.sochainUrl = '';
|
|
85853
85779
|
this.setSochainUrl(sochainUrl);
|
|
85854
85780
|
this.haskoinUrl = haskoinUrl;
|
|
@@ -86066,12 +85992,15 @@ class Client extends xchainClient.UTXOClient {
|
|
|
86066
85992
|
*
|
|
86067
85993
|
* @param {TxParams&FeeRate} params The transfer options.
|
|
86068
85994
|
* @returns {TxHash} The transaction hash.
|
|
85995
|
+
*
|
|
85996
|
+
* @throws {"memo too long"} Thrown if memo longer than 80 chars.
|
|
86069
85997
|
*/
|
|
86070
85998
|
transfer(params) {
|
|
86071
85999
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86072
86000
|
const fromAddressIndex = (params === null || params === void 0 ? void 0 : params.walletIndex) || 0;
|
|
86073
86001
|
// set the default fee rate to `fast`
|
|
86074
86002
|
const feeRate = params.feeRate || (yield this.getFeeRates())[xchainClient.FeeOption.Fast];
|
|
86003
|
+
xchainClient.checkFeeBounds(this.feeBounds, feeRate);
|
|
86075
86004
|
/**
|
|
86076
86005
|
* do not spend pending UTXOs when adding a memo
|
|
86077
86006
|
* https://github.com/xchainjs/xchainjs-lib/issues/330
|
|
@@ -86086,39 +86015,13 @@ class Client extends xchainClient.UTXOClient {
|
|
|
86086
86015
|
return yield broadcastTx$1({ txHex, haskoinUrl });
|
|
86087
86016
|
});
|
|
86088
86017
|
}
|
|
86089
|
-
/**
|
|
86090
|
-
* Transaction to THORChain inbound address.
|
|
86091
|
-
*
|
|
86092
|
-
* @param {DepositParams} params The transaction options.
|
|
86093
|
-
* @returns {TxHash} The transaction hash.
|
|
86094
|
-
*
|
|
86095
|
-
* @throws {"halted chain"} Thrown if chain is halted.
|
|
86096
|
-
* @throws {"halted trading"} Thrown if trading is halted.
|
|
86097
|
-
*/
|
|
86098
|
-
deposit({ walletIndex = 0, asset = AssetBTC, amount, memo }) {
|
|
86099
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
86100
|
-
const inboundDetails = yield getInboundDetails(asset.chain, this.network);
|
|
86101
|
-
if (inboundDetails.haltedChain) {
|
|
86102
|
-
throw new Error(`Halted chain for ${assetToString(asset)}`);
|
|
86103
|
-
}
|
|
86104
|
-
if (inboundDetails.haltedTrading) {
|
|
86105
|
-
throw new Error(`Halted trading for ${assetToString(asset)}`);
|
|
86106
|
-
}
|
|
86107
|
-
const txHash = yield this.transfer({
|
|
86108
|
-
walletIndex,
|
|
86109
|
-
asset,
|
|
86110
|
-
amount,
|
|
86111
|
-
recipient: inboundDetails.vault,
|
|
86112
|
-
memo,
|
|
86113
|
-
});
|
|
86114
|
-
return txHash;
|
|
86115
|
-
});
|
|
86116
|
-
}
|
|
86117
86018
|
}
|
|
86118
86019
|
|
|
86119
86020
|
exports.BTC_DECIMAL = BTC_DECIMAL;
|
|
86120
86021
|
exports.Client = Client;
|
|
86022
|
+
exports.LOWER_FEE_BOUND = LOWER_FEE_BOUND;
|
|
86121
86023
|
exports.MIN_TX_FEE = MIN_TX_FEE;
|
|
86024
|
+
exports.UPPER_FEE_BOUND = UPPER_FEE_BOUND;
|
|
86122
86025
|
exports.broadcastTx = broadcastTx$1;
|
|
86123
86026
|
exports.buildTx = buildTx;
|
|
86124
86027
|
exports.calcFee = calcFee;
|