@xchainjs/xchain-doge 0.2.0 → 0.2.1
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 +12 -0
- package/README.md +7 -39
- package/lib/blockcypher-api.d.ts +1 -1
- package/lib/client.d.ts +11 -1
- package/lib/index.esm.js +203 -120
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +196 -113
- package/lib/index.js.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -16,6 +16,13 @@ Following peer dependencies have to be installed into your project. These are no
|
|
|
16
16
|
yarn add @xchainjs/xchain-client @xchainjs/xchain-crypto @xchainjs/xchain-util axios bitcoinjs-lib coininfo wif
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
## Documentation
|
|
20
|
+
|
|
21
|
+
### [`xchain doge`](http://docs.xchainjs.org/xchain-client/xchain-doge/)
|
|
22
|
+
[`How xchain-doge works`](http://docs.xchainjs.org/xchain-client/xchain-doge/how-it-works.html)\
|
|
23
|
+
[`How to use xchain-doge`](http://docs.xchainjs.org/xchain-client/xchain-doge/how-to-use.html)
|
|
24
|
+
|
|
25
|
+
|
|
19
26
|
## Service Providers
|
|
20
27
|
|
|
21
28
|
This package uses the following service providers:
|
|
@@ -32,42 +39,3 @@ This package uses the following service providers:
|
|
|
32
39
|
Sochain API rate limits: https://sochain.com/api#rate-limits (300 requests/minute)
|
|
33
40
|
|
|
34
41
|
BlockCypher API rate limits: https://api.blockcypher.com/v1/doge/main (5 requests/second)
|
|
35
|
-
|
|
36
|
-
## Usage
|
|
37
|
-
|
|
38
|
-
Initialize client and use class methods:
|
|
39
|
-
|
|
40
|
-
```
|
|
41
|
-
import { Client, Network } from '../src/client'
|
|
42
|
-
|
|
43
|
-
// Create a new client interface
|
|
44
|
-
const dogeClient = new Client({ network: Network.Testnet })
|
|
45
|
-
|
|
46
|
-
// Set phrase
|
|
47
|
-
dogeClient.setPhrase('phrase here')
|
|
48
|
-
|
|
49
|
-
// Get address
|
|
50
|
-
const address = dogeClient.getAddress()
|
|
51
|
-
|
|
52
|
-
// Get balance
|
|
53
|
-
const balance = await dogeClient.getBalance()
|
|
54
|
-
|
|
55
|
-
// Transfer with feeRate
|
|
56
|
-
const txid = await dogeClient.transfer({ asset: AssetDoge, recipient: 'recipient address here', amount: baseAmount(100, DOGE_DECIMAL), feeRate: 1 })
|
|
57
|
-
|
|
58
|
-
// Transfer with default feeRate (default is `fast`)
|
|
59
|
-
const txid = await dogeClient.transfer({ asset: AssetDoge, recipient: 'recipient address here', amount: baseAmount(100, DOGE_DECIMAL) })
|
|
60
|
-
|
|
61
|
-
// Get fee estimations
|
|
62
|
-
const { fast, fastest, average } = await dogeClient.getFees()
|
|
63
|
-
|
|
64
|
-
// Get feeRate estimations
|
|
65
|
-
const { fast, fastest, average } = await dogeClient.getFeeRates()
|
|
66
|
-
|
|
67
|
-
// Search transactions
|
|
68
|
-
const transactions = await dogeClient.getTransactions({ address: 'address here', limit: 4 })
|
|
69
|
-
|
|
70
|
-
// Get a transaction with a given txId/hash
|
|
71
|
-
const txData = await dogeClient.getTransactionData('b660ee07167cfa32681e2623f3a29dc64a089cabd9a3a07dd17f9028ac956eb8')
|
|
72
|
-
|
|
73
|
-
```
|
package/lib/blockcypher-api.d.ts
CHANGED
package/lib/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address, Balance, Fee, FeeRate, Tx, TxHash, TxHistoryParams, TxParams, TxsPage, UTXOClient, XChainClientParams } from '@xchainjs/xchain-client';
|
|
1
|
+
import { Address, Balance, DepositParams, 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;
|
|
@@ -115,5 +115,15 @@ 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>;
|
|
118
128
|
}
|
|
119
129
|
export { Client };
|
package/lib/index.esm.js
CHANGED
|
@@ -5,7 +5,7 @@ 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 from 'axios';
|
|
8
|
+
import axios$1 from 'axios';
|
|
9
9
|
|
|
10
10
|
/*! *****************************************************************************
|
|
11
11
|
Copyright (c) Microsoft Corporation.
|
|
@@ -61858,7 +61858,7 @@ var sha256$2 = createCommonjsModule(function (module, exports) {
|
|
|
61858
61858
|
* @param {string} phrase
|
|
61859
61859
|
* @returns {boolean} `true` or `false`
|
|
61860
61860
|
*/
|
|
61861
|
-
|
|
61861
|
+
const validatePhrase = (phrase) => {
|
|
61862
61862
|
return src_6(phrase);
|
|
61863
61863
|
};
|
|
61864
61864
|
/**
|
|
@@ -61869,7 +61869,7 @@ var validatePhrase = function (phrase) {
|
|
|
61869
61869
|
*
|
|
61870
61870
|
* @throws {"Invalid BIP39 phrase"} Thrown if phrase is an invalid one.
|
|
61871
61871
|
*/
|
|
61872
|
-
|
|
61872
|
+
const getSeed = (phrase) => {
|
|
61873
61873
|
if (!validatePhrase(phrase)) {
|
|
61874
61874
|
throw new Error('Invalid BIP39 phrase');
|
|
61875
61875
|
}
|
|
@@ -64796,14 +64796,14 @@ var bignumber$1 = createCommonjsModule$1(function (module) {
|
|
|
64796
64796
|
* @param {string | number | BigNumber.Instance} value
|
|
64797
64797
|
* @returns {BigNumber} The BigNumber interface from the given value.
|
|
64798
64798
|
*/
|
|
64799
|
-
|
|
64799
|
+
const bn$1 = (value) => new bignumber$1(value);
|
|
64800
64800
|
/**
|
|
64801
64801
|
* Helper to check whether a BigNumber is valid or not
|
|
64802
64802
|
*
|
|
64803
64803
|
* @param {BigNumber} value
|
|
64804
64804
|
* @returns {boolean} `true` or `false`.
|
|
64805
64805
|
* */
|
|
64806
|
-
|
|
64806
|
+
const isValidBN = (value) => !value.isNaN();
|
|
64807
64807
|
/**
|
|
64808
64808
|
* The enumuration for symbol position.
|
|
64809
64809
|
* `before` or `after`
|
|
@@ -64821,14 +64821,12 @@ var SymbolPosition;
|
|
|
64821
64821
|
* @param {number} decimalPlaces The decimal place. (optional)
|
|
64822
64822
|
* @returns {BigNumber} The BigNumber interface from the given value and decimal.
|
|
64823
64823
|
* */
|
|
64824
|
-
|
|
64825
|
-
|
|
64826
|
-
|
|
64827
|
-
var fixedBN = isValidBN(n) ? n.toFixed(decimalPlaces) : bn$1(0).toFixed(decimalPlaces);
|
|
64824
|
+
const fixedBN = (value, decimalPlaces = 2) => {
|
|
64825
|
+
const n = bn$1(value || 0);
|
|
64826
|
+
const fixedBN = isValidBN(n) ? n.toFixed(decimalPlaces) : bn$1(0).toFixed(decimalPlaces);
|
|
64828
64827
|
return bn$1(fixedBN);
|
|
64829
64828
|
};
|
|
64830
64829
|
|
|
64831
|
-
var _a;
|
|
64832
64830
|
var Chain;
|
|
64833
64831
|
(function (Chain) {
|
|
64834
64832
|
Chain["Binance"] = "BNB";
|
|
@@ -64842,38 +64840,38 @@ var Chain;
|
|
|
64842
64840
|
Chain["Terra"] = "TERRA";
|
|
64843
64841
|
Chain["Doge"] = "DOGE";
|
|
64844
64842
|
})(Chain || (Chain = {}));
|
|
64845
|
-
|
|
64846
|
-
|
|
64847
|
-
|
|
64848
|
-
|
|
64849
|
-
|
|
64850
|
-
|
|
64851
|
-
|
|
64852
|
-
|
|
64853
|
-
|
|
64854
|
-
|
|
64843
|
+
const BNBChain = Chain.Binance;
|
|
64844
|
+
const BTCChain = Chain.Bitcoin;
|
|
64845
|
+
const ETHChain = Chain.Ethereum;
|
|
64846
|
+
const THORChain = Chain.THORChain;
|
|
64847
|
+
const CosmosChain = Chain.Cosmos;
|
|
64848
|
+
const PolkadotChain = Chain.Polkadot;
|
|
64849
|
+
const BCHChain = Chain.BitcoinCash;
|
|
64850
|
+
const LTCChain = Chain.Litecoin;
|
|
64851
|
+
const TerraChain = Chain.Terra;
|
|
64852
|
+
const DOGEChain = Chain.Doge;
|
|
64855
64853
|
/**
|
|
64856
64854
|
* Convert chain to string.
|
|
64857
64855
|
*
|
|
64858
64856
|
* @param {Chain} chainId.
|
|
64859
64857
|
* @returns {string} The string based on the given chain type.
|
|
64860
64858
|
*/
|
|
64861
|
-
|
|
64859
|
+
const chainToString = Object.assign((chainId) => {
|
|
64862
64860
|
if (!(chainId in chainToString))
|
|
64863
64861
|
return 'unknown chain';
|
|
64864
64862
|
return chainToString[chainId];
|
|
64865
|
-
},
|
|
64866
|
-
|
|
64867
|
-
|
|
64868
|
-
|
|
64869
|
-
|
|
64870
|
-
|
|
64871
|
-
|
|
64872
|
-
|
|
64873
|
-
|
|
64874
|
-
|
|
64875
|
-
|
|
64876
|
-
|
|
64863
|
+
}, {
|
|
64864
|
+
[Chain.THORChain]: 'Thorchain',
|
|
64865
|
+
[Chain.Bitcoin]: 'Bitcoin',
|
|
64866
|
+
[Chain.BitcoinCash]: 'Bitcoin Cash',
|
|
64867
|
+
[Chain.Litecoin]: 'Litecoin',
|
|
64868
|
+
[Chain.Ethereum]: 'Ethereum',
|
|
64869
|
+
[Chain.Binance]: 'Binance Chain',
|
|
64870
|
+
[Chain.Cosmos]: 'Cosmos',
|
|
64871
|
+
[Chain.Polkadot]: 'Polkadot',
|
|
64872
|
+
[Chain.Terra]: 'Terra',
|
|
64873
|
+
[Chain.Doge]: 'Dogecoin',
|
|
64874
|
+
});
|
|
64877
64875
|
|
|
64878
64876
|
var Denomination;
|
|
64879
64877
|
(function (Denomination) {
|
|
@@ -64893,9 +64891,7 @@ var Denomination;
|
|
|
64893
64891
|
* @param {unknown} v
|
|
64894
64892
|
* @returns {boolean} `true` or `false`.
|
|
64895
64893
|
* */
|
|
64896
|
-
|
|
64897
|
-
return typeof v === 'string' || typeof v === 'number' || v instanceof bignumber$1;
|
|
64898
|
-
};
|
|
64894
|
+
const isBigNumberValue = (v) => typeof v === 'string' || typeof v === 'number' || v instanceof bignumber$1;
|
|
64899
64895
|
/**
|
|
64900
64896
|
* Default number of asset decimals
|
|
64901
64897
|
* For history reason and by starting the project on Binance chain assets, it's 8 decimal.
|
|
@@ -64906,7 +64902,7 @@ var isBigNumberValue = function (v) {
|
|
|
64906
64902
|
* 0.00000001 RUNE == 1 ð (tor)
|
|
64907
64903
|
* ```
|
|
64908
64904
|
* */
|
|
64909
|
-
|
|
64905
|
+
const ASSET_DECIMAL = 8;
|
|
64910
64906
|
/**
|
|
64911
64907
|
* Factory to create values of assets (e.g. RUNE)
|
|
64912
64908
|
*
|
|
@@ -64915,34 +64911,21 @@ var ASSET_DECIMAL = 8;
|
|
|
64915
64911
|
* @returns {AssetAmount} The asset amount from the given value and decimal.
|
|
64916
64912
|
*
|
|
64917
64913
|
**/
|
|
64918
|
-
|
|
64919
|
-
|
|
64920
|
-
var amount = fixedBN(value, decimal);
|
|
64914
|
+
const assetAmount = (value, decimal = ASSET_DECIMAL) => {
|
|
64915
|
+
const amount = fixedBN(value, decimal);
|
|
64921
64916
|
return {
|
|
64922
64917
|
type: Denomination.Asset,
|
|
64923
|
-
amount:
|
|
64924
|
-
plus:
|
|
64925
|
-
|
|
64926
|
-
|
|
64927
|
-
|
|
64928
|
-
|
|
64929
|
-
|
|
64930
|
-
|
|
64931
|
-
|
|
64932
|
-
|
|
64933
|
-
|
|
64934
|
-
return assetAmount(amount.times(isBigNumberValue(v) ? v : v.amount()), d);
|
|
64935
|
-
},
|
|
64936
|
-
div: function (v, d) {
|
|
64937
|
-
if (d === void 0) { d = decimal; }
|
|
64938
|
-
return assetAmount(amount.div(isBigNumberValue(v) ? v : v.amount()), d);
|
|
64939
|
-
},
|
|
64940
|
-
lt: function (v) { return amount.lt(isBigNumberValue(v) ? v : v.amount()); },
|
|
64941
|
-
lte: function (v) { return amount.lte(isBigNumberValue(v) ? v : v.amount()); },
|
|
64942
|
-
gt: function (v) { return amount.gt(isBigNumberValue(v) ? v : v.amount()); },
|
|
64943
|
-
gte: function (v) { return amount.gte(isBigNumberValue(v) ? v : v.amount()); },
|
|
64944
|
-
eq: function (v) { return amount.eq(isBigNumberValue(v) ? v : v.amount()); },
|
|
64945
|
-
decimal: decimal,
|
|
64918
|
+
amount: () => amount,
|
|
64919
|
+
plus: (v, d = decimal) => assetAmount(amount.plus(isBigNumberValue(v) ? v : v.amount()), d),
|
|
64920
|
+
minus: (v, d = decimal) => assetAmount(amount.minus(isBigNumberValue(v) ? v : v.amount()), d),
|
|
64921
|
+
times: (v, d = decimal) => assetAmount(amount.times(isBigNumberValue(v) ? v : v.amount()), d),
|
|
64922
|
+
div: (v, d = decimal) => assetAmount(amount.div(isBigNumberValue(v) ? v : v.amount()), d),
|
|
64923
|
+
lt: (v) => amount.lt(isBigNumberValue(v) ? v : v.amount()),
|
|
64924
|
+
lte: (v) => amount.lte(isBigNumberValue(v) ? v : v.amount()),
|
|
64925
|
+
gt: (v) => amount.gt(isBigNumberValue(v) ? v : v.amount()),
|
|
64926
|
+
gte: (v) => amount.gte(isBigNumberValue(v) ? v : v.amount()),
|
|
64927
|
+
eq: (v) => amount.eq(isBigNumberValue(v) ? v : v.amount()),
|
|
64928
|
+
decimal,
|
|
64946
64929
|
};
|
|
64947
64930
|
};
|
|
64948
64931
|
/**
|
|
@@ -64952,34 +64935,21 @@ var assetAmount = function (value, decimal) {
|
|
|
64952
64935
|
* @param {number} decimal The decimal places of its associated AssetAmount. (optional)
|
|
64953
64936
|
* @returns {BaseAmount} The base amount from the given value and decimal.
|
|
64954
64937
|
**/
|
|
64955
|
-
|
|
64956
|
-
|
|
64957
|
-
var amount = fixedBN(value, 0);
|
|
64938
|
+
const baseAmount = (value, decimal = ASSET_DECIMAL) => {
|
|
64939
|
+
const amount = fixedBN(value, 0);
|
|
64958
64940
|
return {
|
|
64959
64941
|
type: Denomination.Base,
|
|
64960
|
-
amount:
|
|
64961
|
-
plus:
|
|
64962
|
-
|
|
64963
|
-
|
|
64964
|
-
|
|
64965
|
-
|
|
64966
|
-
|
|
64967
|
-
|
|
64968
|
-
|
|
64969
|
-
|
|
64970
|
-
|
|
64971
|
-
return baseAmount(amount.times(isBigNumberValue(v) ? v : v.amount()), d);
|
|
64972
|
-
},
|
|
64973
|
-
div: function (v, d) {
|
|
64974
|
-
if (d === void 0) { d = decimal; }
|
|
64975
|
-
return baseAmount(amount.div(isBigNumberValue(v) ? v : v.amount()).decimalPlaces(0, bignumber$1.ROUND_DOWN), d);
|
|
64976
|
-
},
|
|
64977
|
-
lt: function (v) { return amount.lt(isBigNumberValue(v) ? v : v.amount()); },
|
|
64978
|
-
lte: function (v) { return amount.lte(isBigNumberValue(v) ? v : v.amount()); },
|
|
64979
|
-
gt: function (v) { return amount.gt(isBigNumberValue(v) ? v : v.amount()); },
|
|
64980
|
-
gte: function (v) { return amount.gte(isBigNumberValue(v) ? v : v.amount()); },
|
|
64981
|
-
eq: function (v) { return amount.eq(isBigNumberValue(v) ? v : v.amount()); },
|
|
64982
|
-
decimal: decimal,
|
|
64942
|
+
amount: () => amount,
|
|
64943
|
+
plus: (v, d = decimal) => baseAmount(amount.plus(isBigNumberValue(v) ? v : v.amount()), d),
|
|
64944
|
+
minus: (v, d = decimal) => baseAmount(amount.minus(isBigNumberValue(v) ? v : v.amount()), d),
|
|
64945
|
+
times: (v, d = decimal) => baseAmount(amount.times(isBigNumberValue(v) ? v : v.amount()), d),
|
|
64946
|
+
div: (v, d = decimal) => baseAmount(amount.div(isBigNumberValue(v) ? v : v.amount()).decimalPlaces(0, bignumber$1.ROUND_DOWN), d),
|
|
64947
|
+
lt: (v) => amount.lt(isBigNumberValue(v) ? v : v.amount()),
|
|
64948
|
+
lte: (v) => amount.lte(isBigNumberValue(v) ? v : v.amount()),
|
|
64949
|
+
gt: (v) => amount.gt(isBigNumberValue(v) ? v : v.amount()),
|
|
64950
|
+
gte: (v) => amount.gte(isBigNumberValue(v) ? v : v.amount()),
|
|
64951
|
+
eq: (v) => amount.eq(isBigNumberValue(v) ? v : v.amount()),
|
|
64952
|
+
decimal,
|
|
64983
64953
|
};
|
|
64984
64954
|
};
|
|
64985
64955
|
/**
|
|
@@ -64988,8 +64958,8 @@ var baseAmount = function (value, decimal) {
|
|
|
64988
64958
|
* @param {AssetAmount} asset
|
|
64989
64959
|
* @returns {BaseAmount} The base amount from the given AssetAmount.
|
|
64990
64960
|
* */
|
|
64991
|
-
|
|
64992
|
-
|
|
64961
|
+
const assetToBase = (asset) => {
|
|
64962
|
+
const value = asset
|
|
64993
64963
|
.amount()
|
|
64994
64964
|
.multipliedBy(Math.pow(10, asset.decimal))
|
|
64995
64965
|
.integerValue();
|
|
@@ -65001,78 +64971,72 @@ var assetToBase = function (asset) {
|
|
|
65001
64971
|
* Based on definition in Thorchain `common`
|
|
65002
64972
|
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
65003
64973
|
*/
|
|
65004
|
-
|
|
64974
|
+
const AssetBNB = { chain: Chain.Binance, symbol: 'BNB', ticker: 'BNB', synth: false };
|
|
65005
64975
|
/**
|
|
65006
64976
|
* Base "chain" asset on bitcoin main net.
|
|
65007
64977
|
*
|
|
65008
64978
|
* Based on definition in Thorchain `common`
|
|
65009
64979
|
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
65010
64980
|
*/
|
|
65011
|
-
|
|
64981
|
+
const AssetBTC = { chain: Chain.Bitcoin, symbol: 'BTC', ticker: 'BTC', synth: false };
|
|
65012
64982
|
/**
|
|
65013
64983
|
* Base "chain" asset on bitcoin cash main net.
|
|
65014
64984
|
*
|
|
65015
64985
|
* Based on definition in Thorchain `common`
|
|
65016
64986
|
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
65017
64987
|
*/
|
|
65018
|
-
|
|
64988
|
+
const AssetBCH = { chain: Chain.BitcoinCash, symbol: 'BCH', ticker: 'BCH', synth: false };
|
|
65019
64989
|
/**
|
|
65020
64990
|
* Base "chain" asset on litecoin main net.
|
|
65021
64991
|
*
|
|
65022
64992
|
* Based on definition in Thorchain `common`
|
|
65023
64993
|
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
65024
64994
|
*/
|
|
65025
|
-
|
|
64995
|
+
const AssetLTC = { chain: Chain.Litecoin, symbol: 'LTC', ticker: 'LTC', synth: false };
|
|
65026
64996
|
/**
|
|
65027
64997
|
* Dogecoin asset
|
|
65028
64998
|
* Based on definition in Thorchain
|
|
65029
64999
|
* @see https://gitlab.com/thorchain/thornode/-/blob/781-add-doge-chain/common/asset.go#L24
|
|
65030
65000
|
*/
|
|
65031
|
-
|
|
65032
|
-
|
|
65033
|
-
* Luna asset
|
|
65034
|
-
* Based on definition in Thorchain
|
|
65035
|
-
* @see TBD
|
|
65036
|
-
*/
|
|
65037
|
-
var AssetLUNA = { chain: Chain.Terra, symbol: 'LUNA', ticker: 'LUNA', synth: false };
|
|
65038
|
-
var RUNE_TICKER = 'RUNE';
|
|
65001
|
+
const AssetDOGE = { chain: Chain.Doge, symbol: 'DOGE', ticker: 'DOGE', synth: false };
|
|
65002
|
+
const RUNE_TICKER = 'RUNE';
|
|
65039
65003
|
/**
|
|
65040
65004
|
* Base "chain" asset on ethereum main net.
|
|
65041
65005
|
*
|
|
65042
65006
|
* Based on definition in Thorchain `common`
|
|
65043
65007
|
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
65044
65008
|
*/
|
|
65045
|
-
|
|
65009
|
+
const AssetETH = { chain: Chain.Ethereum, symbol: 'ETH', ticker: 'ETH', synth: false };
|
|
65046
65010
|
/**
|
|
65047
65011
|
* Base "chain" asset for RUNE-67C on Binance test net.
|
|
65048
65012
|
*
|
|
65049
65013
|
* Based on definition in Thorchain `common`
|
|
65050
65014
|
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
65051
65015
|
*/
|
|
65052
|
-
|
|
65016
|
+
const AssetRune67C = { chain: Chain.Binance, symbol: 'RUNE-67C', ticker: RUNE_TICKER, synth: false };
|
|
65053
65017
|
/**
|
|
65054
65018
|
* Base "chain" asset for RUNE-B1A on Binance main net.
|
|
65055
65019
|
*
|
|
65056
65020
|
* Based on definition in Thorchain `common`
|
|
65057
65021
|
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
65058
65022
|
*/
|
|
65059
|
-
|
|
65023
|
+
const AssetRuneB1A = { chain: Chain.Binance, symbol: 'RUNE-B1A', ticker: RUNE_TICKER, synth: false };
|
|
65060
65024
|
/**
|
|
65061
65025
|
* Base "chain" asset on thorchain main net.
|
|
65062
65026
|
*
|
|
65063
65027
|
* Based on definition in Thorchain `common`
|
|
65064
65028
|
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
65065
65029
|
*/
|
|
65066
|
-
|
|
65030
|
+
const AssetRuneNative = { chain: Chain.THORChain, symbol: RUNE_TICKER, ticker: RUNE_TICKER, synth: false };
|
|
65067
65031
|
/**
|
|
65068
65032
|
* Base "chain" asset for RUNE on ethereum main net.
|
|
65069
65033
|
*
|
|
65070
65034
|
* Based on definition in Thorchain `common`
|
|
65071
65035
|
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
65072
65036
|
*/
|
|
65073
|
-
|
|
65037
|
+
const AssetRuneERC20 = {
|
|
65074
65038
|
chain: Chain.Ethereum,
|
|
65075
|
-
symbol: RUNE_TICKER
|
|
65039
|
+
symbol: `${RUNE_TICKER}-0x3155ba85d5f96b2d030a4966af206230e46849cb`,
|
|
65076
65040
|
ticker: RUNE_TICKER,
|
|
65077
65041
|
synth: false,
|
|
65078
65042
|
};
|
|
@@ -65082,12 +65046,33 @@ var AssetRuneERC20 = {
|
|
|
65082
65046
|
* Based on definition in Thorchain `common`
|
|
65083
65047
|
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
65084
65048
|
*/
|
|
65085
|
-
|
|
65049
|
+
const AssetRuneERC20Testnet = {
|
|
65086
65050
|
chain: Chain.Ethereum,
|
|
65087
|
-
symbol: RUNE_TICKER
|
|
65051
|
+
symbol: `${RUNE_TICKER}-0xd601c6A3a36721320573885A8d8420746dA3d7A0`,
|
|
65088
65052
|
ticker: RUNE_TICKER,
|
|
65089
65053
|
synth: false,
|
|
65090
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
|
+
};
|
|
65091
65076
|
/**
|
|
65092
65077
|
* Currency symbols currently supported
|
|
65093
65078
|
*/
|
|
@@ -65098,7 +65083,77 @@ var AssetCurrencySymbol;
|
|
|
65098
65083
|
AssetCurrencySymbol["SATOSHI"] = "\u26A1";
|
|
65099
65084
|
AssetCurrencySymbol["ETH"] = "\u039E";
|
|
65100
65085
|
AssetCurrencySymbol["USD"] = "$";
|
|
65101
|
-
})(AssetCurrencySymbol || (AssetCurrencySymbol = {}));
|
|
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
|
+
});
|
|
65102
65157
|
|
|
65103
65158
|
var inherits_browser$1 = createCommonjsModule$1(function (module) {
|
|
65104
65159
|
if (typeof Object.create === 'function') {
|
|
@@ -85079,7 +85134,7 @@ const DEFAULT_SUGGESTED_TRANSACTION_FEE = 150000;
|
|
|
85079
85134
|
*/
|
|
85080
85135
|
const getSuggestedTxFee = ({ blockcypherUrl }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85081
85136
|
try {
|
|
85082
|
-
const response = yield axios.get(`${blockcypherUrl}/doge/main`);
|
|
85137
|
+
const response = yield axios$1.get(`${blockcypherUrl}/doge/main`);
|
|
85083
85138
|
return response.data.low_fee_per_kb / 1000; // feePerKb to feePerByte
|
|
85084
85139
|
}
|
|
85085
85140
|
catch (error) {
|
|
@@ -85128,7 +85183,7 @@ const getSendTxUrl$1 = ({ sochainUrl, network }) => {
|
|
|
85128
85183
|
*/
|
|
85129
85184
|
const getAddress = ({ sochainUrl, network, address, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85130
85185
|
const url = `${sochainUrl}/address/${toSochainNetwork(network)}/${address}`;
|
|
85131
|
-
const response = yield axios.get(url);
|
|
85186
|
+
const response = yield axios$1.get(url);
|
|
85132
85187
|
const addressResponse = response.data;
|
|
85133
85188
|
return addressResponse.data;
|
|
85134
85189
|
});
|
|
@@ -85144,7 +85199,7 @@ const getAddress = ({ sochainUrl, network, address, }) => __awaiter(void 0, void
|
|
|
85144
85199
|
*/
|
|
85145
85200
|
const getTx = ({ sochainUrl, network, hash }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85146
85201
|
const url = `${sochainUrl}/get_tx/${toSochainNetwork(network)}/${hash}`;
|
|
85147
|
-
const response = yield axios.get(url);
|
|
85202
|
+
const response = yield axios$1.get(url);
|
|
85148
85203
|
const tx = response.data;
|
|
85149
85204
|
return tx.data;
|
|
85150
85205
|
});
|
|
@@ -85160,7 +85215,7 @@ const getTx = ({ sochainUrl, network, hash }) => __awaiter(void 0, void 0, void
|
|
|
85160
85215
|
*/
|
|
85161
85216
|
const getBalance = ({ sochainUrl, network, address, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85162
85217
|
const url = `${sochainUrl}/get_address_balance/${toSochainNetwork(network)}/${address}`;
|
|
85163
|
-
const response = yield axios.get(url);
|
|
85218
|
+
const response = yield axios$1.get(url);
|
|
85164
85219
|
const balanceResponse = response.data;
|
|
85165
85220
|
const confirmed = assetAmount(balanceResponse.data.confirmed_balance, DOGE_DECIMAL);
|
|
85166
85221
|
const unconfirmed = assetAmount(balanceResponse.data.unconfirmed_balance, DOGE_DECIMAL);
|
|
@@ -85181,10 +85236,10 @@ const getBalance = ({ sochainUrl, network, address, }) => __awaiter(void 0, void
|
|
|
85181
85236
|
const getUnspentTxs = ({ sochainUrl, network, address, startingFromTxId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85182
85237
|
let resp = null;
|
|
85183
85238
|
if (startingFromTxId) {
|
|
85184
|
-
resp = yield axios.get(`${sochainUrl}/get_tx_unspent/${toSochainNetwork(network)}/${address}/${startingFromTxId}`);
|
|
85239
|
+
resp = yield axios$1.get(`${sochainUrl}/get_tx_unspent/${toSochainNetwork(network)}/${address}/${startingFromTxId}`);
|
|
85185
85240
|
}
|
|
85186
85241
|
else {
|
|
85187
|
-
resp = yield axios.get(`${sochainUrl}/get_tx_unspent/${toSochainNetwork(network)}/${address}`);
|
|
85242
|
+
resp = yield axios$1.get(`${sochainUrl}/get_tx_unspent/${toSochainNetwork(network)}/${address}`);
|
|
85188
85243
|
}
|
|
85189
85244
|
const response = resp.data;
|
|
85190
85245
|
const txs = response.data.txs;
|
|
@@ -86531,7 +86586,7 @@ var accumulative = function accumulative (utxos, outputs, feeRate) {
|
|
|
86531
86586
|
* @returns {string} Transaction ID.
|
|
86532
86587
|
*/
|
|
86533
86588
|
const broadcastTxToSochain = ({ txHex, nodeUrl }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86534
|
-
const response = (yield axios.post(nodeUrl, {
|
|
86589
|
+
const response = (yield axios$1.post(nodeUrl, {
|
|
86535
86590
|
tx_hex: txHex,
|
|
86536
86591
|
})).data;
|
|
86537
86592
|
if (response.error) {
|
|
@@ -86547,7 +86602,7 @@ const broadcastTxToSochain = ({ txHex, nodeUrl }) => __awaiter(void 0, void 0, v
|
|
|
86547
86602
|
* @returns {string} Transaction ID.
|
|
86548
86603
|
*/
|
|
86549
86604
|
const broadcastTxToBlockCypher = ({ txHex, nodeUrl }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86550
|
-
const response = (yield axios.post(nodeUrl, {
|
|
86605
|
+
const response = (yield axios$1.post(nodeUrl, {
|
|
86551
86606
|
tx: txHex,
|
|
86552
86607
|
})).data;
|
|
86553
86608
|
if (response.error) {
|
|
@@ -87100,6 +87155,34 @@ class Client extends UTXOClient {
|
|
|
87100
87155
|
});
|
|
87101
87156
|
});
|
|
87102
87157
|
}
|
|
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
|
+
}
|
|
87103
87186
|
}
|
|
87104
87187
|
|
|
87105
87188
|
/**
|