Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 455/add stagenet support #456

Merged
merged 15 commits into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The interface is [defined here.](https://github.com/xchainjs/xchainjs-lib/blob/m

The interface supports as a minimum the following functions for each blockchain:

1. Initialise with a valid BIP39 phrase and specified network (testnet/mainnet)
1. Initialise with a valid BIP39 phrase and specified network (testnet/stagenet/mainnet)
2. Get the address, with support for BIP44 path derivations (default is Index 0)
3. Get the balance (UTXO or account-based)
4. Get transaction history for that address
Expand Down
6 changes: 6 additions & 0 deletions packages/xchain-binance/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v.5.4.0 (2021-12-28)

## Breaking change

- Add stagenet environment handling for `Network` and `BaseXChainClient` changes client to default to mainnet values until stagenet is configured.

# v.5.3.1 (2021-09-03)

- updated to the latest dependencies
Expand Down
2 changes: 1 addition & 1 deletion packages/xchain-binance/__tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('BinanceClient Test', () => {

const mainnetClientURL = 'https://dex.binance.org'
const testnetClientURL = 'https://testnet-dex.binance.org'
const thornodeMainetClientURL = 'https://thornode.thorchain.info'
const thornodeMainetClientURL = 'https://thornode.ninerealms.com'

beforeEach(async () => {
bnbClient = new BinanceClient({ phrase, network: 'mainnet' as Network })
Expand Down
6 changes: 3 additions & 3 deletions packages/xchain-binance/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xchainjs/xchain-binance",
"version": "5.3.1",
"version": "5.4.0",
"description": "Custom Binance client and utilities used by XChainJS clients",
"keywords": [
"BNB",
Expand Down Expand Up @@ -35,7 +35,7 @@
"devDependencies": {
"@binance-chain/javascript-sdk": "^4.2.0",
"@types/big.js": "^4.0.5",
"@xchainjs/xchain-client": "^0.10.3",
"@xchainjs/xchain-client": "^0.11.0",
"@xchainjs/xchain-crypto": "^0.2.6",
"@xchainjs/xchain-util": "^0.3.1"
},
Expand All @@ -44,7 +44,7 @@
},
"peerDependencies": {
"@binance-chain/javascript-sdk": "^4.2.0",
"@xchainjs/xchain-client": "^0.10.2",
"@xchainjs/xchain-client": "^0.11.0",
"@xchainjs/xchain-crypto": "^0.2.6",
"@xchainjs/xchain-util": "^0.3.1"
}
Expand Down
23 changes: 20 additions & 3 deletions packages/xchain-binance/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ class Client extends BaseXChainClient implements BinanceClient, XChainClient {
return this.bncClient
}

/**
* Gets the current network, and enforces type limited to
* 'mainnet' and 'testnet', which conflicts with `xchain-client`
*
* Remove this once @binance-chain has stagenet support.
* @returns {Network}
*/
getNetwork(): Network.Mainnet | Network.Testnet {
switch (super.getNetwork()) {
case Network.Mainnet:
case Network.Stagenet:
return Network.Mainnet
case Network.Testnet:
return Network.Testnet
}
}

/**
* Set/update the current network.
*
Expand All @@ -114,7 +131,7 @@ class Client extends BaseXChainClient implements BinanceClient, XChainClient {
* @throws {"Network must be provided"}
* Thrown if network has not been set before.
*/
setNetwork(network: Network): void {
setNetwork(network: Network.Mainnet | Network.Testnet): void {
super.setNetwork(network)
this.bncClient = new BncClient(this.getClientUrl())
this.bncClient.chooseNetwork(network)
Expand All @@ -126,7 +143,7 @@ class Client extends BaseXChainClient implements BinanceClient, XChainClient {
* @returns {string} The client url for binance chain based on the network.
*/
private getClientUrl(): string {
switch (this.network) {
switch (this.getNetwork()) {
case Network.Mainnet:
return 'https://dex.binance.org'
case Network.Testnet:
Expand All @@ -140,7 +157,7 @@ class Client extends BaseXChainClient implements BinanceClient, XChainClient {
* @returns {string} The explorer url based on the network.
*/
getExplorerUrl(): string {
switch (this.network) {
switch (this.getNetwork()) {
case Network.Mainnet:
return 'https://explorer.binance.org'
case Network.Testnet:
Expand Down
1 change: 1 addition & 0 deletions packages/xchain-binance/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const getDefaultFees = (): Fees => {
export const getPrefix = (network: Network) => {
switch (network) {
case Network.Mainnet:
case Network.Stagenet:
return 'bnb'
case Network.Testnet:
return 'tbnb'
Expand Down
6 changes: 6 additions & 0 deletions packages/xchain-bitcoin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v.0.16.0 (2021-12-28)

## Breaking change

- Add stagenet environment handling for `Network` and `BaseXChainClient` changes client to default to mainnet values until stagenet is configured.

# v.0.15.13 (2021-11-12)

- updated haskoin api URL
Expand Down
6 changes: 3 additions & 3 deletions packages/xchain-bitcoin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xchainjs/xchain-bitcoin",
"version": "0.15.13",
"version": "0.16.0",
"description": "Custom Bitcoin client and utilities used by XChainJS clients",
"keywords": [
"XChain",
Expand Down Expand Up @@ -34,7 +34,7 @@
"devDependencies": {
"@types/bitcoinjs-lib": "^5.0.0",
"@types/wif": "^2.0.2",
"@xchainjs/xchain-client": "^0.10.3",
"@xchainjs/xchain-client": "^0.11.0",
"@xchainjs/xchain-crypto": "^0.2.6",
"@xchainjs/xchain-util": "^0.3.1",
"axios": "^0.21.1",
Expand All @@ -44,7 +44,7 @@
"wif": "^2.0.6"
},
"peerDependencies": {
"@xchainjs/xchain-client": "^0.10.3",
"@xchainjs/xchain-client": "^0.11.0",
"@xchainjs/xchain-crypto": "^0.2.6",
"@xchainjs/xchain-util": "^0.3.1",
"axios": "^0.21.1",
Expand Down
1 change: 1 addition & 0 deletions packages/xchain-bitcoin/src/blockstream-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const broadcastTx = async ({ network, txHex, blockstreamUrl }: BroadcastT
const url = (() => {
switch (network) {
case Network.Mainnet:
case Network.Stagenet:
return `${blockstreamUrl}/api/tx`
case Network.Testnet:
return `${blockstreamUrl}/testnet/api/tx`
Expand Down
2 changes: 2 additions & 0 deletions packages/xchain-bitcoin/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Client extends UTXOClient {
rootDerivationPaths = {
[Network.Mainnet]: `84'/0'/0'/0/`, //note this isn't bip44 compliant, but it keeps the wallets generated compatible to pre HD wallets
[Network.Testnet]: `84'/1'/0'/0/`,
[Network.Stagenet]: `84'/0'/0'/0/`,
},
phrase = '',
}: BitcoinClientParams) {
Expand Down Expand Up @@ -83,6 +84,7 @@ class Client extends UTXOClient {
getExplorerUrl(): string {
switch (this.network) {
case Network.Mainnet:
case Network.Stagenet:
return 'https://blockstream.info'
case Network.Testnet:
return 'https://blockstream.info/testnet'
Expand Down
1 change: 1 addition & 0 deletions packages/xchain-bitcoin/src/sochain-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const DEFAULT_SUGGESTED_TRANSACTION_FEE = 127
const toSochainNetwork = (network: Network): string => {
switch (network) {
case Network.Mainnet:
case Network.Stagenet:
return 'BTC'
case Network.Testnet:
return 'BTCTEST'
Expand Down
6 changes: 5 additions & 1 deletion packages/xchain-bitcoin/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const arrayAverage = (array: number[]): number => {
export const btcNetwork = (network: Network): Bitcoin.Network => {
switch (network) {
case Network.Mainnet:
case Network.Stagenet:
return Bitcoin.networks.bitcoin
case Network.Testnet:
return Bitcoin.networks.testnet
Expand All @@ -106,6 +107,7 @@ export const btcNetwork = (network: Network): Bitcoin.Network => {
export const getBalance = async (params: AddressParams): Promise<Balance[]> => {
switch (params.network) {
case Network.Mainnet:
case Network.Stagenet:
return [
{
asset: AssetBTC,
Expand Down Expand Up @@ -181,7 +183,8 @@ export const scanUTXOs = async ({
} as UTXO),
)
}
case Network.Mainnet: {
case Network.Mainnet:
case Network.Stagenet: {
let utxos: haskoinApi.UtxoData[] = []

if (confirmedOnly) {
Expand Down Expand Up @@ -344,6 +347,7 @@ export const getDefaultFees = (): Fees => {
export const getPrefix = (network: Network) => {
switch (network) {
case Network.Mainnet:
case Network.Stagenet:
return 'bc1'
case Network.Testnet:
return 'tb1'
Expand Down
6 changes: 6 additions & 0 deletions packages/xchain-bitcoincash/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v.0.12.0 (2021-12-28)

## Breaking change

- Add stagenet environment handling for `Network` and `BaseXChainClient` changes client to default to mainnet values until stagenet is configured.

# v.0.11.10 (2021-11-12)

- updated haskoin api URL
Expand Down
2 changes: 1 addition & 1 deletion packages/xchain-bitcoincash/__mocks__/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const mock_estimateFee = () => {
}

export const mock_estimateFeeFromThor = () => {
nock('https://thornode.thorchain.info')
nock('https://thornode.ninerealms.com')
.get('/thorchain/inbound_addresses')
.reply(200, [
{
Expand Down
6 changes: 3 additions & 3 deletions packages/xchain-bitcoincash/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xchainjs/xchain-bitcoincash",
"version": "0.11.10",
"version": "0.12.0",
"description": "Custom bitcoincash client and utilities used by XChainJS clients",
"keywords": [
"XChain",
Expand Down Expand Up @@ -39,7 +39,7 @@
"@psf/bitcoincashjs-lib": "^4.0.2",
"@types/bchaddrjs": "0.4.0",
"@types/uniqid": "^5.3.1",
"@xchainjs/xchain-client": "^0.10.3",
"@xchainjs/xchain-client": "^0.11.0",
"@xchainjs/xchain-crypto": "^0.2.6",
"@xchainjs/xchain-util": "^0.3.1",
"axios": "^0.21.1",
Expand All @@ -49,7 +49,7 @@
},
"peerDependencies": {
"@psf/bitcoincashjs-lib": "^4.0.2",
"@xchainjs/xchain-client": "^0.10.3",
"@xchainjs/xchain-client": "^0.11.0",
"@xchainjs/xchain-crypto": "^0.2.6",
"@xchainjs/xchain-util": "^0.3.1",
"axios": "^0.21.1",
Expand Down
4 changes: 4 additions & 0 deletions packages/xchain-bitcoincash/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ class Client extends UTXOClient {
haskoinUrl = {
[Network.Testnet]: 'https://api.haskoin.com/haskoin-store/bch-testnet',
[Network.Mainnet]: 'https://api.haskoin.com/haskoin-store/bch',
[Network.Stagenet]: 'https://api.haskoin.com/haskoin-store/bch',
},
phrase,
nodeUrl = {
[Network.Testnet]: 'https://testnet.bch.thorchain.info',
[Network.Mainnet]: 'https://bch.thorchain.info',
[Network.Stagenet]: 'https://bch.thorchain.info',
},
nodeAuth = {
username: 'thorchain',
Expand All @@ -63,6 +65,7 @@ class Client extends UTXOClient {
rootDerivationPaths = {
[Network.Mainnet]: `m/44'/145'/0'/0/`,
[Network.Testnet]: `m/44'/1'/0'/0/`,
[Network.Stagenet]: `m/44'/145'/0'/0/`,
},
}: BitcoinCashClientParams) {
super(Chain.BitcoinCash, { network, rootDerivationPaths, phrase })
Expand Down Expand Up @@ -123,6 +126,7 @@ class Client extends UTXOClient {
getExplorerUrl(): string {
switch (this.network) {
case Network.Mainnet:
case Network.Stagenet:
return 'https://www.blockchain.com/bch'
case Network.Testnet:
return 'https://www.blockchain.com/bch-testnet'
Expand Down
2 changes: 2 additions & 0 deletions packages/xchain-bitcoincash/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const getBalance = async (params: AddressParams): Promise<Balance[]> => {
export const bchNetwork = (network: Network): BCHNetwork => {
switch (network) {
case Network.Mainnet:
case Network.Stagenet:
return coininfo.bitcoincash.main.toBitcoinJS()
case Network.Testnet:
return coininfo.bitcoincash.test.toBitcoinJS()
Expand Down Expand Up @@ -183,6 +184,7 @@ export const parseTransaction = (tx: Transaction): Tx => {
export const toBCHAddressNetwork = (network: Network): string => {
switch (network) {
case Network.Mainnet:
case Network.Stagenet:
return bchaddr.Network.Mainnet
case Network.Testnet:
return bchaddr.Network.Testnet
Expand Down
6 changes: 6 additions & 0 deletions packages/xchain-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v.0.11.0 (2021-12-28)

### Breaking change

- Expand `Network` enum type to include stagenet and introduce stagenet environment variables to `BaseXChainClient` for thorchain.

# v.0.10.3 (2021-09-02)

- updated to the latest dependencies
Expand Down
2 changes: 1 addition & 1 deletion packages/xchain-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public address: Address

## Set Network

Used to set a type of `Network`, which is either `'mainnet'` or `'testnet'`.
Used to set a type of `Network`, which is either `'mainnet'`, `'stagenet'` or `'testnet'`.

```ts
setNetwork(net: Network): XChainClient
Expand Down
2 changes: 1 addition & 1 deletion packages/xchain-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xchainjs/xchain-client",
"version": "0.10.3",
"version": "0.11.0",
"license": "MIT",
"main": "lib/index",
"types": "lib/index",
Expand Down
9 changes: 8 additions & 1 deletion packages/xchain-client/src/BaseXChainClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
XChainClientParams,
} from './types'

const MAINNET_THORNODE_API_BASE = 'https://thornode.thorchain.info/thorchain'
const MAINNET_THORNODE_API_BASE = 'https://thornode.ninerealms.com/thorchain'
const STAGENET_THORNODE_API_BASE = 'https://stagenet-thornode.ninerealms.com/thorchain'
const TESTNET_THORNODE_API_BASE = 'https://testnet.thornode.thorchain.info/thorchain'

export abstract class BaseXChainClient implements XChainClient {
Expand All @@ -39,6 +40,8 @@ export abstract class BaseXChainClient implements XChainClient {
constructor(chain: Chain, params: XChainClientParams) {
this.chain = chain
this.network = params.network || Network.Testnet
// Fire off a warning in the console to indicate that stagenet and real assets are being used.
if (this.network === Network.Stagenet) console.warn('WARNING: This is using stagenet! Real assets are being used!')
if (params.rootDerivationPaths) this.rootDerivationPaths = params.rootDerivationPaths
//NOTE: we don't call this.setPhrase() to vaoid generating an address and paying the perf penalty
if (params.phrase) {
Expand All @@ -62,6 +65,8 @@ export abstract class BaseXChainClient implements XChainClient {
throw new Error('Network must be provided')
}
this.network = network
// Fire off a warning in the console to indicate that stagenet and real assets are being used.
if (this.network === Network.Stagenet) console.warn('WARNING: This is using stagenet! Real assets are being used!')
}

/**
Expand Down Expand Up @@ -90,6 +95,8 @@ export abstract class BaseXChainClient implements XChainClient {
switch (this.network) {
case Network.Mainnet:
return MAINNET_THORNODE_API_BASE
case Network.Stagenet:
return STAGENET_THORNODE_API_BASE
case Network.Testnet:
return TESTNET_THORNODE_API_BASE
}
Expand Down
1 change: 1 addition & 0 deletions packages/xchain-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type Address = string

export enum Network {
Mainnet = 'mainnet',
Stagenet = 'stagenet',
Testnet = 'testnet',
}

Expand Down
7 changes: 7 additions & 0 deletions packages/xchain-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v.0.15.0 (2021-12-28)

## Breaking change

- Add stagenet environment handling for `Network` and `BaseXChainClient` changes client to default to mainnet values until stagenet is configured.

# v.0.14.0 (2021-12-15)

### Update
Expand All @@ -6,6 +12,7 @@
- extract public part into `unsignedStdTxGet` to use it in `transfer` and `transferSignedOffline`

### Add

- `TxOfflineParams` types
- `transferSignedOffline` functions

Expand Down
Loading