@xchainjs/xchain-doge 0.2.1 → 0.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/lib/client.d.ts +2 -12
- package/lib/const.d.ts +2 -0
- package/lib/index.esm.js +22 -135
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +15 -126
- package/lib/index.js.map +1 -1
- package/package.json +5 -5
- package/CHANGELOG.md +0 -43
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.
|
|
@@ -64885,7 +64885,7 @@ const chainToString = Object.assign((chainId) => {
|
|
|
64885
64885
|
[Chain.Polkadot]: 'Polkadot',
|
|
64886
64886
|
[Chain.Terra]: 'Terra',
|
|
64887
64887
|
[Chain.Doge]: 'Dogecoin',
|
|
64888
|
-
});
|
|
64888
|
+
});
|
|
64889
64889
|
|
|
64890
64890
|
var Denomination;
|
|
64891
64891
|
(function (Denomination) {
|
|
@@ -65066,27 +65066,6 @@ const AssetRuneERC20Testnet = {
|
|
|
65066
65066
|
ticker: RUNE_TICKER,
|
|
65067
65067
|
synth: false,
|
|
65068
65068
|
};
|
|
65069
|
-
const SYNTH_DELIMITER = '/';
|
|
65070
|
-
const NON_SYNTH_DELIMITER = '.';
|
|
65071
|
-
/**
|
|
65072
|
-
* Returns an `Asset` as a string using following naming convention:
|
|
65073
|
-
*
|
|
65074
|
-
* `AAA.BBB-CCC`
|
|
65075
|
-
* where
|
|
65076
|
-
* chain: `AAA`
|
|
65077
|
-
* ticker (optional): `BBB`
|
|
65078
|
-
* symbol: `BBB-CCC` or `CCC` (if no ticker available)
|
|
65079
|
-
* symbol (synth): `BBB/CCC` or `CCC` (if no ticker available)
|
|
65080
|
-
*
|
|
65081
|
-
* @see https://docs.thorchain.org/developers/transaction-memos#asset-notation
|
|
65082
|
-
*
|
|
65083
|
-
* @param {Asset} asset The given asset.
|
|
65084
|
-
* @returns {string} The string from the given asset.
|
|
65085
|
-
*/
|
|
65086
|
-
const assetToString = ({ chain, symbol, synth }) => {
|
|
65087
|
-
const delimiter = synth ? SYNTH_DELIMITER : NON_SYNTH_DELIMITER;
|
|
65088
|
-
return `${chain}${delimiter}${symbol}`;
|
|
65089
|
-
};
|
|
65090
65069
|
/**
|
|
65091
65070
|
* Currency symbols currently supported
|
|
65092
65071
|
*/
|
|
@@ -65097,77 +65076,7 @@ var AssetCurrencySymbol;
|
|
|
65097
65076
|
AssetCurrencySymbol["SATOSHI"] = "\u26A1";
|
|
65098
65077
|
AssetCurrencySymbol["ETH"] = "\u039E";
|
|
65099
65078
|
AssetCurrencySymbol["USD"] = "$";
|
|
65100
|
-
})(AssetCurrencySymbol || (AssetCurrencySymbol = {}));
|
|
65101
|
-
|
|
65102
|
-
/*! *****************************************************************************
|
|
65103
|
-
Copyright (c) Microsoft Corporation.
|
|
65104
|
-
|
|
65105
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
65106
|
-
purpose with or without fee is hereby granted.
|
|
65107
|
-
|
|
65108
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
65109
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
65110
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
65111
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
65112
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
65113
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
65114
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
65115
|
-
***************************************************************************** */
|
|
65116
|
-
|
|
65117
|
-
function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
65118
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
65119
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
65120
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
65121
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
65122
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
65123
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
65124
|
-
});
|
|
65125
|
-
}
|
|
65126
|
-
|
|
65127
|
-
const axios = require('axios');
|
|
65128
|
-
const midgardBaseUrls = {
|
|
65129
|
-
[xchainClient.Network.Testnet]: ['https://testnet.midgard.thorchain.info'],
|
|
65130
|
-
[xchainClient.Network.Mainnet]: ['https://midgard.ninerealms.com', 'https://midgard.thorswap.net'],
|
|
65131
|
-
};
|
|
65132
|
-
const getMimirDetails = (network = xchainClient.Network.Mainnet) => __awaiter$1(void 0, void 0, void 0, function* () {
|
|
65133
|
-
const path = '/v2/thorchain/mimir';
|
|
65134
|
-
for (const baseUrl of midgardBaseUrls[network]) {
|
|
65135
|
-
try {
|
|
65136
|
-
const { data } = yield axios.get(`${baseUrl}${path}`);
|
|
65137
|
-
return data;
|
|
65138
|
-
}
|
|
65139
|
-
catch (e) {
|
|
65140
|
-
console.error(e);
|
|
65141
|
-
}
|
|
65142
|
-
}
|
|
65143
|
-
throw new Error('Midgard not responding');
|
|
65144
|
-
});
|
|
65145
|
-
const getAllInboundDetails = (network = xchainClient.Network.Mainnet) => __awaiter$1(void 0, void 0, void 0, function* () {
|
|
65146
|
-
const path = '/v2/thorchain/inbound_addresses';
|
|
65147
|
-
for (const baseUrl of midgardBaseUrls[network]) {
|
|
65148
|
-
try {
|
|
65149
|
-
const { data } = yield axios.get(`${baseUrl}${path}`);
|
|
65150
|
-
return data;
|
|
65151
|
-
}
|
|
65152
|
-
catch (e) {
|
|
65153
|
-
console.error(e);
|
|
65154
|
-
}
|
|
65155
|
-
}
|
|
65156
|
-
throw new Error('Midgard not responding');
|
|
65157
|
-
});
|
|
65158
|
-
const getInboundDetails = (chain, network = xchainClient.Network.Mainnet) => __awaiter$1(void 0, void 0, void 0, function* () {
|
|
65159
|
-
const [mimirDetails, allInboundDetails] = yield Promise.all([getMimirDetails(network), getAllInboundDetails(network)]);
|
|
65160
|
-
const inboundDetail = allInboundDetails === null || allInboundDetails === void 0 ? void 0 : allInboundDetails.find((item) => item.chain === chain);
|
|
65161
|
-
const details = {
|
|
65162
|
-
vault: (inboundDetail === null || inboundDetail === void 0 ? void 0 : inboundDetail.address) || '',
|
|
65163
|
-
haltedChain: (inboundDetail === null || inboundDetail === void 0 ? void 0 : inboundDetail.halted) || !!mimirDetails[`HALT${chain}CHAIN`] || !!mimirDetails['HALTCHAINGLOBAL'],
|
|
65164
|
-
haltedTrading: !!mimirDetails['HALTTRADING'] || !!mimirDetails[`HALT${chain}TRADING`],
|
|
65165
|
-
haltedLP: !!mimirDetails['PAUSELP'] || !!mimirDetails[`PAUSELP${chain}`],
|
|
65166
|
-
};
|
|
65167
|
-
if (inboundDetail === null || inboundDetail === void 0 ? void 0 : inboundDetail.router)
|
|
65168
|
-
details.router = inboundDetail.router;
|
|
65169
|
-
return details;
|
|
65170
|
-
});
|
|
65079
|
+
})(AssetCurrencySymbol || (AssetCurrencySymbol = {}));
|
|
65171
65080
|
|
|
65172
65081
|
var inherits_browser$1 = createCommonjsModule$1(function (module) {
|
|
65173
65082
|
if (typeof Object.create === 'function') {
|
|
@@ -85170,7 +85079,9 @@ const getSendTxUrl = ({ blockcypherUrl, network }) => {
|
|
|
85170
85079
|
* @see https://github.com/dogecoin/dogecoin/blob/master/src/validation.h#L58
|
|
85171
85080
|
*/
|
|
85172
85081
|
const MIN_TX_FEE = 100000;
|
|
85173
|
-
const DOGE_DECIMAL = 8;
|
|
85082
|
+
const DOGE_DECIMAL = 8;
|
|
85083
|
+
const LOWER_FEE_BOUND = 40000;
|
|
85084
|
+
const UPPER_FEE_BOUND = 20000000;
|
|
85174
85085
|
|
|
85175
85086
|
const toSochainNetwork = (network) => {
|
|
85176
85087
|
switch (network) {
|
|
@@ -86900,12 +86811,15 @@ class Client extends xchainClient.UTXOClient {
|
|
|
86900
86811
|
*
|
|
86901
86812
|
* @param {DogecoinClientParams} params
|
|
86902
86813
|
*/
|
|
86903
|
-
constructor({ network = xchainClient.Network.Testnet,
|
|
86814
|
+
constructor({ network = xchainClient.Network.Testnet, feeBounds = {
|
|
86815
|
+
lower: LOWER_FEE_BOUND,
|
|
86816
|
+
upper: UPPER_FEE_BOUND,
|
|
86817
|
+
}, sochainUrl = 'https://sochain.com/api/v2', blockcypherUrl = 'https://api.blockcypher.com/v1', phrase, rootDerivationPaths = {
|
|
86904
86818
|
[xchainClient.Network.Mainnet]: `m/44'/3'/0'/0/`,
|
|
86905
86819
|
[xchainClient.Network.Stagenet]: `m/44'/3'/0'/0/`,
|
|
86906
86820
|
[xchainClient.Network.Testnet]: `m/44'/1'/0'/0/`,
|
|
86907
86821
|
}, }) {
|
|
86908
|
-
super(Chain.Doge, { network, rootDerivationPaths, phrase });
|
|
86822
|
+
super(Chain.Doge, { network, rootDerivationPaths, phrase, feeBounds });
|
|
86909
86823
|
this.sochainUrl = '';
|
|
86910
86824
|
this.blockcypherUrl = '';
|
|
86911
86825
|
this.setSochainUrl(sochainUrl);
|
|
@@ -87138,6 +87052,7 @@ class Client extends xchainClient.UTXOClient {
|
|
|
87138
87052
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87139
87053
|
const fromAddressIndex = (params === null || params === void 0 ? void 0 : params.walletIndex) || 0;
|
|
87140
87054
|
const feeRate = params.feeRate || (yield this.getSuggestedFeeRate());
|
|
87055
|
+
xchainClient.checkFeeBounds(this.feeBounds, feeRate);
|
|
87141
87056
|
const { psbt } = yield buildTx({
|
|
87142
87057
|
amount: params.amount,
|
|
87143
87058
|
recipient: params.recipient,
|
|
@@ -87169,34 +87084,6 @@ class Client extends xchainClient.UTXOClient {
|
|
|
87169
87084
|
});
|
|
87170
87085
|
});
|
|
87171
87086
|
}
|
|
87172
|
-
/**
|
|
87173
|
-
* Transaction to THORChain inbound address.
|
|
87174
|
-
*
|
|
87175
|
-
* @param {DepositParams} params The transaction options.
|
|
87176
|
-
* @returns {TxHash} The transaction hash.
|
|
87177
|
-
*
|
|
87178
|
-
* @throws {"halted chain"} Thrown if chain is halted.
|
|
87179
|
-
* @throws {"halted trading"} Thrown if trading is halted.
|
|
87180
|
-
*/
|
|
87181
|
-
deposit({ walletIndex = 0, asset = AssetDOGE, amount, memo }) {
|
|
87182
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
87183
|
-
const inboundDetails = yield getInboundDetails(asset.chain, this.network);
|
|
87184
|
-
if (inboundDetails.haltedChain) {
|
|
87185
|
-
throw new Error(`Halted chain for ${assetToString(asset)}`);
|
|
87186
|
-
}
|
|
87187
|
-
if (inboundDetails.haltedTrading) {
|
|
87188
|
-
throw new Error(`Halted trading for ${assetToString(asset)}`);
|
|
87189
|
-
}
|
|
87190
|
-
const txHash = yield this.transfer({
|
|
87191
|
-
walletIndex,
|
|
87192
|
-
asset,
|
|
87193
|
-
amount,
|
|
87194
|
-
recipient: inboundDetails.vault,
|
|
87195
|
-
memo,
|
|
87196
|
-
});
|
|
87197
|
-
return txHash;
|
|
87198
|
-
});
|
|
87199
|
-
}
|
|
87200
87087
|
}
|
|
87201
87088
|
|
|
87202
87089
|
/**
|
|
@@ -87215,7 +87102,9 @@ const createTxInfo = (params) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
87215
87102
|
|
|
87216
87103
|
exports.Client = Client;
|
|
87217
87104
|
exports.DOGE_DECIMAL = DOGE_DECIMAL;
|
|
87105
|
+
exports.LOWER_FEE_BOUND = LOWER_FEE_BOUND;
|
|
87218
87106
|
exports.MIN_TX_FEE = MIN_TX_FEE;
|
|
87107
|
+
exports.UPPER_FEE_BOUND = UPPER_FEE_BOUND;
|
|
87219
87108
|
exports.broadcastTx = broadcastTx;
|
|
87220
87109
|
exports.buildTx = buildTx;
|
|
87221
87110
|
exports.calcFee = calcFee;
|