@xchainjs/xchain-wallet 0.1.3 → 0.1.5
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.d.ts +6 -0
- package/lib/index.esm.js +60 -55
- package/lib/index.js +60 -55
- package/lib/wallet.d.ts +57 -54
- package/package.json +4 -4
package/lib/index.d.ts
CHANGED
package/lib/index.esm.js
CHANGED
|
@@ -11995,44 +11995,49 @@ const isApproved = ({ provider, contractAddress, spenderAddress, fromAddress, am
|
|
|
11995
11995
|
return txAmount.lte(allowance);
|
|
11996
11996
|
});
|
|
11997
11997
|
|
|
11998
|
+
// Class definition for a Wallet
|
|
11998
11999
|
class Wallet {
|
|
11999
12000
|
/**
|
|
12000
12001
|
* Constructor to create a wallet with the desired clients
|
|
12001
12002
|
*
|
|
12002
|
-
* @param {Record<string>} clients Clients by chain the wallet
|
|
12003
|
-
* @returns Wallet
|
|
12003
|
+
* @param {Record<string>} clients Clients mapped by chain with which the wallet works
|
|
12004
|
+
* @returns Wallet instance
|
|
12004
12005
|
*/
|
|
12005
12006
|
constructor(clients) {
|
|
12006
12007
|
this.clients = clients;
|
|
12007
12008
|
this.network = Network.Mainnet;
|
|
12009
|
+
// Check if clients array is not empty
|
|
12008
12010
|
if (Object.values(clients).length) {
|
|
12011
|
+
// Get the network of the first client
|
|
12009
12012
|
const network = Object.values(clients)[0].getNetwork();
|
|
12013
|
+
// Ensure all clients are on the same network
|
|
12010
12014
|
if (!Object.values(clients).every((client) => client.getNetwork() === network)) {
|
|
12011
12015
|
throw Error('Clients not working on the same network');
|
|
12012
12016
|
}
|
|
12013
|
-
this.network = network;
|
|
12017
|
+
this.network = network; // Set the network for the wallet
|
|
12014
12018
|
}
|
|
12015
12019
|
}
|
|
12016
12020
|
/**
|
|
12017
|
-
* Get the network clients are working in
|
|
12018
|
-
* @returns {Network} network
|
|
12021
|
+
* Get the network that the clients are working in
|
|
12022
|
+
* @returns {Network} The network
|
|
12019
12023
|
*/
|
|
12020
12024
|
getNetwork() {
|
|
12021
12025
|
return this.network;
|
|
12022
12026
|
}
|
|
12023
12027
|
/**
|
|
12024
|
-
* Set the network clients are working in
|
|
12025
|
-
* @param {Network} network Network
|
|
12028
|
+
* Set the network that the clients are working in
|
|
12029
|
+
* @param {Network} network The Network to set
|
|
12026
12030
|
*/
|
|
12027
12031
|
setNetwork(network) {
|
|
12032
|
+
// Set network for each client
|
|
12028
12033
|
Object.values(this.clients).forEach((client) => client.setNetwork(network));
|
|
12029
12034
|
this.network = network;
|
|
12030
12035
|
}
|
|
12031
12036
|
/**
|
|
12032
12037
|
* Add a new client to the wallet
|
|
12033
|
-
* @param chain to
|
|
12034
|
-
* @returns {boolean}
|
|
12035
|
-
* @throws {Error} If
|
|
12038
|
+
* @param chain - Chain to add the client for
|
|
12039
|
+
* @returns {boolean} True if client is successfully added, otherwise false
|
|
12040
|
+
* @throws {Error} If trying to add a client on a different network compared to others
|
|
12036
12041
|
*/
|
|
12037
12042
|
addClient(chain, client) {
|
|
12038
12043
|
if (chain in this.clients)
|
|
@@ -12049,9 +12054,9 @@ class Wallet {
|
|
|
12049
12054
|
return true;
|
|
12050
12055
|
}
|
|
12051
12056
|
/**
|
|
12052
|
-
* Purge and remove client from wallet
|
|
12053
|
-
* @param chain to remove the client
|
|
12054
|
-
* @returns {true}
|
|
12057
|
+
* Purge and remove client from the wallet
|
|
12058
|
+
* @param chain Chain to remove the client for
|
|
12059
|
+
* @returns {true} True if the client is successfully purged and removed, otherwise false
|
|
12055
12060
|
*/
|
|
12056
12061
|
purgeClient(chain) {
|
|
12057
12062
|
try {
|
|
@@ -12066,7 +12071,7 @@ class Wallet {
|
|
|
12066
12071
|
}
|
|
12067
12072
|
/**
|
|
12068
12073
|
* Purge and remove all clients from wallet
|
|
12069
|
-
* @returns {boolean}
|
|
12074
|
+
* @returns {boolean} True if the wallet is successfully purged and removed, otherwise false
|
|
12070
12075
|
*/
|
|
12071
12076
|
purgeWallet() {
|
|
12072
12077
|
try {
|
|
@@ -12082,8 +12087,8 @@ class Wallet {
|
|
|
12082
12087
|
}
|
|
12083
12088
|
/**
|
|
12084
12089
|
* Get chain address
|
|
12085
|
-
* @param {Chain} chain
|
|
12086
|
-
* @returns {string}
|
|
12090
|
+
* @param {Chain} chain The chain
|
|
12091
|
+
* @returns {string} The chain address
|
|
12087
12092
|
*/
|
|
12088
12093
|
getAddress(chain) {
|
|
12089
12094
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12092,10 +12097,9 @@ class Wallet {
|
|
|
12092
12097
|
});
|
|
12093
12098
|
}
|
|
12094
12099
|
/**
|
|
12095
|
-
* Get wallet chain addresses.
|
|
12096
|
-
* @param {Chain[]} chains Optional
|
|
12097
|
-
*
|
|
12098
|
-
* @returns the chains addresses
|
|
12100
|
+
* Get the wallet chain addresses.
|
|
12101
|
+
* @param {Chain[]} chains Optional chains to get addresses for, if not provided, returns all wallet addresses
|
|
12102
|
+
* @returns Addresses mapped by chain
|
|
12099
12103
|
*/
|
|
12100
12104
|
getAddresses(chains) {
|
|
12101
12105
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12113,8 +12117,8 @@ class Wallet {
|
|
|
12113
12117
|
}
|
|
12114
12118
|
/**
|
|
12115
12119
|
* Check if address is valid
|
|
12116
|
-
* @param {Chain} chain in which the address has to be valid
|
|
12117
|
-
* @param {string} address to validate
|
|
12120
|
+
* @param {Chain} chain The chain in which the address has to be valid
|
|
12121
|
+
* @param {string} address The address to validate
|
|
12118
12122
|
* @returns {boolean} true if it is a valid address, otherwise, false
|
|
12119
12123
|
*/
|
|
12120
12124
|
validateAddress(chain, address) {
|
|
@@ -12123,7 +12127,7 @@ class Wallet {
|
|
|
12123
12127
|
}
|
|
12124
12128
|
/**
|
|
12125
12129
|
* Get chain balances
|
|
12126
|
-
* @param {Chain} chain to retrieve the balance of
|
|
12130
|
+
* @param {Chain} chain The chain to retrieve the balance of
|
|
12127
12131
|
* @returns {Balance[]} the chain balances
|
|
12128
12132
|
*/
|
|
12129
12133
|
getBalance(chain, assets) {
|
|
@@ -12133,7 +12137,7 @@ class Wallet {
|
|
|
12133
12137
|
});
|
|
12134
12138
|
}
|
|
12135
12139
|
/**
|
|
12136
|
-
*
|
|
12140
|
+
* By default, it returns all the wallet balances unless assets are provided, in that case,
|
|
12137
12141
|
* only asset balances will be returned by chain
|
|
12138
12142
|
* @param {Assets[]} assets - Optional. Assets of which return the balance
|
|
12139
12143
|
* @returns {Record<Chain, Balance[]>} Balances by chain
|
|
@@ -12176,7 +12180,8 @@ class Wallet {
|
|
|
12176
12180
|
});
|
|
12177
12181
|
}
|
|
12178
12182
|
/**
|
|
12179
|
-
* Get wallet histories.
|
|
12183
|
+
* Get wallet histories.
|
|
12184
|
+
* By default, it returns all the wallet histories unless chains are provided, in that case,
|
|
12180
12185
|
* only chain histories will be returned by chain
|
|
12181
12186
|
* @param {Chain[]} chains - Optional. Chain of which return the transaction history
|
|
12182
12187
|
* @returns {TxsPage} the chain transaction history
|
|
@@ -12197,8 +12202,8 @@ class Wallet {
|
|
|
12197
12202
|
}
|
|
12198
12203
|
/**
|
|
12199
12204
|
* Get explorer url
|
|
12200
|
-
* @param {Chain} chain to retrieve the explorer of
|
|
12201
|
-
* @returns {string} the transaction
|
|
12205
|
+
* @param {Chain} chain The chain to retrieve the explorer of
|
|
12206
|
+
* @returns {string} the transaction URL
|
|
12202
12207
|
*/
|
|
12203
12208
|
getExplorerUrl(chain) {
|
|
12204
12209
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12207,10 +12212,10 @@ class Wallet {
|
|
|
12207
12212
|
});
|
|
12208
12213
|
}
|
|
12209
12214
|
/**
|
|
12210
|
-
* Get address
|
|
12211
|
-
* @param {Chain} chain of the address
|
|
12212
|
-
* @param {string} address to retrieve the
|
|
12213
|
-
* @returns {string}
|
|
12215
|
+
* Get address URL
|
|
12216
|
+
* @param {Chain} chain Chain of the address
|
|
12217
|
+
* @param {string} address The address to retrieve the URL of
|
|
12218
|
+
* @returns {string} The address URL
|
|
12214
12219
|
*/
|
|
12215
12220
|
getExplorerAddressUrl(chain, address) {
|
|
12216
12221
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12219,10 +12224,10 @@ class Wallet {
|
|
|
12219
12224
|
});
|
|
12220
12225
|
}
|
|
12221
12226
|
/**
|
|
12222
|
-
* Get transaction
|
|
12223
|
-
* @param {Chain} chain of the transaction
|
|
12224
|
-
* @param {string} hash of the transaction
|
|
12225
|
-
* @returns the transaction
|
|
12227
|
+
* Get transaction URL
|
|
12228
|
+
* @param {Chain} chain Chain of the transaction
|
|
12229
|
+
* @param {string} hash Hash of the transaction
|
|
12230
|
+
* @returns the transaction URL
|
|
12226
12231
|
*/
|
|
12227
12232
|
getExplorerTxUrl(chain, hash) {
|
|
12228
12233
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12232,9 +12237,9 @@ class Wallet {
|
|
|
12232
12237
|
}
|
|
12233
12238
|
/**
|
|
12234
12239
|
* Get feeRates. Only available for EVM clients
|
|
12235
|
-
* @param {Chain} chain of which return the feeRates
|
|
12236
|
-
* @returns {GasPrices}
|
|
12237
|
-
* @throws {Error}
|
|
12240
|
+
* @param {Chain} chain Chain of which return the feeRates
|
|
12241
|
+
* @returns {GasPrices} Chain of which return the feeRates
|
|
12242
|
+
* @throws {Error} If gas fee rates cannot be returned from the chain
|
|
12238
12243
|
*/
|
|
12239
12244
|
getGasFeeRates(chain) {
|
|
12240
12245
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12246,8 +12251,8 @@ class Wallet {
|
|
|
12246
12251
|
}
|
|
12247
12252
|
/**
|
|
12248
12253
|
* Make a transaction
|
|
12249
|
-
* @param {TxParams} txParams to make the transfer
|
|
12250
|
-
* @returns
|
|
12254
|
+
* @param {TxParams} txParams txParams - The parameters to make the transfer
|
|
12255
|
+
* @returns The transaction hash
|
|
12251
12256
|
*/
|
|
12252
12257
|
transfer({ asset, amount, recipient, memo, walletIndex }) {
|
|
12253
12258
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12265,7 +12270,7 @@ class Wallet {
|
|
|
12265
12270
|
* Make a deposit
|
|
12266
12271
|
* @param {DepositParam} depositParams
|
|
12267
12272
|
* @returns {string} the hash of the deposit
|
|
12268
|
-
* @throws {Error} if
|
|
12273
|
+
* @throws {Error} if cannot make deposit with the asset
|
|
12269
12274
|
*/
|
|
12270
12275
|
deposit({ asset, amount, memo, walletIndex, sequence, gasLimit, }) {
|
|
12271
12276
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12277,12 +12282,12 @@ class Wallet {
|
|
|
12277
12282
|
}
|
|
12278
12283
|
/**
|
|
12279
12284
|
* Check if an spenderAddress is allowed to spend in name of another address certain asset amount
|
|
12280
|
-
* @param {Asset} asset to check
|
|
12281
|
-
* @param {BaseAmount} amount to check
|
|
12282
|
-
* @param {string} fromAddress owner of the amount asset
|
|
12283
|
-
* @param {string} spenderAddress spender to check if it is allowed to spend
|
|
12285
|
+
* @param {Asset} asset The asset to check
|
|
12286
|
+
* @param {BaseAmount} amount The amount to check
|
|
12287
|
+
* @param {string} fromAddress The owner of the amount asset from
|
|
12288
|
+
* @param {string} spenderAddress The spender to check if it is allowed to spend
|
|
12284
12289
|
* @returns true if the spenderAddress is allowed to spend the amount, otherwise, false
|
|
12285
|
-
* @throws {Error}
|
|
12290
|
+
* @throws {Error} If asset is a non ERC20 asset
|
|
12286
12291
|
*/
|
|
12287
12292
|
approve(asset, amount, spenderAddress) {
|
|
12288
12293
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12297,12 +12302,12 @@ class Wallet {
|
|
|
12297
12302
|
}
|
|
12298
12303
|
/**
|
|
12299
12304
|
* Check if an spenderAddress is allowed to spend in name of another address certain asset amount
|
|
12300
|
-
* @param {Asset} asset to check
|
|
12301
|
-
* @param {BaseAmount} amount to check
|
|
12302
|
-
* @param {string} fromAddress
|
|
12303
|
-
* @param {string} spenderAddress
|
|
12305
|
+
* @param {Asset} asset The asset to check
|
|
12306
|
+
* @param {BaseAmount} amount The amount to check
|
|
12307
|
+
* @param {string} fromAddress oThe wner of the amount asset from
|
|
12308
|
+
* @param {string} spenderAddress Spender to check if it is allowed to spend
|
|
12304
12309
|
* @returns true if the spenderAddress is allowed to spend the amount, otherwise, false
|
|
12305
|
-
* @throws {Error}
|
|
12310
|
+
* @throws {Error} If asset is a non ERC20 asset
|
|
12306
12311
|
*/
|
|
12307
12312
|
isApproved(asset, amount, fromAddress, spenderAddress) {
|
|
12308
12313
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12323,7 +12328,7 @@ class Wallet {
|
|
|
12323
12328
|
}
|
|
12324
12329
|
/**
|
|
12325
12330
|
* Broadcast transaction
|
|
12326
|
-
* @param {Chain} chain in which broadcast the signed raw transaction
|
|
12331
|
+
* @param {Chain} chain The chain in which broadcast the signed raw transaction
|
|
12327
12332
|
* @param {string} txHex signed raw transaction
|
|
12328
12333
|
* @returns {TxHash} the broadcasted transaction hash
|
|
12329
12334
|
*/
|
|
@@ -12347,9 +12352,9 @@ class Wallet {
|
|
|
12347
12352
|
}
|
|
12348
12353
|
/**
|
|
12349
12354
|
* Get chain client
|
|
12350
|
-
* @param {Chain} chain of which return the client
|
|
12351
|
-
* @returns {XChainClient}
|
|
12352
|
-
* @throws {Error}
|
|
12355
|
+
* @param {Chain} chain The chain of which to return the client
|
|
12356
|
+
* @returns {XChainClient} The chain client
|
|
12357
|
+
* @throws {Error} If the client does not exist
|
|
12353
12358
|
*/
|
|
12354
12359
|
getClient(chain) {
|
|
12355
12360
|
const client = this.clients[chain];
|
package/lib/index.js
CHANGED
|
@@ -11999,44 +11999,49 @@ const isApproved = ({ provider, contractAddress, spenderAddress, fromAddress, am
|
|
|
11999
11999
|
return txAmount.lte(allowance);
|
|
12000
12000
|
});
|
|
12001
12001
|
|
|
12002
|
+
// Class definition for a Wallet
|
|
12002
12003
|
class Wallet {
|
|
12003
12004
|
/**
|
|
12004
12005
|
* Constructor to create a wallet with the desired clients
|
|
12005
12006
|
*
|
|
12006
|
-
* @param {Record<string>} clients Clients by chain the wallet
|
|
12007
|
-
* @returns Wallet
|
|
12007
|
+
* @param {Record<string>} clients Clients mapped by chain with which the wallet works
|
|
12008
|
+
* @returns Wallet instance
|
|
12008
12009
|
*/
|
|
12009
12010
|
constructor(clients) {
|
|
12010
12011
|
this.clients = clients;
|
|
12011
12012
|
this.network = xchainClient.Network.Mainnet;
|
|
12013
|
+
// Check if clients array is not empty
|
|
12012
12014
|
if (Object.values(clients).length) {
|
|
12015
|
+
// Get the network of the first client
|
|
12013
12016
|
const network = Object.values(clients)[0].getNetwork();
|
|
12017
|
+
// Ensure all clients are on the same network
|
|
12014
12018
|
if (!Object.values(clients).every((client) => client.getNetwork() === network)) {
|
|
12015
12019
|
throw Error('Clients not working on the same network');
|
|
12016
12020
|
}
|
|
12017
|
-
this.network = network;
|
|
12021
|
+
this.network = network; // Set the network for the wallet
|
|
12018
12022
|
}
|
|
12019
12023
|
}
|
|
12020
12024
|
/**
|
|
12021
|
-
* Get the network clients are working in
|
|
12022
|
-
* @returns {Network} network
|
|
12025
|
+
* Get the network that the clients are working in
|
|
12026
|
+
* @returns {Network} The network
|
|
12023
12027
|
*/
|
|
12024
12028
|
getNetwork() {
|
|
12025
12029
|
return this.network;
|
|
12026
12030
|
}
|
|
12027
12031
|
/**
|
|
12028
|
-
* Set the network clients are working in
|
|
12029
|
-
* @param {Network} network Network
|
|
12032
|
+
* Set the network that the clients are working in
|
|
12033
|
+
* @param {Network} network The Network to set
|
|
12030
12034
|
*/
|
|
12031
12035
|
setNetwork(network) {
|
|
12036
|
+
// Set network for each client
|
|
12032
12037
|
Object.values(this.clients).forEach((client) => client.setNetwork(network));
|
|
12033
12038
|
this.network = network;
|
|
12034
12039
|
}
|
|
12035
12040
|
/**
|
|
12036
12041
|
* Add a new client to the wallet
|
|
12037
|
-
* @param chain to
|
|
12038
|
-
* @returns {boolean}
|
|
12039
|
-
* @throws {Error} If
|
|
12042
|
+
* @param chain - Chain to add the client for
|
|
12043
|
+
* @returns {boolean} True if client is successfully added, otherwise false
|
|
12044
|
+
* @throws {Error} If trying to add a client on a different network compared to others
|
|
12040
12045
|
*/
|
|
12041
12046
|
addClient(chain, client) {
|
|
12042
12047
|
if (chain in this.clients)
|
|
@@ -12053,9 +12058,9 @@ class Wallet {
|
|
|
12053
12058
|
return true;
|
|
12054
12059
|
}
|
|
12055
12060
|
/**
|
|
12056
|
-
* Purge and remove client from wallet
|
|
12057
|
-
* @param chain to remove the client
|
|
12058
|
-
* @returns {true}
|
|
12061
|
+
* Purge and remove client from the wallet
|
|
12062
|
+
* @param chain Chain to remove the client for
|
|
12063
|
+
* @returns {true} True if the client is successfully purged and removed, otherwise false
|
|
12059
12064
|
*/
|
|
12060
12065
|
purgeClient(chain) {
|
|
12061
12066
|
try {
|
|
@@ -12070,7 +12075,7 @@ class Wallet {
|
|
|
12070
12075
|
}
|
|
12071
12076
|
/**
|
|
12072
12077
|
* Purge and remove all clients from wallet
|
|
12073
|
-
* @returns {boolean}
|
|
12078
|
+
* @returns {boolean} True if the wallet is successfully purged and removed, otherwise false
|
|
12074
12079
|
*/
|
|
12075
12080
|
purgeWallet() {
|
|
12076
12081
|
try {
|
|
@@ -12086,8 +12091,8 @@ class Wallet {
|
|
|
12086
12091
|
}
|
|
12087
12092
|
/**
|
|
12088
12093
|
* Get chain address
|
|
12089
|
-
* @param {Chain} chain
|
|
12090
|
-
* @returns {string}
|
|
12094
|
+
* @param {Chain} chain The chain
|
|
12095
|
+
* @returns {string} The chain address
|
|
12091
12096
|
*/
|
|
12092
12097
|
getAddress(chain) {
|
|
12093
12098
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12096,10 +12101,9 @@ class Wallet {
|
|
|
12096
12101
|
});
|
|
12097
12102
|
}
|
|
12098
12103
|
/**
|
|
12099
|
-
* Get wallet chain addresses.
|
|
12100
|
-
* @param {Chain[]} chains Optional
|
|
12101
|
-
*
|
|
12102
|
-
* @returns the chains addresses
|
|
12104
|
+
* Get the wallet chain addresses.
|
|
12105
|
+
* @param {Chain[]} chains Optional chains to get addresses for, if not provided, returns all wallet addresses
|
|
12106
|
+
* @returns Addresses mapped by chain
|
|
12103
12107
|
*/
|
|
12104
12108
|
getAddresses(chains) {
|
|
12105
12109
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12117,8 +12121,8 @@ class Wallet {
|
|
|
12117
12121
|
}
|
|
12118
12122
|
/**
|
|
12119
12123
|
* Check if address is valid
|
|
12120
|
-
* @param {Chain} chain in which the address has to be valid
|
|
12121
|
-
* @param {string} address to validate
|
|
12124
|
+
* @param {Chain} chain The chain in which the address has to be valid
|
|
12125
|
+
* @param {string} address The address to validate
|
|
12122
12126
|
* @returns {boolean} true if it is a valid address, otherwise, false
|
|
12123
12127
|
*/
|
|
12124
12128
|
validateAddress(chain, address) {
|
|
@@ -12127,7 +12131,7 @@ class Wallet {
|
|
|
12127
12131
|
}
|
|
12128
12132
|
/**
|
|
12129
12133
|
* Get chain balances
|
|
12130
|
-
* @param {Chain} chain to retrieve the balance of
|
|
12134
|
+
* @param {Chain} chain The chain to retrieve the balance of
|
|
12131
12135
|
* @returns {Balance[]} the chain balances
|
|
12132
12136
|
*/
|
|
12133
12137
|
getBalance(chain, assets) {
|
|
@@ -12137,7 +12141,7 @@ class Wallet {
|
|
|
12137
12141
|
});
|
|
12138
12142
|
}
|
|
12139
12143
|
/**
|
|
12140
|
-
*
|
|
12144
|
+
* By default, it returns all the wallet balances unless assets are provided, in that case,
|
|
12141
12145
|
* only asset balances will be returned by chain
|
|
12142
12146
|
* @param {Assets[]} assets - Optional. Assets of which return the balance
|
|
12143
12147
|
* @returns {Record<Chain, Balance[]>} Balances by chain
|
|
@@ -12180,7 +12184,8 @@ class Wallet {
|
|
|
12180
12184
|
});
|
|
12181
12185
|
}
|
|
12182
12186
|
/**
|
|
12183
|
-
* Get wallet histories.
|
|
12187
|
+
* Get wallet histories.
|
|
12188
|
+
* By default, it returns all the wallet histories unless chains are provided, in that case,
|
|
12184
12189
|
* only chain histories will be returned by chain
|
|
12185
12190
|
* @param {Chain[]} chains - Optional. Chain of which return the transaction history
|
|
12186
12191
|
* @returns {TxsPage} the chain transaction history
|
|
@@ -12201,8 +12206,8 @@ class Wallet {
|
|
|
12201
12206
|
}
|
|
12202
12207
|
/**
|
|
12203
12208
|
* Get explorer url
|
|
12204
|
-
* @param {Chain} chain to retrieve the explorer of
|
|
12205
|
-
* @returns {string} the transaction
|
|
12209
|
+
* @param {Chain} chain The chain to retrieve the explorer of
|
|
12210
|
+
* @returns {string} the transaction URL
|
|
12206
12211
|
*/
|
|
12207
12212
|
getExplorerUrl(chain) {
|
|
12208
12213
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12211,10 +12216,10 @@ class Wallet {
|
|
|
12211
12216
|
});
|
|
12212
12217
|
}
|
|
12213
12218
|
/**
|
|
12214
|
-
* Get address
|
|
12215
|
-
* @param {Chain} chain of the address
|
|
12216
|
-
* @param {string} address to retrieve the
|
|
12217
|
-
* @returns {string}
|
|
12219
|
+
* Get address URL
|
|
12220
|
+
* @param {Chain} chain Chain of the address
|
|
12221
|
+
* @param {string} address The address to retrieve the URL of
|
|
12222
|
+
* @returns {string} The address URL
|
|
12218
12223
|
*/
|
|
12219
12224
|
getExplorerAddressUrl(chain, address) {
|
|
12220
12225
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12223,10 +12228,10 @@ class Wallet {
|
|
|
12223
12228
|
});
|
|
12224
12229
|
}
|
|
12225
12230
|
/**
|
|
12226
|
-
* Get transaction
|
|
12227
|
-
* @param {Chain} chain of the transaction
|
|
12228
|
-
* @param {string} hash of the transaction
|
|
12229
|
-
* @returns the transaction
|
|
12231
|
+
* Get transaction URL
|
|
12232
|
+
* @param {Chain} chain Chain of the transaction
|
|
12233
|
+
* @param {string} hash Hash of the transaction
|
|
12234
|
+
* @returns the transaction URL
|
|
12230
12235
|
*/
|
|
12231
12236
|
getExplorerTxUrl(chain, hash) {
|
|
12232
12237
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12236,9 +12241,9 @@ class Wallet {
|
|
|
12236
12241
|
}
|
|
12237
12242
|
/**
|
|
12238
12243
|
* Get feeRates. Only available for EVM clients
|
|
12239
|
-
* @param {Chain} chain of which return the feeRates
|
|
12240
|
-
* @returns {GasPrices}
|
|
12241
|
-
* @throws {Error}
|
|
12244
|
+
* @param {Chain} chain Chain of which return the feeRates
|
|
12245
|
+
* @returns {GasPrices} Chain of which return the feeRates
|
|
12246
|
+
* @throws {Error} If gas fee rates cannot be returned from the chain
|
|
12242
12247
|
*/
|
|
12243
12248
|
getGasFeeRates(chain) {
|
|
12244
12249
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12250,8 +12255,8 @@ class Wallet {
|
|
|
12250
12255
|
}
|
|
12251
12256
|
/**
|
|
12252
12257
|
* Make a transaction
|
|
12253
|
-
* @param {TxParams} txParams to make the transfer
|
|
12254
|
-
* @returns
|
|
12258
|
+
* @param {TxParams} txParams txParams - The parameters to make the transfer
|
|
12259
|
+
* @returns The transaction hash
|
|
12255
12260
|
*/
|
|
12256
12261
|
transfer({ asset, amount, recipient, memo, walletIndex }) {
|
|
12257
12262
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12269,7 +12274,7 @@ class Wallet {
|
|
|
12269
12274
|
* Make a deposit
|
|
12270
12275
|
* @param {DepositParam} depositParams
|
|
12271
12276
|
* @returns {string} the hash of the deposit
|
|
12272
|
-
* @throws {Error} if
|
|
12277
|
+
* @throws {Error} if cannot make deposit with the asset
|
|
12273
12278
|
*/
|
|
12274
12279
|
deposit({ asset, amount, memo, walletIndex, sequence, gasLimit, }) {
|
|
12275
12280
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12281,12 +12286,12 @@ class Wallet {
|
|
|
12281
12286
|
}
|
|
12282
12287
|
/**
|
|
12283
12288
|
* Check if an spenderAddress is allowed to spend in name of another address certain asset amount
|
|
12284
|
-
* @param {Asset} asset to check
|
|
12285
|
-
* @param {BaseAmount} amount to check
|
|
12286
|
-
* @param {string} fromAddress owner of the amount asset
|
|
12287
|
-
* @param {string} spenderAddress spender to check if it is allowed to spend
|
|
12289
|
+
* @param {Asset} asset The asset to check
|
|
12290
|
+
* @param {BaseAmount} amount The amount to check
|
|
12291
|
+
* @param {string} fromAddress The owner of the amount asset from
|
|
12292
|
+
* @param {string} spenderAddress The spender to check if it is allowed to spend
|
|
12288
12293
|
* @returns true if the spenderAddress is allowed to spend the amount, otherwise, false
|
|
12289
|
-
* @throws {Error}
|
|
12294
|
+
* @throws {Error} If asset is a non ERC20 asset
|
|
12290
12295
|
*/
|
|
12291
12296
|
approve(asset, amount, spenderAddress) {
|
|
12292
12297
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12301,12 +12306,12 @@ class Wallet {
|
|
|
12301
12306
|
}
|
|
12302
12307
|
/**
|
|
12303
12308
|
* Check if an spenderAddress is allowed to spend in name of another address certain asset amount
|
|
12304
|
-
* @param {Asset} asset to check
|
|
12305
|
-
* @param {BaseAmount} amount to check
|
|
12306
|
-
* @param {string} fromAddress
|
|
12307
|
-
* @param {string} spenderAddress
|
|
12309
|
+
* @param {Asset} asset The asset to check
|
|
12310
|
+
* @param {BaseAmount} amount The amount to check
|
|
12311
|
+
* @param {string} fromAddress oThe wner of the amount asset from
|
|
12312
|
+
* @param {string} spenderAddress Spender to check if it is allowed to spend
|
|
12308
12313
|
* @returns true if the spenderAddress is allowed to spend the amount, otherwise, false
|
|
12309
|
-
* @throws {Error}
|
|
12314
|
+
* @throws {Error} If asset is a non ERC20 asset
|
|
12310
12315
|
*/
|
|
12311
12316
|
isApproved(asset, amount, fromAddress, spenderAddress) {
|
|
12312
12317
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
@@ -12327,7 +12332,7 @@ class Wallet {
|
|
|
12327
12332
|
}
|
|
12328
12333
|
/**
|
|
12329
12334
|
* Broadcast transaction
|
|
12330
|
-
* @param {Chain} chain in which broadcast the signed raw transaction
|
|
12335
|
+
* @param {Chain} chain The chain in which broadcast the signed raw transaction
|
|
12331
12336
|
* @param {string} txHex signed raw transaction
|
|
12332
12337
|
* @returns {TxHash} the broadcasted transaction hash
|
|
12333
12338
|
*/
|
|
@@ -12351,9 +12356,9 @@ class Wallet {
|
|
|
12351
12356
|
}
|
|
12352
12357
|
/**
|
|
12353
12358
|
* Get chain client
|
|
12354
|
-
* @param {Chain} chain of which return the client
|
|
12355
|
-
* @returns {XChainClient}
|
|
12356
|
-
* @throws {Error}
|
|
12359
|
+
* @param {Chain} chain The chain of which to return the client
|
|
12360
|
+
* @returns {XChainClient} The chain client
|
|
12361
|
+
* @throws {Error} If the client does not exist
|
|
12357
12362
|
*/
|
|
12358
12363
|
getClient(chain) {
|
|
12359
12364
|
const client = this.clients[chain];
|
package/lib/wallet.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import necessary modules and libraries
|
|
3
|
+
*/
|
|
1
4
|
import { Balance, Network, Tx, TxHash, TxParams, TxsPage, XChainClient } from '@xchainjs/xchain-client';
|
|
2
5
|
import { GasPrices } from '@xchainjs/xchain-evm';
|
|
3
6
|
import { DepositParam } from '@xchainjs/xchain-mayachain';
|
|
@@ -10,66 +13,65 @@ export declare class Wallet {
|
|
|
10
13
|
/**
|
|
11
14
|
* Constructor to create a wallet with the desired clients
|
|
12
15
|
*
|
|
13
|
-
* @param {Record<string>} clients Clients by chain the wallet
|
|
14
|
-
* @returns Wallet
|
|
16
|
+
* @param {Record<string>} clients Clients mapped by chain with which the wallet works
|
|
17
|
+
* @returns Wallet instance
|
|
15
18
|
*/
|
|
16
19
|
constructor(clients: Record<Chain, XChainClient>);
|
|
17
20
|
/**
|
|
18
|
-
* Get the network clients are working in
|
|
19
|
-
* @returns {Network} network
|
|
21
|
+
* Get the network that the clients are working in
|
|
22
|
+
* @returns {Network} The network
|
|
20
23
|
*/
|
|
21
24
|
getNetwork(): Network;
|
|
22
25
|
/**
|
|
23
|
-
* Set the network clients are working in
|
|
24
|
-
* @param {Network} network Network
|
|
26
|
+
* Set the network that the clients are working in
|
|
27
|
+
* @param {Network} network The Network to set
|
|
25
28
|
*/
|
|
26
29
|
setNetwork(network: Network): void;
|
|
27
30
|
/**
|
|
28
31
|
* Add a new client to the wallet
|
|
29
|
-
* @param chain to
|
|
30
|
-
* @returns {boolean}
|
|
31
|
-
* @throws {Error} If
|
|
32
|
+
* @param chain - Chain to add the client for
|
|
33
|
+
* @returns {boolean} True if client is successfully added, otherwise false
|
|
34
|
+
* @throws {Error} If trying to add a client on a different network compared to others
|
|
32
35
|
*/
|
|
33
36
|
addClient(chain: Chain, client: XChainClient): boolean;
|
|
34
37
|
/**
|
|
35
|
-
* Purge and remove client from wallet
|
|
36
|
-
* @param chain to remove the client
|
|
37
|
-
* @returns {true}
|
|
38
|
+
* Purge and remove client from the wallet
|
|
39
|
+
* @param chain Chain to remove the client for
|
|
40
|
+
* @returns {true} True if the client is successfully purged and removed, otherwise false
|
|
38
41
|
*/
|
|
39
42
|
purgeClient(chain: Chain): boolean;
|
|
40
43
|
/**
|
|
41
44
|
* Purge and remove all clients from wallet
|
|
42
|
-
* @returns {boolean}
|
|
45
|
+
* @returns {boolean} True if the wallet is successfully purged and removed, otherwise false
|
|
43
46
|
*/
|
|
44
47
|
purgeWallet(): boolean;
|
|
45
48
|
/**
|
|
46
49
|
* Get chain address
|
|
47
|
-
* @param {Chain} chain
|
|
48
|
-
* @returns {string}
|
|
50
|
+
* @param {Chain} chain The chain
|
|
51
|
+
* @returns {string} The chain address
|
|
49
52
|
*/
|
|
50
53
|
getAddress(chain: Chain): Promise<string>;
|
|
51
54
|
/**
|
|
52
|
-
* Get wallet chain addresses.
|
|
53
|
-
* @param {Chain[]} chains Optional
|
|
54
|
-
*
|
|
55
|
-
* @returns the chains addresses
|
|
55
|
+
* Get the wallet chain addresses.
|
|
56
|
+
* @param {Chain[]} chains Optional chains to get addresses for, if not provided, returns all wallet addresses
|
|
57
|
+
* @returns Addresses mapped by chain
|
|
56
58
|
*/
|
|
57
59
|
getAddresses(chains?: Chain[]): Promise<Record<Chain, Address>>;
|
|
58
60
|
/**
|
|
59
61
|
* Check if address is valid
|
|
60
|
-
* @param {Chain} chain in which the address has to be valid
|
|
61
|
-
* @param {string} address to validate
|
|
62
|
+
* @param {Chain} chain The chain in which the address has to be valid
|
|
63
|
+
* @param {string} address The address to validate
|
|
62
64
|
* @returns {boolean} true if it is a valid address, otherwise, false
|
|
63
65
|
*/
|
|
64
66
|
validateAddress(chain: Chain, address: string): boolean;
|
|
65
67
|
/**
|
|
66
68
|
* Get chain balances
|
|
67
|
-
* @param {Chain} chain to retrieve the balance of
|
|
69
|
+
* @param {Chain} chain The chain to retrieve the balance of
|
|
68
70
|
* @returns {Balance[]} the chain balances
|
|
69
71
|
*/
|
|
70
72
|
getBalance(chain: Chain, assets?: Asset[]): Promise<Balance[]>;
|
|
71
73
|
/**
|
|
72
|
-
*
|
|
74
|
+
* By default, it returns all the wallet balances unless assets are provided, in that case,
|
|
73
75
|
* only asset balances will be returned by chain
|
|
74
76
|
* @param {Assets[]} assets - Optional. Assets of which return the balance
|
|
75
77
|
* @returns {Record<Chain, Balance[]>} Balances by chain
|
|
@@ -89,7 +91,8 @@ export declare class Wallet {
|
|
|
89
91
|
*/
|
|
90
92
|
getTransactionsHistory(chain: Chain): Promise<TxsPage>;
|
|
91
93
|
/**
|
|
92
|
-
* Get wallet histories.
|
|
94
|
+
* Get wallet histories.
|
|
95
|
+
* By default, it returns all the wallet histories unless chains are provided, in that case,
|
|
93
96
|
* only chain histories will be returned by chain
|
|
94
97
|
* @param {Chain[]} chains - Optional. Chain of which return the transaction history
|
|
95
98
|
* @returns {TxsPage} the chain transaction history
|
|
@@ -97,35 +100,35 @@ export declare class Wallet {
|
|
|
97
100
|
getTransactionsHistories(chains?: Chain[]): Promise<Record<Chain, TxsPage>>;
|
|
98
101
|
/**
|
|
99
102
|
* Get explorer url
|
|
100
|
-
* @param {Chain} chain to retrieve the explorer of
|
|
101
|
-
* @returns {string} the transaction
|
|
103
|
+
* @param {Chain} chain The chain to retrieve the explorer of
|
|
104
|
+
* @returns {string} the transaction URL
|
|
102
105
|
*/
|
|
103
106
|
getExplorerUrl(chain: Chain): Promise<string>;
|
|
104
107
|
/**
|
|
105
|
-
* Get address
|
|
106
|
-
* @param {Chain} chain of the address
|
|
107
|
-
* @param {string} address to retrieve the
|
|
108
|
-
* @returns {string}
|
|
108
|
+
* Get address URL
|
|
109
|
+
* @param {Chain} chain Chain of the address
|
|
110
|
+
* @param {string} address The address to retrieve the URL of
|
|
111
|
+
* @returns {string} The address URL
|
|
109
112
|
*/
|
|
110
113
|
getExplorerAddressUrl(chain: Chain, address: string): Promise<string>;
|
|
111
114
|
/**
|
|
112
|
-
* Get transaction
|
|
113
|
-
* @param {Chain} chain of the transaction
|
|
114
|
-
* @param {string} hash of the transaction
|
|
115
|
-
* @returns the transaction
|
|
115
|
+
* Get transaction URL
|
|
116
|
+
* @param {Chain} chain Chain of the transaction
|
|
117
|
+
* @param {string} hash Hash of the transaction
|
|
118
|
+
* @returns the transaction URL
|
|
116
119
|
*/
|
|
117
120
|
getExplorerTxUrl(chain: Chain, hash: string): Promise<string>;
|
|
118
121
|
/**
|
|
119
122
|
* Get feeRates. Only available for EVM clients
|
|
120
|
-
* @param {Chain} chain of which return the feeRates
|
|
121
|
-
* @returns {GasPrices}
|
|
122
|
-
* @throws {Error}
|
|
123
|
+
* @param {Chain} chain Chain of which return the feeRates
|
|
124
|
+
* @returns {GasPrices} Chain of which return the feeRates
|
|
125
|
+
* @throws {Error} If gas fee rates cannot be returned from the chain
|
|
123
126
|
*/
|
|
124
127
|
getGasFeeRates(chain: Chain): Promise<GasPrices>;
|
|
125
128
|
/**
|
|
126
129
|
* Make a transaction
|
|
127
|
-
* @param {TxParams} txParams to make the transfer
|
|
128
|
-
* @returns
|
|
130
|
+
* @param {TxParams} txParams txParams - The parameters to make the transfer
|
|
131
|
+
* @returns The transaction hash
|
|
129
132
|
*/
|
|
130
133
|
transfer({ asset, amount, recipient, memo, walletIndex }: TxParams & {
|
|
131
134
|
asset: Asset;
|
|
@@ -134,34 +137,34 @@ export declare class Wallet {
|
|
|
134
137
|
* Make a deposit
|
|
135
138
|
* @param {DepositParam} depositParams
|
|
136
139
|
* @returns {string} the hash of the deposit
|
|
137
|
-
* @throws {Error} if
|
|
140
|
+
* @throws {Error} if cannot make deposit with the asset
|
|
138
141
|
*/
|
|
139
142
|
deposit({ asset, amount, memo, walletIndex, sequence, gasLimit, }: DepositParam & {
|
|
140
143
|
asset: Asset;
|
|
141
144
|
}): Promise<string>;
|
|
142
145
|
/**
|
|
143
146
|
* Check if an spenderAddress is allowed to spend in name of another address certain asset amount
|
|
144
|
-
* @param {Asset} asset to check
|
|
145
|
-
* @param {BaseAmount} amount to check
|
|
146
|
-
* @param {string} fromAddress owner of the amount asset
|
|
147
|
-
* @param {string} spenderAddress spender to check if it is allowed to spend
|
|
147
|
+
* @param {Asset} asset The asset to check
|
|
148
|
+
* @param {BaseAmount} amount The amount to check
|
|
149
|
+
* @param {string} fromAddress The owner of the amount asset from
|
|
150
|
+
* @param {string} spenderAddress The spender to check if it is allowed to spend
|
|
148
151
|
* @returns true if the spenderAddress is allowed to spend the amount, otherwise, false
|
|
149
|
-
* @throws {Error}
|
|
152
|
+
* @throws {Error} If asset is a non ERC20 asset
|
|
150
153
|
*/
|
|
151
154
|
approve(asset: Asset, amount: BaseAmount, spenderAddress: string): Promise<ethers.providers.TransactionResponse>;
|
|
152
155
|
/**
|
|
153
156
|
* Check if an spenderAddress is allowed to spend in name of another address certain asset amount
|
|
154
|
-
* @param {Asset} asset to check
|
|
155
|
-
* @param {BaseAmount} amount to check
|
|
156
|
-
* @param {string} fromAddress
|
|
157
|
-
* @param {string} spenderAddress
|
|
157
|
+
* @param {Asset} asset The asset to check
|
|
158
|
+
* @param {BaseAmount} amount The amount to check
|
|
159
|
+
* @param {string} fromAddress oThe wner of the amount asset from
|
|
160
|
+
* @param {string} spenderAddress Spender to check if it is allowed to spend
|
|
158
161
|
* @returns true if the spenderAddress is allowed to spend the amount, otherwise, false
|
|
159
|
-
* @throws {Error}
|
|
162
|
+
* @throws {Error} If asset is a non ERC20 asset
|
|
160
163
|
*/
|
|
161
164
|
isApproved(asset: Asset, amount: BaseAmount, fromAddress: string, spenderAddress: string): Promise<boolean>;
|
|
162
165
|
/**
|
|
163
166
|
* Broadcast transaction
|
|
164
|
-
* @param {Chain} chain in which broadcast the signed raw transaction
|
|
167
|
+
* @param {Chain} chain The chain in which broadcast the signed raw transaction
|
|
165
168
|
* @param {string} txHex signed raw transaction
|
|
166
169
|
* @returns {TxHash} the broadcasted transaction hash
|
|
167
170
|
*/
|
|
@@ -175,9 +178,9 @@ export declare class Wallet {
|
|
|
175
178
|
getChainWallet(chain: Chain): ethers.Wallet;
|
|
176
179
|
/**
|
|
177
180
|
* Get chain client
|
|
178
|
-
* @param {Chain} chain of which return the client
|
|
179
|
-
* @returns {XChainClient}
|
|
180
|
-
* @throws {Error}
|
|
181
|
+
* @param {Chain} chain The chain of which to return the client
|
|
182
|
+
* @returns {XChainClient} The chain client
|
|
183
|
+
* @throws {Error} If the client does not exist
|
|
181
184
|
*/
|
|
182
185
|
private getClient;
|
|
183
186
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-wallet",
|
|
3
3
|
"description": "XChainjs clients wrapper to work with several chains at the same time",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "lib/index.esm.js",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"@xchainjs/xchain-evm": "0.4.4",
|
|
32
32
|
"@xchainjs/xchain-util": "0.13.2",
|
|
33
33
|
"@xchainjs/xchain-client": "0.16.1",
|
|
34
|
-
"@xchainjs/xchain-thorchain": "1.0.
|
|
34
|
+
"@xchainjs/xchain-thorchain": "1.0.3",
|
|
35
|
+
"@xchainjs/xchain-mayachain": "1.0.0",
|
|
35
36
|
"ethers": "5.6.6"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@xchainjs/xchain-bitcoin": "0.23.10",
|
|
39
|
-
"@xchainjs/xchain-ethereum": "0.31.5"
|
|
40
|
-
"@xchainjs/xchain-mayachain": "0.2.16"
|
|
40
|
+
"@xchainjs/xchain-ethereum": "0.31.5"
|
|
41
41
|
}
|
|
42
42
|
}
|