diff --git a/packages/xchain-thorchain-amm/CHANGELOG.md b/packages/xchain-thorchain-amm/CHANGELOG.md index c0498e5b1..6b77bc0c6 100644 --- a/packages/xchain-thorchain-amm/CHANGELOG.md +++ b/packages/xchain-thorchain-amm/CHANGELOG.md @@ -1,3 +1,9 @@ +# v0.7.13 (2023-11-05) + +## Update + +- Wallet can be initialised with a custom config by chain + # v0.7.12 (2023-11-05) ## Update diff --git a/packages/xchain-thorchain-amm/__e2e__/wallet.e2e.ts b/packages/xchain-thorchain-amm/__e2e__/wallet.e2e.ts index 4908aed06..c06dc8940 100644 --- a/packages/xchain-thorchain-amm/__e2e__/wallet.e2e.ts +++ b/packages/xchain-thorchain-amm/__e2e__/wallet.e2e.ts @@ -1,5 +1,5 @@ import cosmosclient from '@cosmos-client/core' -import { Network } from '@xchainjs/xchain-client' +import { ExplorerProvider, Network } from '@xchainjs/xchain-client' import { AssetBTC, AssetETH, @@ -13,7 +13,7 @@ import { import { baseToAsset, formatAssetAmountCurrency, register9Rheader } from '@xchainjs/xchain-util' import axios from 'axios' -import { Wallet } from '../src/wallet' +import { ChainConfigs, Wallet } from '../src/wallet' require('dotenv').config() @@ -127,4 +127,43 @@ describe('xchain-swap wallet Tests', () => { console.error(e) } }) + + it(`Can init wallet with custom config`, async () => { + try { + const customConfig: ChainConfigs = { + [BTCChain]: { + explorerProviders: { + [Network.Mainnet]: new ExplorerProvider( + 'https://custom.mainnet.provider', + 'https://custom.mainnet.provider/address/%%ADDRESS%%', + 'https://custom.mainnet.provider/tx/%%TX_ID%%', + ), + [Network.Testnet]: new ExplorerProvider( + 'https://custom.testnet.provider', + 'https://custom.testnet.provider/address/%%ADDRESS%%', + 'https://custom.testnet.provider/tx/%%TX_ID%%', + ), + [Network.Stagenet]: new ExplorerProvider( + 'https://custom.stagenet.provider', + 'https://custom.stagenet.provider/address/%%ADDRESS%%', + 'https://custom.stagenet.provider/tx/%%TX_ID%%', + ), + }, + dataProviders: [], + }, + } + const wallet = new Wallet( + process.env.MAINNETPHRASE || 'you forgot to set the phrase', + thorchainQueryMainnet, + customConfig, + ) + for (const [chain, client] of Object.entries(wallet.clients)) { + console.log(`${chain} config`) + console.log(`Network: ${client.getNetwork()}`) + console.log(`Explorer provider: ${client.getExplorerUrl()}`) + } + } catch (e) { + console.error(e) + } + }) }) diff --git a/packages/xchain-thorchain-amm/package.json b/packages/xchain-thorchain-amm/package.json index b51a0eb7c..4c24e8307 100644 --- a/packages/xchain-thorchain-amm/package.json +++ b/packages/xchain-thorchain-amm/package.json @@ -1,6 +1,6 @@ { "name": "@xchainjs/xchain-thorchain-amm", - "version": "0.7.12", + "version": "0.7.13", "description": "module that exposes estimating & swappping cryptocurrency assets on thorchain", "keywords": [ "THORChain", diff --git a/packages/xchain-thorchain-amm/src/wallet.ts b/packages/xchain-thorchain-amm/src/wallet.ts index 5c64101f7..e074378f1 100644 --- a/packages/xchain-thorchain-amm/src/wallet.ts +++ b/packages/xchain-thorchain-amm/src/wallet.ts @@ -1,15 +1,16 @@ -import { Client as AvaxClient, defaultAvaxParams } from '@xchainjs/xchain-avax' -import { Client as BnbClient } from '@xchainjs/xchain-binance' -import { BTCChain, Client as BtcClient } from '@xchainjs/xchain-bitcoin' -import { Client as BchClient } from '@xchainjs/xchain-bitcoincash' -import { Client as BscClient, defaultBscParams } from '@xchainjs/xchain-bsc' -import { FeeOption, Network, XChainClient } from '@xchainjs/xchain-client' -import { Client as CosmosClient } from '@xchainjs/xchain-cosmos' -import { Client as DogeClient } from '@xchainjs/xchain-doge' -import { Client as EthClient, defaultEthParams } from '@xchainjs/xchain-ethereum' -import { Client as LtcClient } from '@xchainjs/xchain-litecoin' -import { Client as MayaClient } from '@xchainjs/xchain-mayachain' -import { Client as ThorClient, THORChain, ThorchainClient } from '@xchainjs/xchain-thorchain' +import { AVAXChain, Client as AvaxClient, defaultAvaxParams } from '@xchainjs/xchain-avax' +import { BNBChain, Client as BnbClient } from '@xchainjs/xchain-binance' +import { BTCChain, Client as BtcClient, defaultBTCParams as defaultBtcParams } from '@xchainjs/xchain-bitcoin' +import { BCHChain, Client as BchClient, defaultBchParams } from '@xchainjs/xchain-bitcoincash' +import { BSCChain, Client as BscClient, defaultBscParams } from '@xchainjs/xchain-bsc' +import { FeeOption, Network, UtxoClientParams, XChainClient, XChainClientParams } from '@xchainjs/xchain-client' +import { Client as CosmosClient, GAIAChain } from '@xchainjs/xchain-cosmos' +import { Client as DogeClient, DOGEChain, defaultDogeParams } from '@xchainjs/xchain-doge' +import { Client as EthClient, ETHChain, defaultEthParams } from '@xchainjs/xchain-ethereum' +import { EVMClientParams } from '@xchainjs/xchain-evm' +import { Client as LtcClient, LTCChain, defaultLtcParams } from '@xchainjs/xchain-litecoin' +import { Client as MayaClient, MAYAChain, MayachainClientParams } from '@xchainjs/xchain-mayachain' +import { Client as ThorClient, THORChain, ThorchainClient, ThorchainClientParams } from '@xchainjs/xchain-thorchain' import { CryptoAmount, ThorchainQuery } from '@xchainjs/xchain-thorchain-query' import { Address, Asset, assetFromString } from '@xchainjs/xchain-util' @@ -28,6 +29,19 @@ import { EvmHelper } from './utils/evm-helper' export type NodeUrls = Record +export type ChainConfigs = Partial<{ + [BTCChain]: Omit + [BCHChain]: Omit + [LTCChain]: Omit + [DOGEChain]: Omit + [ETHChain]: Omit + [AVAXChain]: Omit + [BSCChain]: Omit + [GAIAChain]: Omit + [BNBChain]: Omit + [THORChain]: Omit + [MAYAChain]: Omit +}> /** * Wallet Class for managing all xchain-* wallets with a mnemonic seed. */ @@ -40,33 +54,26 @@ export class Wallet { * * @param phrase - mnemonic phrase * @param thorchainCache - an instance of the ThorchainCache (could be pointing to stagenet,testnet,mainnet) + * @param chainConfigs - Config by chain * @returns Wallet */ - constructor(phrase: string, thorchainQuery: ThorchainQuery) { + constructor(phrase: string, thorchainQuery: ThorchainQuery, chainConfigs: ChainConfigs = {}) { this.thorchainQuery = thorchainQuery const settings = { network: this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, phrase } this.clients = { - BCH: new BchClient(), - BTC: new BtcClient(), - DOGE: new DogeClient(), - LTC: new LtcClient(), - THOR: new ThorClient(settings), - BNB: new BnbClient(settings), - GAIA: new CosmosClient(settings), - MAYA: new MayaClient(settings), - ETH: new EthClient({ ...defaultEthParams, network: settings.network, phrase }), - AVAX: new AvaxClient({ ...defaultAvaxParams, network: settings.network, phrase }), - BSC: new BscClient({ ...defaultBscParams, network: settings.network, phrase }), + BCH: new BchClient({ ...defaultBchParams, ...chainConfigs[BCHChain], ...settings }), + BTC: new BtcClient({ ...defaultBtcParams, ...chainConfigs[BTCChain], ...settings }), + DOGE: new DogeClient({ ...defaultDogeParams, ...chainConfigs[DOGEChain], ...settings }), + LTC: new LtcClient({ ...defaultLtcParams, ...chainConfigs[LTCChain], ...settings }), + THOR: new ThorClient({ ...chainConfigs[THORChain], ...settings }), + BNB: new BnbClient({ ...chainConfigs[BNBChain], ...settings }), + GAIA: new CosmosClient({ ...chainConfigs[GAIAChain], ...settings }), + MAYA: new MayaClient({ ...chainConfigs[MAYAChain], ...settings }), + ETH: new EthClient({ ...defaultEthParams, ...chainConfigs[ETHChain], ...settings }), + AVAX: new AvaxClient({ ...defaultAvaxParams, ...chainConfigs[AVAXChain], ...settings }), + BSC: new BscClient({ ...defaultBscParams, ...chainConfigs[BSCChain], ...settings }), } - this.clients.BCH.setNetwork(settings.network) - this.clients.BCH.setPhrase(settings.phrase, 0) - this.clients.BTC.setNetwork(settings.network) - this.clients.BTC.setPhrase(settings.phrase, 0) - this.clients.DOGE.setNetwork(settings.network) - this.clients.DOGE.setPhrase(settings.phrase, 0) - this.clients.LTC.setNetwork(settings.network) - this.clients.LTC.setPhrase(settings.phrase, 0) this.evmHelpers = { ETH: new EvmHelper(this.clients.ETH, this.thorchainQuery.thorchainCache),