@xchainjs/xchain-mayachain-amm 0.1.3 → 0.2.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/index.esm.js +179 -14
- package/lib/index.js +170 -5
- package/lib/wallet.d.ts +44 -3
- package/package.json +5 -5
package/lib/index.esm.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Client, defaultBTCParams, BTCChain } from '@xchainjs/xchain-bitcoin';
|
|
2
|
-
import { Client as Client$
|
|
3
|
-
import { Client as Client$
|
|
1
|
+
import { Client as Client$2, defaultBTCParams, BTCChain } from '@xchainjs/xchain-bitcoin';
|
|
2
|
+
import { Client as Client$4, defaultDashParams, DASHChain } from '@xchainjs/xchain-dash';
|
|
3
|
+
import { Client as Client$3, defaultEthParams, ETHChain, AssetETH } from '@xchainjs/xchain-ethereum';
|
|
4
4
|
import { isApproved, abi } from '@xchainjs/xchain-evm';
|
|
5
|
-
import { Client as Client$
|
|
6
|
-
import {
|
|
7
|
-
import { Client as Client$4, THORChain } from '@xchainjs/xchain-thorchain';
|
|
8
|
-
import { assetToString, getContractAddressFromAsset, CryptoAmount, baseAmount } from '@xchainjs/xchain-util';
|
|
5
|
+
import { Client as Client$1 } from '@xchainjs/xchain-cosmos-sdk';
|
|
6
|
+
import { baseAmount, eqAsset, assetToString, getContractAddressFromAsset, CryptoAmount } from '@xchainjs/xchain-util';
|
|
9
7
|
import { Network } from '@xchainjs/xchain-client';
|
|
8
|
+
import { Client as Client$6, MAYAChain } from '@xchainjs/xchain-mayachain';
|
|
9
|
+
import { Client as Client$5, THORChain } from '@xchainjs/xchain-thorchain';
|
|
10
10
|
import { MayachainQuery } from '@xchainjs/xchain-mayachain-query';
|
|
11
11
|
import { ethers } from 'ethers';
|
|
12
12
|
|
|
@@ -35,6 +35,76 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
const KUJI_DECIMAL = 6;
|
|
39
|
+
const DEFAULT_FEE = baseAmount(5000, KUJI_DECIMAL);
|
|
40
|
+
const KUJIChain = 'KUJI';
|
|
41
|
+
const AssetKUJI = { chain: KUJIChain, symbol: 'KUJI', ticker: 'KUJI', synth: false };
|
|
42
|
+
|
|
43
|
+
const getDefaultClientUrls = () => {
|
|
44
|
+
return {
|
|
45
|
+
[Network.Testnet]: 'https://kujira-testnet-rpc.polkachu.com/',
|
|
46
|
+
[Network.Stagenet]: 'https://rpc.cosmos.directory/kujira/',
|
|
47
|
+
[Network.Mainnet]: 'https://rpc.cosmos.directory/kujira/',
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const getDefaultRootDerivationPaths = () => ({
|
|
51
|
+
[Network.Mainnet]: `44'/118'/0'/0/`,
|
|
52
|
+
[Network.Testnet]: `44'/118'/0'/0/`,
|
|
53
|
+
[Network.Stagenet]: `44'/118'/0'/0/`,
|
|
54
|
+
});
|
|
55
|
+
const getDefaultExplorers = () => ({
|
|
56
|
+
[Network.Mainnet]: 'https://finder.kujira.network/kaiyo-1',
|
|
57
|
+
[Network.Testnet]: 'https://finder.kujira.network/harpoon-4',
|
|
58
|
+
[Network.Stagenet]: 'https://finder.kujira.network/kaiyo-1',
|
|
59
|
+
});
|
|
60
|
+
const defaultClientConfig = {
|
|
61
|
+
chain: AssetKUJI.chain,
|
|
62
|
+
network: Network.Mainnet,
|
|
63
|
+
clientUrls: getDefaultClientUrls(),
|
|
64
|
+
rootDerivationPaths: getDefaultRootDerivationPaths(),
|
|
65
|
+
prefix: 'kujira',
|
|
66
|
+
defaultDecimals: 6,
|
|
67
|
+
defaultFee: DEFAULT_FEE,
|
|
68
|
+
baseDenom: 'ukuji',
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
class Client extends Client$1 {
|
|
72
|
+
constructor(config = defaultClientConfig) {
|
|
73
|
+
super(Object.assign(Object.assign({}, defaultClientConfig), config));
|
|
74
|
+
}
|
|
75
|
+
getAssetInfo() {
|
|
76
|
+
const assetInfo = {
|
|
77
|
+
asset: AssetKUJI,
|
|
78
|
+
decimal: KUJI_DECIMAL,
|
|
79
|
+
};
|
|
80
|
+
return assetInfo;
|
|
81
|
+
}
|
|
82
|
+
getDenom(asset) {
|
|
83
|
+
if (eqAsset(asset, AssetKUJI))
|
|
84
|
+
return this.baseDenom;
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
assetFromDenom(denom) {
|
|
88
|
+
if (denom === this.baseDenom)
|
|
89
|
+
return AssetKUJI;
|
|
90
|
+
return {
|
|
91
|
+
chain: AssetKUJI.chain,
|
|
92
|
+
symbol: denom,
|
|
93
|
+
ticker: '',
|
|
94
|
+
synth: false,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
getExplorerUrl() {
|
|
98
|
+
return getDefaultExplorers()[this.network];
|
|
99
|
+
}
|
|
100
|
+
getExplorerAddressUrl(address) {
|
|
101
|
+
return `${this.getExplorerUrl()}/address/${address}`;
|
|
102
|
+
}
|
|
103
|
+
getExplorerTxUrl(txID) {
|
|
104
|
+
return `${this.getExplorerUrl()}/tx/${txID}`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
38
108
|
class Wallet {
|
|
39
109
|
/**
|
|
40
110
|
* Constructor to create a Wallet
|
|
@@ -47,12 +117,12 @@ class Wallet {
|
|
|
47
117
|
constructor(phrase, network, chainConfigs = {}) {
|
|
48
118
|
const settings = { network, phrase };
|
|
49
119
|
this.clients = {
|
|
50
|
-
BTC: new Client(Object.assign(Object.assign(Object.assign({}, defaultBTCParams), chainConfigs[BTCChain]), settings)),
|
|
51
|
-
ETH: new Client$
|
|
52
|
-
DASH: new Client$
|
|
53
|
-
KUJI: new Client
|
|
54
|
-
THOR: new Client$
|
|
55
|
-
MAYA: new Client$
|
|
120
|
+
BTC: new Client$2(Object.assign(Object.assign(Object.assign({}, defaultBTCParams), chainConfigs[BTCChain]), settings)),
|
|
121
|
+
ETH: new Client$3(Object.assign(Object.assign(Object.assign({}, defaultEthParams), chainConfigs[ETHChain]), settings)),
|
|
122
|
+
DASH: new Client$4(Object.assign(Object.assign(Object.assign({}, defaultDashParams), chainConfigs[DASHChain]), settings)),
|
|
123
|
+
KUJI: new Client(Object.assign(Object.assign(Object.assign({}, defaultClientConfig), chainConfigs[KUJIChain]), settings)),
|
|
124
|
+
THOR: new Client$5(Object.assign(Object.assign({}, chainConfigs[THORChain]), settings)),
|
|
125
|
+
MAYA: new Client$6(Object.assign(Object.assign({}, chainConfigs[MAYAChain]), settings)),
|
|
56
126
|
};
|
|
57
127
|
}
|
|
58
128
|
/**
|
|
@@ -67,7 +137,27 @@ class Wallet {
|
|
|
67
137
|
});
|
|
68
138
|
}
|
|
69
139
|
/**
|
|
70
|
-
*
|
|
140
|
+
* Get wallet chain addresses.
|
|
141
|
+
* @param {Chain[]} chains Optional - Chains of which return the address of. If not provided, it will return
|
|
142
|
+
* the wallet chain addresses
|
|
143
|
+
* @returns the chains addresses
|
|
144
|
+
*/
|
|
145
|
+
getAddresses(chains) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
const _chains = chains || Object.keys(this.clients);
|
|
148
|
+
const tasks = _chains.map((chain) => {
|
|
149
|
+
return this.getAddress(chain);
|
|
150
|
+
});
|
|
151
|
+
const walletAddresses = {};
|
|
152
|
+
const addresses = yield Promise.all(tasks);
|
|
153
|
+
addresses.map((walletAddress, index) => {
|
|
154
|
+
walletAddresses[_chains[index]] = walletAddress;
|
|
155
|
+
});
|
|
156
|
+
return walletAddresses;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Check if an address is valid
|
|
71
161
|
* @param {Chain} chain in which the address has to be valid
|
|
72
162
|
* @param {string} address to validate
|
|
73
163
|
* @returns true if it is a valid address, otherwise, false
|
|
@@ -76,6 +166,81 @@ class Wallet {
|
|
|
76
166
|
const client = this.getChainClient(chain);
|
|
77
167
|
return client.validateAddress(address);
|
|
78
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Get chain balances.
|
|
171
|
+
* @param {Chain} chain - Chains of the assets
|
|
172
|
+
* @param {Assets[]} assets - Optional. Assets of which return the balance
|
|
173
|
+
* @returns {Balance[]} Balances by chain
|
|
174
|
+
*/
|
|
175
|
+
getBalance(chain, assets) {
|
|
176
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
const client = this.getChainClient(chain);
|
|
178
|
+
return client.getBalance(yield this.getAddress(chain), assets);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Get wallet balances. By default, it returns all the wallet balances unless assets are provided, in that case,
|
|
183
|
+
* only asset balances will be returned by chain
|
|
184
|
+
* @param {Assets[]} assets - Optional. Assets of which return the balance
|
|
185
|
+
* @returns {Record<Chain, Balance[]>} Balances by chain
|
|
186
|
+
*/
|
|
187
|
+
getBalances(assets) {
|
|
188
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
+
const chains = assets ? Array.from(new Set(assets.map((asset) => asset.chain))) : Object.keys(this.clients);
|
|
190
|
+
const tasks = chains.map((chain) => __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
return yield this.getBalance(chain, assets === null || assets === void 0 ? void 0 : assets.filter((asset) => asset.chain === chain));
|
|
192
|
+
}));
|
|
193
|
+
const walletBalances = {};
|
|
194
|
+
const balances = yield Promise.all(tasks);
|
|
195
|
+
balances.map((chainBalance, index) => {
|
|
196
|
+
walletBalances[chains[index]] = chainBalance;
|
|
197
|
+
});
|
|
198
|
+
return walletBalances;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Get transaction data from hash
|
|
203
|
+
* @param {Chain} chain - Chain in which the transaction was done
|
|
204
|
+
* @param {string} hash - Hash of the transaction
|
|
205
|
+
* @returns
|
|
206
|
+
*/
|
|
207
|
+
getTransactionData(chain, hash) {
|
|
208
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
+
const client = this.getChainClient(chain);
|
|
210
|
+
return yield client.getTransactionData(hash);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Returns the transaction history of a chain
|
|
215
|
+
* @param {Chain} chain Chain of which return the transaction history
|
|
216
|
+
* @returns {TxsPage} the chain transaction history
|
|
217
|
+
*/
|
|
218
|
+
getTransactionsHistory(chain) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
const client = this.getChainClient(chain);
|
|
221
|
+
return client.getTransactions();
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Get wallet histories. By default, it returns all the wallet histories unless chains are provided, in that case,
|
|
226
|
+
* only chain histories will be returned by chain
|
|
227
|
+
* @param {Chain[]} chains - Optional. Chain of which return the transaction history
|
|
228
|
+
* @returns {TxsPage} the chain transaction history
|
|
229
|
+
*/
|
|
230
|
+
getTransactionsHistories(chains) {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
const _chains = chains || Object.keys(this.clients);
|
|
233
|
+
const tasks = _chains.map((chain) => __awaiter(this, void 0, void 0, function* () {
|
|
234
|
+
return this.getTransactionsHistory(chain);
|
|
235
|
+
}));
|
|
236
|
+
const walletHistories = {};
|
|
237
|
+
const histories = yield Promise.all(tasks);
|
|
238
|
+
histories.map((history, index) => {
|
|
239
|
+
walletHistories[_chains[index]] = history;
|
|
240
|
+
});
|
|
241
|
+
return walletHistories;
|
|
242
|
+
});
|
|
243
|
+
}
|
|
79
244
|
/**
|
|
80
245
|
* Make a transaction
|
|
81
246
|
* @param {TxParams} txParams to make the transfer
|
package/lib/index.js
CHANGED
|
@@ -6,11 +6,11 @@ var xchainBitcoin = require('@xchainjs/xchain-bitcoin');
|
|
|
6
6
|
var xchainDash = require('@xchainjs/xchain-dash');
|
|
7
7
|
var xchainEthereum = require('@xchainjs/xchain-ethereum');
|
|
8
8
|
var xchainEvm = require('@xchainjs/xchain-evm');
|
|
9
|
-
var
|
|
10
|
-
var xchainMayachain = require('@xchainjs/xchain-mayachain');
|
|
11
|
-
var xchainThorchain = require('@xchainjs/xchain-thorchain');
|
|
9
|
+
var xchainCosmosSdk = require('@xchainjs/xchain-cosmos-sdk');
|
|
12
10
|
var xchainUtil = require('@xchainjs/xchain-util');
|
|
13
11
|
var xchainClient = require('@xchainjs/xchain-client');
|
|
12
|
+
var xchainMayachain = require('@xchainjs/xchain-mayachain');
|
|
13
|
+
var xchainThorchain = require('@xchainjs/xchain-thorchain');
|
|
14
14
|
var xchainMayachainQuery = require('@xchainjs/xchain-mayachain-query');
|
|
15
15
|
var ethers = require('ethers');
|
|
16
16
|
|
|
@@ -39,6 +39,76 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
const KUJI_DECIMAL = 6;
|
|
43
|
+
const DEFAULT_FEE = xchainUtil.baseAmount(5000, KUJI_DECIMAL);
|
|
44
|
+
const KUJIChain = 'KUJI';
|
|
45
|
+
const AssetKUJI = { chain: KUJIChain, symbol: 'KUJI', ticker: 'KUJI', synth: false };
|
|
46
|
+
|
|
47
|
+
const getDefaultClientUrls = () => {
|
|
48
|
+
return {
|
|
49
|
+
[xchainClient.Network.Testnet]: 'https://kujira-testnet-rpc.polkachu.com/',
|
|
50
|
+
[xchainClient.Network.Stagenet]: 'https://rpc.cosmos.directory/kujira/',
|
|
51
|
+
[xchainClient.Network.Mainnet]: 'https://rpc.cosmos.directory/kujira/',
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const getDefaultRootDerivationPaths = () => ({
|
|
55
|
+
[xchainClient.Network.Mainnet]: `44'/118'/0'/0/`,
|
|
56
|
+
[xchainClient.Network.Testnet]: `44'/118'/0'/0/`,
|
|
57
|
+
[xchainClient.Network.Stagenet]: `44'/118'/0'/0/`,
|
|
58
|
+
});
|
|
59
|
+
const getDefaultExplorers = () => ({
|
|
60
|
+
[xchainClient.Network.Mainnet]: 'https://finder.kujira.network/kaiyo-1',
|
|
61
|
+
[xchainClient.Network.Testnet]: 'https://finder.kujira.network/harpoon-4',
|
|
62
|
+
[xchainClient.Network.Stagenet]: 'https://finder.kujira.network/kaiyo-1',
|
|
63
|
+
});
|
|
64
|
+
const defaultClientConfig = {
|
|
65
|
+
chain: AssetKUJI.chain,
|
|
66
|
+
network: xchainClient.Network.Mainnet,
|
|
67
|
+
clientUrls: getDefaultClientUrls(),
|
|
68
|
+
rootDerivationPaths: getDefaultRootDerivationPaths(),
|
|
69
|
+
prefix: 'kujira',
|
|
70
|
+
defaultDecimals: 6,
|
|
71
|
+
defaultFee: DEFAULT_FEE,
|
|
72
|
+
baseDenom: 'ukuji',
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
class Client extends xchainCosmosSdk.Client {
|
|
76
|
+
constructor(config = defaultClientConfig) {
|
|
77
|
+
super(Object.assign(Object.assign({}, defaultClientConfig), config));
|
|
78
|
+
}
|
|
79
|
+
getAssetInfo() {
|
|
80
|
+
const assetInfo = {
|
|
81
|
+
asset: AssetKUJI,
|
|
82
|
+
decimal: KUJI_DECIMAL,
|
|
83
|
+
};
|
|
84
|
+
return assetInfo;
|
|
85
|
+
}
|
|
86
|
+
getDenom(asset) {
|
|
87
|
+
if (xchainUtil.eqAsset(asset, AssetKUJI))
|
|
88
|
+
return this.baseDenom;
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
assetFromDenom(denom) {
|
|
92
|
+
if (denom === this.baseDenom)
|
|
93
|
+
return AssetKUJI;
|
|
94
|
+
return {
|
|
95
|
+
chain: AssetKUJI.chain,
|
|
96
|
+
symbol: denom,
|
|
97
|
+
ticker: '',
|
|
98
|
+
synth: false,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
getExplorerUrl() {
|
|
102
|
+
return getDefaultExplorers()[this.network];
|
|
103
|
+
}
|
|
104
|
+
getExplorerAddressUrl(address) {
|
|
105
|
+
return `${this.getExplorerUrl()}/address/${address}`;
|
|
106
|
+
}
|
|
107
|
+
getExplorerTxUrl(txID) {
|
|
108
|
+
return `${this.getExplorerUrl()}/tx/${txID}`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
42
112
|
class Wallet {
|
|
43
113
|
/**
|
|
44
114
|
* Constructor to create a Wallet
|
|
@@ -54,7 +124,7 @@ class Wallet {
|
|
|
54
124
|
BTC: new xchainBitcoin.Client(Object.assign(Object.assign(Object.assign({}, xchainBitcoin.defaultBTCParams), chainConfigs[xchainBitcoin.BTCChain]), settings)),
|
|
55
125
|
ETH: new xchainEthereum.Client(Object.assign(Object.assign(Object.assign({}, xchainEthereum.defaultEthParams), chainConfigs[xchainEthereum.ETHChain]), settings)),
|
|
56
126
|
DASH: new xchainDash.Client(Object.assign(Object.assign(Object.assign({}, xchainDash.defaultDashParams), chainConfigs[xchainDash.DASHChain]), settings)),
|
|
57
|
-
KUJI: new
|
|
127
|
+
KUJI: new Client(Object.assign(Object.assign(Object.assign({}, defaultClientConfig), chainConfigs[KUJIChain]), settings)),
|
|
58
128
|
THOR: new xchainThorchain.Client(Object.assign(Object.assign({}, chainConfigs[xchainThorchain.THORChain]), settings)),
|
|
59
129
|
MAYA: new xchainMayachain.Client(Object.assign(Object.assign({}, chainConfigs[xchainMayachain.MAYAChain]), settings)),
|
|
60
130
|
};
|
|
@@ -71,7 +141,27 @@ class Wallet {
|
|
|
71
141
|
});
|
|
72
142
|
}
|
|
73
143
|
/**
|
|
74
|
-
*
|
|
144
|
+
* Get wallet chain addresses.
|
|
145
|
+
* @param {Chain[]} chains Optional - Chains of which return the address of. If not provided, it will return
|
|
146
|
+
* the wallet chain addresses
|
|
147
|
+
* @returns the chains addresses
|
|
148
|
+
*/
|
|
149
|
+
getAddresses(chains) {
|
|
150
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
const _chains = chains || Object.keys(this.clients);
|
|
152
|
+
const tasks = _chains.map((chain) => {
|
|
153
|
+
return this.getAddress(chain);
|
|
154
|
+
});
|
|
155
|
+
const walletAddresses = {};
|
|
156
|
+
const addresses = yield Promise.all(tasks);
|
|
157
|
+
addresses.map((walletAddress, index) => {
|
|
158
|
+
walletAddresses[_chains[index]] = walletAddress;
|
|
159
|
+
});
|
|
160
|
+
return walletAddresses;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Check if an address is valid
|
|
75
165
|
* @param {Chain} chain in which the address has to be valid
|
|
76
166
|
* @param {string} address to validate
|
|
77
167
|
* @returns true if it is a valid address, otherwise, false
|
|
@@ -80,6 +170,81 @@ class Wallet {
|
|
|
80
170
|
const client = this.getChainClient(chain);
|
|
81
171
|
return client.validateAddress(address);
|
|
82
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Get chain balances.
|
|
175
|
+
* @param {Chain} chain - Chains of the assets
|
|
176
|
+
* @param {Assets[]} assets - Optional. Assets of which return the balance
|
|
177
|
+
* @returns {Balance[]} Balances by chain
|
|
178
|
+
*/
|
|
179
|
+
getBalance(chain, assets) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
const client = this.getChainClient(chain);
|
|
182
|
+
return client.getBalance(yield this.getAddress(chain), assets);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Get wallet balances. By default, it returns all the wallet balances unless assets are provided, in that case,
|
|
187
|
+
* only asset balances will be returned by chain
|
|
188
|
+
* @param {Assets[]} assets - Optional. Assets of which return the balance
|
|
189
|
+
* @returns {Record<Chain, Balance[]>} Balances by chain
|
|
190
|
+
*/
|
|
191
|
+
getBalances(assets) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
const chains = assets ? Array.from(new Set(assets.map((asset) => asset.chain))) : Object.keys(this.clients);
|
|
194
|
+
const tasks = chains.map((chain) => __awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
return yield this.getBalance(chain, assets === null || assets === void 0 ? void 0 : assets.filter((asset) => asset.chain === chain));
|
|
196
|
+
}));
|
|
197
|
+
const walletBalances = {};
|
|
198
|
+
const balances = yield Promise.all(tasks);
|
|
199
|
+
balances.map((chainBalance, index) => {
|
|
200
|
+
walletBalances[chains[index]] = chainBalance;
|
|
201
|
+
});
|
|
202
|
+
return walletBalances;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Get transaction data from hash
|
|
207
|
+
* @param {Chain} chain - Chain in which the transaction was done
|
|
208
|
+
* @param {string} hash - Hash of the transaction
|
|
209
|
+
* @returns
|
|
210
|
+
*/
|
|
211
|
+
getTransactionData(chain, hash) {
|
|
212
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
213
|
+
const client = this.getChainClient(chain);
|
|
214
|
+
return yield client.getTransactionData(hash);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Returns the transaction history of a chain
|
|
219
|
+
* @param {Chain} chain Chain of which return the transaction history
|
|
220
|
+
* @returns {TxsPage} the chain transaction history
|
|
221
|
+
*/
|
|
222
|
+
getTransactionsHistory(chain) {
|
|
223
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
const client = this.getChainClient(chain);
|
|
225
|
+
return client.getTransactions();
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Get wallet histories. By default, it returns all the wallet histories unless chains are provided, in that case,
|
|
230
|
+
* only chain histories will be returned by chain
|
|
231
|
+
* @param {Chain[]} chains - Optional. Chain of which return the transaction history
|
|
232
|
+
* @returns {TxsPage} the chain transaction history
|
|
233
|
+
*/
|
|
234
|
+
getTransactionsHistories(chains) {
|
|
235
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
236
|
+
const _chains = chains || Object.keys(this.clients);
|
|
237
|
+
const tasks = _chains.map((chain) => __awaiter(this, void 0, void 0, function* () {
|
|
238
|
+
return this.getTransactionsHistory(chain);
|
|
239
|
+
}));
|
|
240
|
+
const walletHistories = {};
|
|
241
|
+
const histories = yield Promise.all(tasks);
|
|
242
|
+
histories.map((history, index) => {
|
|
243
|
+
walletHistories[_chains[index]] = history;
|
|
244
|
+
});
|
|
245
|
+
return walletHistories;
|
|
246
|
+
});
|
|
247
|
+
}
|
|
83
248
|
/**
|
|
84
249
|
* Make a transaction
|
|
85
250
|
* @param {TxParams} txParams to make the transfer
|
package/lib/wallet.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BTCChain } from '@xchainjs/xchain-bitcoin';
|
|
2
|
-
import { Network, TxParams, XChainClient, XChainClientParams } from '@xchainjs/xchain-client';
|
|
2
|
+
import { Balance, Network, Tx, TxParams, TxsPage, XChainClient, XChainClientParams } from '@xchainjs/xchain-client';
|
|
3
3
|
import { CosmosSdkClientParams } from '@xchainjs/xchain-cosmos-sdk';
|
|
4
4
|
import { DASHChain } from '@xchainjs/xchain-dash';
|
|
5
5
|
import { ETHChain } from '@xchainjs/xchain-ethereum';
|
|
@@ -7,7 +7,7 @@ import { EVMClientParams, GasPrices } from '@xchainjs/xchain-evm';
|
|
|
7
7
|
import { KUJIChain } from '@xchainjs/xchain-kujira';
|
|
8
8
|
import { DepositParam, MAYAChain, MayachainClientParams } from '@xchainjs/xchain-mayachain';
|
|
9
9
|
import { THORChain, ThorchainClientParams } from '@xchainjs/xchain-thorchain';
|
|
10
|
-
import { Asset, BaseAmount, Chain } from '@xchainjs/xchain-util';
|
|
10
|
+
import { Address, Asset, BaseAmount, Chain } from '@xchainjs/xchain-util';
|
|
11
11
|
import { UtxoClientParams } from '@xchainjs/xchain-utxo';
|
|
12
12
|
import { ethers } from 'ethers';
|
|
13
13
|
export type NodeUrls = Record<Network, string>;
|
|
@@ -37,12 +37,53 @@ export declare class Wallet {
|
|
|
37
37
|
*/
|
|
38
38
|
getAddress(chain: Chain): Promise<string>;
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
40
|
+
* Get wallet chain addresses.
|
|
41
|
+
* @param {Chain[]} chains Optional - Chains of which return the address of. If not provided, it will return
|
|
42
|
+
* the wallet chain addresses
|
|
43
|
+
* @returns the chains addresses
|
|
44
|
+
*/
|
|
45
|
+
getAddresses(chains?: Chain[]): Promise<Record<Chain, Address>>;
|
|
46
|
+
/**
|
|
47
|
+
* Check if an address is valid
|
|
41
48
|
* @param {Chain} chain in which the address has to be valid
|
|
42
49
|
* @param {string} address to validate
|
|
43
50
|
* @returns true if it is a valid address, otherwise, false
|
|
44
51
|
*/
|
|
45
52
|
validateAddress(chain: Chain, address: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Get chain balances.
|
|
55
|
+
* @param {Chain} chain - Chains of the assets
|
|
56
|
+
* @param {Assets[]} assets - Optional. Assets of which return the balance
|
|
57
|
+
* @returns {Balance[]} Balances by chain
|
|
58
|
+
*/
|
|
59
|
+
getBalance(chain: Chain, assets?: Asset[]): Promise<Balance[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Get wallet balances. By default, it returns all the wallet balances unless assets are provided, in that case,
|
|
62
|
+
* only asset balances will be returned by chain
|
|
63
|
+
* @param {Assets[]} assets - Optional. Assets of which return the balance
|
|
64
|
+
* @returns {Record<Chain, Balance[]>} Balances by chain
|
|
65
|
+
*/
|
|
66
|
+
getBalances(assets?: Asset[]): Promise<Record<Chain, Balance[]>>;
|
|
67
|
+
/**
|
|
68
|
+
* Get transaction data from hash
|
|
69
|
+
* @param {Chain} chain - Chain in which the transaction was done
|
|
70
|
+
* @param {string} hash - Hash of the transaction
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
getTransactionData(chain: Chain, hash: string): Promise<Tx>;
|
|
74
|
+
/**
|
|
75
|
+
* Returns the transaction history of a chain
|
|
76
|
+
* @param {Chain} chain Chain of which return the transaction history
|
|
77
|
+
* @returns {TxsPage} the chain transaction history
|
|
78
|
+
*/
|
|
79
|
+
getTransactionsHistory(chain: Chain): Promise<TxsPage>;
|
|
80
|
+
/**
|
|
81
|
+
* Get wallet histories. By default, it returns all the wallet histories unless chains are provided, in that case,
|
|
82
|
+
* only chain histories will be returned by chain
|
|
83
|
+
* @param {Chain[]} chains - Optional. Chain of which return the transaction history
|
|
84
|
+
* @returns {TxsPage} the chain transaction history
|
|
85
|
+
*/
|
|
86
|
+
getTransactionsHistories(chains?: Chain[]): Promise<Record<Chain, TxsPage>>;
|
|
46
87
|
/**
|
|
47
88
|
* Make a transaction
|
|
48
89
|
* @param {TxParams} txParams to make the transfer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-mayachain-amm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "module that exposes estimating & swapping cryptocurrency assets on mayachain",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MAYAChain",
|
|
@@ -35,6 +35,10 @@
|
|
|
35
35
|
"bugs": {
|
|
36
36
|
"url": "https://github.com/xchainjs/xchainjs-lib/issues"
|
|
37
37
|
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@xchainjs/xchain-ethereum": "0.31.4",
|
|
40
|
+
"@xchainjs/xchain-kujira": "0.1.6"
|
|
41
|
+
},
|
|
38
42
|
"devDependencies": {
|
|
39
43
|
"@cosmos-client/core": "0.46.1",
|
|
40
44
|
"@psf/bitcoincashjs-lib": "^4.0.3",
|
|
@@ -43,11 +47,9 @@
|
|
|
43
47
|
"@xchainjs/xchain-cosmos-sdk": "^0.1.5",
|
|
44
48
|
"@xchainjs/xchain-crypto": "^0.3.0",
|
|
45
49
|
"@xchainjs/xchain-dash": "^0.2.8",
|
|
46
|
-
"@xchainjs/xchain-ethereum": "^0.31.3",
|
|
47
50
|
"@xchainjs/xchain-mayanode": "^0.1.2",
|
|
48
51
|
"@xchainjs/xchain-mayachain-query": "^0.1.3",
|
|
49
52
|
"@xchainjs/xchain-evm": "^0.4.3",
|
|
50
|
-
"@xchainjs/xchain-kujira": "^0.1.5",
|
|
51
53
|
"@xchainjs/xchain-mayachain": "^0.2.13",
|
|
52
54
|
"@xchainjs/xchain-mayamidgard": "^0.1.0",
|
|
53
55
|
"@xchainjs/xchain-thorchain": "^0.28.16",
|
|
@@ -72,11 +74,9 @@
|
|
|
72
74
|
"@xchainjs/xchain-cosmos-sdk": "^0.1.5",
|
|
73
75
|
"@xchainjs/xchain-crypto": "^0.3.0",
|
|
74
76
|
"@xchainjs/xchain-dash": "^0.2.8",
|
|
75
|
-
"@xchainjs/xchain-ethereum": "^0.31.3",
|
|
76
77
|
"@xchainjs/xchain-mayanode": "^0.1.2",
|
|
77
78
|
"@xchainjs/xchain-mayachain-query": "^0.1.3",
|
|
78
79
|
"@xchainjs/xchain-evm": "^0.4.3",
|
|
79
|
-
"@xchainjs/xchain-kujira": "^0.1.5",
|
|
80
80
|
"@xchainjs/xchain-mayachain": "^0.2.13",
|
|
81
81
|
"@xchainjs/xchain-mayamidgard": "^0.1.0",
|
|
82
82
|
"@xchainjs/xchain-thorchain": "^0.28.16",
|