Skip to content

Commit

Permalink
894 midgard query decimals (#896)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xp3gasus authored Nov 4, 2023
1 parent aba77c2 commit 0d5d691
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 15 deletions.
6 changes: 6 additions & 0 deletions packages/xchain-midgard-query/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.1.4 (2023-11-04)

## Update

- getDecimalForAsset can handle synth assets

# v0.1.3 (2023-10-06)

## Update
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Network } from '@xchainjs/xchain-client'
import { THORNameDetails } from '@xchainjs/xchain-midgard'
import { assetFromStringEx } from '@xchainjs/xchain-util'

import { MidgardCache } from '../src/midgard-cache'
import { MidgardQuery } from '../src/midgard-query'
Expand Down Expand Up @@ -75,4 +76,14 @@ describe('Midgard-query liquidity action end to end Tests', () => {
)
console.log('thornames', thornames)
})
it(`Shoud return decimals by asset`, async () => {
const atomDecimals = await midgardQuery.getDecimalForAsset(AssetATOM)
const avaxDecimals = await midgardQuery.getDecimalForAsset(AssetAVAX)
const btcDecimals = await midgardQuery.getDecimalForAsset(AssetBTC)
const synthBtcDecimals = await midgardQuery.getDecimalForAsset(assetFromStringEx('BTC/BTC'))
console.log(`AssetATOM decimals: ${atomDecimals}`)
console.log(`AssetAVAX decimals: ${avaxDecimals}`)
console.log(`AssetBTC decimals: ${btcDecimals}`)
console.log(`Synth AssetBTC decimals: ${synthBtcDecimals}`)
})
})
4 changes: 2 additions & 2 deletions packages/xchain-midgard-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xchainjs/xchain-midgard-query",
"version": "0.1.3",
"version": "0.1.4",
"license": "MIT",
"description": "Module that is responsible for get data from Midgard API",
"keywords": [
Expand Down Expand Up @@ -50,4 +50,4 @@
"publishConfig": {
"access": "public"
}
}
}
13 changes: 6 additions & 7 deletions packages/xchain-midgard-query/src/midgard-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,11 @@ export class MidgardQuery {
* @returns {number} Number of decimals from Midgard https://gitlab.com/thorchain/midgard#refresh-native-decimals
*/
public async getDecimalForAsset(asset: Asset): Promise<number> {
if (!isAssetRuneNative(asset)) {
const pool = await this.getPool(assetToString(asset))
const decimals = Number(pool.nativeDecimal)
if (decimals > 0) return decimals
else return DEFAULT_THORCHAIN_DECIMALS
}
return DEFAULT_THORCHAIN_DECIMALS
if (isAssetRuneNative(asset) || asset.synth) return DEFAULT_THORCHAIN_DECIMALS

const pool = await this.getPool(assetToString(asset))
const decimals = Number(pool.nativeDecimal)

return decimals > 0 ? decimals : DEFAULT_THORCHAIN_DECIMALS
}
}
6 changes: 6 additions & 0 deletions packages/xchain-thorchain-amm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.7.11 (2023-11-04)

## Update

- thorchain-query package from 0.6.7 to 0.6.8

# v0.7.10 (2023-11-02)

## Update
Expand Down
6 changes: 3 additions & 3 deletions packages/xchain-thorchain-amm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xchainjs/xchain-thorchain-amm",
"version": "0.7.10",
"version": "0.7.11",
"description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
"keywords": [
"THORChain",
Expand Down Expand Up @@ -50,7 +50,7 @@
"@xchainjs/xchain-doge": "^0.7.3",
"@xchainjs/xchain-ethereum": "^0.30.5",
"@xchainjs/xchain-thornode": "^0.3.8",
"@xchainjs/xchain-thorchain-query": "^0.6.7",
"@xchainjs/xchain-thorchain-query": "^0.6.8",
"@xchainjs/xchain-evm": "^0.3.5",
"@xchainjs/xchain-litecoin": "^0.13.2",
"@xchainjs/xchain-mayachain": "^0.2.8",
Expand Down Expand Up @@ -86,7 +86,7 @@
"@xchainjs/xchain-doge": "^0.7.3",
"@xchainjs/xchain-ethereum": "^0.30.5",
"@xchainjs/xchain-thornode": "^0.3.8",
"@xchainjs/xchain-thorchain-query": "^0.6.7",
"@xchainjs/xchain-thorchain-query": "^0.6.8",
"@xchainjs/xchain-evm": "^0.3.5",
"@xchainjs/xchain-litecoin": "^0.13.2",
"@xchainjs/xchain-mayachain": "^0.2.8",
Expand Down
6 changes: 6 additions & 0 deletions packages/xchain-thorchain-query/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.6.8 (2023-11-04)

## Update

- midgard-query package from 0.1.3 to 0.1.4

# v0.6.7 (2023-11-03)

## Update
Expand Down
6 changes: 3 additions & 3 deletions packages/xchain-thorchain-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xchainjs/xchain-thorchain-query",
"version": "0.6.7",
"version": "0.6.8",
"license": "MIT",
"description": "Thorchain query module that is resposible for estimating swap calculations and add/remove liquidity for thorchain ",
"keywords": [
Expand Down Expand Up @@ -35,7 +35,7 @@
"devDependencies": {
"@xchainjs/xchain-client": "^0.15.1",
"@xchainjs/xchain-thornode": "^0.3.8",
"@xchainjs/xchain-midgard-query": "^0.1.3",
"@xchainjs/xchain-midgard-query": "^0.1.4",
"@xchainjs/xchain-util": "^0.13.1",
"axios": "^1.3.6",
"axios-retry": "^3.2.5",
Expand All @@ -44,7 +44,7 @@
"peerDependencies": {
"@xchainjs/xchain-client": "^0.15.1",
"@xchainjs/xchain-thornode": "^0.3.8",
"@xchainjs/xchain-midgard-query": "^0.1.3",
"@xchainjs/xchain-midgard-query": "^0.1.4",
"@xchainjs/xchain-util": "^0.13.1",
"axios": "^1.3.6",
"axios-retry": "^3.2.5",
Expand Down

0 comments on commit 0d5d691

Please sign in to comment.