@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/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address, Balance,
|
|
1
|
+
import { Address, Balance, Fee, FeeRate, Tx, TxHash, TxHistoryParams, TxParams, TxsPage, UTXOClient, XChainClientParams } from '@xchainjs/xchain-client';
|
|
2
2
|
export declare type DogecoinClientParams = XChainClientParams & {
|
|
3
3
|
sochainUrl?: string;
|
|
4
4
|
blockcypherUrl?: string;
|
|
@@ -16,7 +16,7 @@ declare class Client extends UTXOClient {
|
|
|
16
16
|
*
|
|
17
17
|
* @param {DogecoinClientParams} params
|
|
18
18
|
*/
|
|
19
|
-
constructor({ network, sochainUrl, blockcypherUrl, phrase, rootDerivationPaths, }: DogecoinClientParams);
|
|
19
|
+
constructor({ network, feeBounds, sochainUrl, blockcypherUrl, phrase, rootDerivationPaths, }: DogecoinClientParams);
|
|
20
20
|
/**
|
|
21
21
|
* Set/Update the sochain url.
|
|
22
22
|
*
|
|
@@ -115,15 +115,5 @@ declare class Client extends UTXOClient {
|
|
|
115
115
|
transfer(params: TxParams & {
|
|
116
116
|
feeRate?: FeeRate;
|
|
117
117
|
}): Promise<TxHash>;
|
|
118
|
-
/**
|
|
119
|
-
* Transaction to THORChain inbound address.
|
|
120
|
-
*
|
|
121
|
-
* @param {DepositParams} params The transaction options.
|
|
122
|
-
* @returns {TxHash} The transaction hash.
|
|
123
|
-
*
|
|
124
|
-
* @throws {"halted chain"} Thrown if chain is halted.
|
|
125
|
-
* @throws {"halted trading"} Thrown if trading is halted.
|
|
126
|
-
*/
|
|
127
|
-
deposit({ walletIndex, asset, amount, memo }: DepositParams): Promise<TxHash>;
|
|
128
118
|
}
|
|
129
119
|
export { Client };
|
package/lib/const.d.ts
CHANGED
package/lib/index.esm.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Network, standardFeeRates, calcFees, UTXOClient, TxType } from '@xchainjs/xchain-client';
|
|
1
|
+
import { Network, standardFeeRates, calcFees, UTXOClient, TxType, checkFeeBounds } from '@xchainjs/xchain-client';
|
|
2
2
|
import buffer from 'buffer';
|
|
3
3
|
import events from 'events';
|
|
4
4
|
import stream from 'stream';
|
|
5
5
|
import string_decoder$1 from 'string_decoder';
|
|
6
6
|
import crypto$1$1 from 'crypto';
|
|
7
7
|
import readableStream from 'readable-stream';
|
|
8
|
-
import axios
|
|
8
|
+
import axios from 'axios';
|
|
9
9
|
|
|
10
10
|
/*! *****************************************************************************
|
|
11
11
|
Copyright (c) Microsoft Corporation.
|
|
@@ -64871,7 +64871,7 @@ const chainToString = Object.assign((chainId) => {
|
|
|
64871
64871
|
[Chain.Polkadot]: 'Polkadot',
|
|
64872
64872
|
[Chain.Terra]: 'Terra',
|
|
64873
64873
|
[Chain.Doge]: 'Dogecoin',
|
|
64874
|
-
});
|
|
64874
|
+
});
|
|
64875
64875
|
|
|
64876
64876
|
var Denomination;
|
|
64877
64877
|
(function (Denomination) {
|
|
@@ -65052,27 +65052,6 @@ const AssetRuneERC20Testnet = {
|
|
|
65052
65052
|
ticker: RUNE_TICKER,
|
|
65053
65053
|
synth: false,
|
|
65054
65054
|
};
|
|
65055
|
-
const SYNTH_DELIMITER = '/';
|
|
65056
|
-
const NON_SYNTH_DELIMITER = '.';
|
|
65057
|
-
/**
|
|
65058
|
-
* Returns an `Asset` as a string using following naming convention:
|
|
65059
|
-
*
|
|
65060
|
-
* `AAA.BBB-CCC`
|
|
65061
|
-
* where
|
|
65062
|
-
* chain: `AAA`
|
|
65063
|
-
* ticker (optional): `BBB`
|
|
65064
|
-
* symbol: `BBB-CCC` or `CCC` (if no ticker available)
|
|
65065
|
-
* symbol (synth): `BBB/CCC` or `CCC` (if no ticker available)
|
|
65066
|
-
*
|
|
65067
|
-
* @see https://docs.thorchain.org/developers/transaction-memos#asset-notation
|
|
65068
|
-
*
|
|
65069
|
-
* @param {Asset} asset The given asset.
|
|
65070
|
-
* @returns {string} The string from the given asset.
|
|
65071
|
-
*/
|
|
65072
|
-
const assetToString = ({ chain, symbol, synth }) => {
|
|
65073
|
-
const delimiter = synth ? SYNTH_DELIMITER : NON_SYNTH_DELIMITER;
|
|
65074
|
-
return `${chain}${delimiter}${symbol}`;
|
|
65075
|
-
};
|
|
65076
65055
|
/**
|
|
65077
65056
|
* Currency symbols currently supported
|
|
65078
65057
|
*/
|
|
@@ -65083,77 +65062,7 @@ var AssetCurrencySymbol;
|
|
|
65083
65062
|
AssetCurrencySymbol["SATOSHI"] = "\u26A1";
|
|
65084
65063
|
AssetCurrencySymbol["ETH"] = "\u039E";
|
|
65085
65064
|
AssetCurrencySymbol["USD"] = "$";
|
|
65086
|
-
})(AssetCurrencySymbol || (AssetCurrencySymbol = {}));
|
|
65087
|
-
|
|
65088
|
-
/*! *****************************************************************************
|
|
65089
|
-
Copyright (c) Microsoft Corporation.
|
|
65090
|
-
|
|
65091
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
65092
|
-
purpose with or without fee is hereby granted.
|
|
65093
|
-
|
|
65094
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
65095
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
65096
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
65097
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
65098
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
65099
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
65100
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
65101
|
-
***************************************************************************** */
|
|
65102
|
-
|
|
65103
|
-
function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
65104
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
65105
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
65106
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
65107
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
65108
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
65109
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
65110
|
-
});
|
|
65111
|
-
}
|
|
65112
|
-
|
|
65113
|
-
const axios = require('axios');
|
|
65114
|
-
const midgardBaseUrls = {
|
|
65115
|
-
[Network.Testnet]: ['https://testnet.midgard.thorchain.info'],
|
|
65116
|
-
[Network.Mainnet]: ['https://midgard.ninerealms.com', 'https://midgard.thorswap.net'],
|
|
65117
|
-
};
|
|
65118
|
-
const getMimirDetails = (network = Network.Mainnet) => __awaiter$1(void 0, void 0, void 0, function* () {
|
|
65119
|
-
const path = '/v2/thorchain/mimir';
|
|
65120
|
-
for (const baseUrl of midgardBaseUrls[network]) {
|
|
65121
|
-
try {
|
|
65122
|
-
const { data } = yield axios.get(`${baseUrl}${path}`);
|
|
65123
|
-
return data;
|
|
65124
|
-
}
|
|
65125
|
-
catch (e) {
|
|
65126
|
-
console.error(e);
|
|
65127
|
-
}
|
|
65128
|
-
}
|
|
65129
|
-
throw new Error('Midgard not responding');
|
|
65130
|
-
});
|
|
65131
|
-
const getAllInboundDetails = (network = Network.Mainnet) => __awaiter$1(void 0, void 0, void 0, function* () {
|
|
65132
|
-
const path = '/v2/thorchain/inbound_addresses';
|
|
65133
|
-
for (const baseUrl of midgardBaseUrls[network]) {
|
|
65134
|
-
try {
|
|
65135
|
-
const { data } = yield axios.get(`${baseUrl}${path}`);
|
|
65136
|
-
return data;
|
|
65137
|
-
}
|
|
65138
|
-
catch (e) {
|
|
65139
|
-
console.error(e);
|
|
65140
|
-
}
|
|
65141
|
-
}
|
|
65142
|
-
throw new Error('Midgard not responding');
|
|
65143
|
-
});
|
|
65144
|
-
const getInboundDetails = (chain, network = Network.Mainnet) => __awaiter$1(void 0, void 0, void 0, function* () {
|
|
65145
|
-
const [mimirDetails, allInboundDetails] = yield Promise.all([getMimirDetails(network), getAllInboundDetails(network)]);
|
|
65146
|
-
const inboundDetail = allInboundDetails === null || allInboundDetails === void 0 ? void 0 : allInboundDetails.find((item) => item.chain === chain);
|
|
65147
|
-
const details = {
|
|
65148
|
-
vault: (inboundDetail === null || inboundDetail === void 0 ? void 0 : inboundDetail.address) || '',
|
|
65149
|
-
haltedChain: (inboundDetail === null || inboundDetail === void 0 ? void 0 : inboundDetail.halted) || !!mimirDetails[`HALT${chain}CHAIN`] || !!mimirDetails['HALTCHAINGLOBAL'],
|
|
65150
|
-
haltedTrading: !!mimirDetails['HALTTRADING'] || !!mimirDetails[`HALT${chain}TRADING`],
|
|
65151
|
-
haltedLP: !!mimirDetails['PAUSELP'] || !!mimirDetails[`PAUSELP${chain}`],
|
|
65152
|
-
};
|
|
65153
|
-
if (inboundDetail === null || inboundDetail === void 0 ? void 0 : inboundDetail.router)
|
|
65154
|
-
details.router = inboundDetail.router;
|
|
65155
|
-
return details;
|
|
65156
|
-
});
|
|
65065
|
+
})(AssetCurrencySymbol || (AssetCurrencySymbol = {}));
|
|
65157
65066
|
|
|
65158
65067
|
var inherits_browser$1 = createCommonjsModule$1(function (module) {
|
|
65159
65068
|
if (typeof Object.create === 'function') {
|
|
@@ -85134,7 +85043,7 @@ const DEFAULT_SUGGESTED_TRANSACTION_FEE = 150000;
|
|
|
85134
85043
|
*/
|
|
85135
85044
|
const getSuggestedTxFee = ({ blockcypherUrl }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85136
85045
|
try {
|
|
85137
|
-
const response = yield axios
|
|
85046
|
+
const response = yield axios.get(`${blockcypherUrl}/doge/main`);
|
|
85138
85047
|
return response.data.low_fee_per_kb / 1000; // feePerKb to feePerByte
|
|
85139
85048
|
}
|
|
85140
85049
|
catch (error) {
|
|
@@ -85156,7 +85065,9 @@ const getSendTxUrl = ({ blockcypherUrl, network }) => {
|
|
|
85156
85065
|
* @see https://github.com/dogecoin/dogecoin/blob/master/src/validation.h#L58
|
|
85157
85066
|
*/
|
|
85158
85067
|
const MIN_TX_FEE = 100000;
|
|
85159
|
-
const DOGE_DECIMAL = 8;
|
|
85068
|
+
const DOGE_DECIMAL = 8;
|
|
85069
|
+
const LOWER_FEE_BOUND = 40000;
|
|
85070
|
+
const UPPER_FEE_BOUND = 20000000;
|
|
85160
85071
|
|
|
85161
85072
|
const toSochainNetwork = (network) => {
|
|
85162
85073
|
switch (network) {
|
|
@@ -85183,7 +85094,7 @@ const getSendTxUrl$1 = ({ sochainUrl, network }) => {
|
|
|
85183
85094
|
*/
|
|
85184
85095
|
const getAddress = ({ sochainUrl, network, address, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85185
85096
|
const url = `${sochainUrl}/address/${toSochainNetwork(network)}/${address}`;
|
|
85186
|
-
const response = yield axios
|
|
85097
|
+
const response = yield axios.get(url);
|
|
85187
85098
|
const addressResponse = response.data;
|
|
85188
85099
|
return addressResponse.data;
|
|
85189
85100
|
});
|
|
@@ -85199,7 +85110,7 @@ const getAddress = ({ sochainUrl, network, address, }) => __awaiter(void 0, void
|
|
|
85199
85110
|
*/
|
|
85200
85111
|
const getTx = ({ sochainUrl, network, hash }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85201
85112
|
const url = `${sochainUrl}/get_tx/${toSochainNetwork(network)}/${hash}`;
|
|
85202
|
-
const response = yield axios
|
|
85113
|
+
const response = yield axios.get(url);
|
|
85203
85114
|
const tx = response.data;
|
|
85204
85115
|
return tx.data;
|
|
85205
85116
|
});
|
|
@@ -85215,7 +85126,7 @@ const getTx = ({ sochainUrl, network, hash }) => __awaiter(void 0, void 0, void
|
|
|
85215
85126
|
*/
|
|
85216
85127
|
const getBalance = ({ sochainUrl, network, address, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85217
85128
|
const url = `${sochainUrl}/get_address_balance/${toSochainNetwork(network)}/${address}`;
|
|
85218
|
-
const response = yield axios
|
|
85129
|
+
const response = yield axios.get(url);
|
|
85219
85130
|
const balanceResponse = response.data;
|
|
85220
85131
|
const confirmed = assetAmount(balanceResponse.data.confirmed_balance, DOGE_DECIMAL);
|
|
85221
85132
|
const unconfirmed = assetAmount(balanceResponse.data.unconfirmed_balance, DOGE_DECIMAL);
|
|
@@ -85236,10 +85147,10 @@ const getBalance = ({ sochainUrl, network, address, }) => __awaiter(void 0, void
|
|
|
85236
85147
|
const getUnspentTxs = ({ sochainUrl, network, address, startingFromTxId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85237
85148
|
let resp = null;
|
|
85238
85149
|
if (startingFromTxId) {
|
|
85239
|
-
resp = yield axios
|
|
85150
|
+
resp = yield axios.get(`${sochainUrl}/get_tx_unspent/${toSochainNetwork(network)}/${address}/${startingFromTxId}`);
|
|
85240
85151
|
}
|
|
85241
85152
|
else {
|
|
85242
|
-
resp = yield axios
|
|
85153
|
+
resp = yield axios.get(`${sochainUrl}/get_tx_unspent/${toSochainNetwork(network)}/${address}`);
|
|
85243
85154
|
}
|
|
85244
85155
|
const response = resp.data;
|
|
85245
85156
|
const txs = response.data.txs;
|
|
@@ -86586,7 +86497,7 @@ var accumulative = function accumulative (utxos, outputs, feeRate) {
|
|
|
86586
86497
|
* @returns {string} Transaction ID.
|
|
86587
86498
|
*/
|
|
86588
86499
|
const broadcastTxToSochain = ({ txHex, nodeUrl }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86589
|
-
const response = (yield axios
|
|
86500
|
+
const response = (yield axios.post(nodeUrl, {
|
|
86590
86501
|
tx_hex: txHex,
|
|
86591
86502
|
})).data;
|
|
86592
86503
|
if (response.error) {
|
|
@@ -86602,7 +86513,7 @@ const broadcastTxToSochain = ({ txHex, nodeUrl }) => __awaiter(void 0, void 0, v
|
|
|
86602
86513
|
* @returns {string} Transaction ID.
|
|
86603
86514
|
*/
|
|
86604
86515
|
const broadcastTxToBlockCypher = ({ txHex, nodeUrl }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86605
|
-
const response = (yield axios
|
|
86516
|
+
const response = (yield axios.post(nodeUrl, {
|
|
86606
86517
|
tx: txHex,
|
|
86607
86518
|
})).data;
|
|
86608
86519
|
if (response.error) {
|
|
@@ -86886,12 +86797,15 @@ class Client extends UTXOClient {
|
|
|
86886
86797
|
*
|
|
86887
86798
|
* @param {DogecoinClientParams} params
|
|
86888
86799
|
*/
|
|
86889
|
-
constructor({ network = Network.Testnet,
|
|
86800
|
+
constructor({ network = Network.Testnet, feeBounds = {
|
|
86801
|
+
lower: LOWER_FEE_BOUND,
|
|
86802
|
+
upper: UPPER_FEE_BOUND,
|
|
86803
|
+
}, sochainUrl = 'https://sochain.com/api/v2', blockcypherUrl = 'https://api.blockcypher.com/v1', phrase, rootDerivationPaths = {
|
|
86890
86804
|
[Network.Mainnet]: `m/44'/3'/0'/0/`,
|
|
86891
86805
|
[Network.Stagenet]: `m/44'/3'/0'/0/`,
|
|
86892
86806
|
[Network.Testnet]: `m/44'/1'/0'/0/`,
|
|
86893
86807
|
}, }) {
|
|
86894
|
-
super(Chain.Doge, { network, rootDerivationPaths, phrase });
|
|
86808
|
+
super(Chain.Doge, { network, rootDerivationPaths, phrase, feeBounds });
|
|
86895
86809
|
this.sochainUrl = '';
|
|
86896
86810
|
this.blockcypherUrl = '';
|
|
86897
86811
|
this.setSochainUrl(sochainUrl);
|
|
@@ -87124,6 +87038,7 @@ class Client extends UTXOClient {
|
|
|
87124
87038
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87125
87039
|
const fromAddressIndex = (params === null || params === void 0 ? void 0 : params.walletIndex) || 0;
|
|
87126
87040
|
const feeRate = params.feeRate || (yield this.getSuggestedFeeRate());
|
|
87041
|
+
checkFeeBounds(this.feeBounds, feeRate);
|
|
87127
87042
|
const { psbt } = yield buildTx({
|
|
87128
87043
|
amount: params.amount,
|
|
87129
87044
|
recipient: params.recipient,
|
|
@@ -87155,34 +87070,6 @@ class Client extends UTXOClient {
|
|
|
87155
87070
|
});
|
|
87156
87071
|
});
|
|
87157
87072
|
}
|
|
87158
|
-
/**
|
|
87159
|
-
* Transaction to THORChain inbound address.
|
|
87160
|
-
*
|
|
87161
|
-
* @param {DepositParams} params The transaction options.
|
|
87162
|
-
* @returns {TxHash} The transaction hash.
|
|
87163
|
-
*
|
|
87164
|
-
* @throws {"halted chain"} Thrown if chain is halted.
|
|
87165
|
-
* @throws {"halted trading"} Thrown if trading is halted.
|
|
87166
|
-
*/
|
|
87167
|
-
deposit({ walletIndex = 0, asset = AssetDOGE, amount, memo }) {
|
|
87168
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
87169
|
-
const inboundDetails = yield getInboundDetails(asset.chain, this.network);
|
|
87170
|
-
if (inboundDetails.haltedChain) {
|
|
87171
|
-
throw new Error(`Halted chain for ${assetToString(asset)}`);
|
|
87172
|
-
}
|
|
87173
|
-
if (inboundDetails.haltedTrading) {
|
|
87174
|
-
throw new Error(`Halted trading for ${assetToString(asset)}`);
|
|
87175
|
-
}
|
|
87176
|
-
const txHash = yield this.transfer({
|
|
87177
|
-
walletIndex,
|
|
87178
|
-
asset,
|
|
87179
|
-
amount,
|
|
87180
|
-
recipient: inboundDetails.vault,
|
|
87181
|
-
memo,
|
|
87182
|
-
});
|
|
87183
|
-
return txHash;
|
|
87184
|
-
});
|
|
87185
|
-
}
|
|
87186
87073
|
}
|
|
87187
87074
|
|
|
87188
87075
|
/**
|
|
@@ -87199,5 +87086,5 @@ const createTxInfo = (params) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
87199
87086
|
};
|
|
87200
87087
|
});
|
|
87201
87088
|
|
|
87202
|
-
export { Client, DOGE_DECIMAL, MIN_TX_FEE, broadcastTx, buildTx, calcFee, createTxInfo, getDefaultFees, getDefaultFeesWithRates, getPrefix, getSendTxUrl, scanUTXOs, validateAddress };
|
|
87089
|
+
export { Client, DOGE_DECIMAL, LOWER_FEE_BOUND, MIN_TX_FEE, UPPER_FEE_BOUND, broadcastTx, buildTx, calcFee, createTxInfo, getDefaultFees, getDefaultFeesWithRates, getPrefix, getSendTxUrl, scanUTXOs, validateAddress };
|
|
87203
87090
|
//# sourceMappingURL=index.esm.js.map
|