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

1012 mayachain refactor #1018

Merged
merged 17 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/cyan-maps-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xchainjs/xchain-cosmos-sdk': patch
---

getAssetDecimals abstract function
5 changes: 5 additions & 0 deletions .changeset/khaki-ants-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xchainjs/xchain-kujira': patch
---

getAssetDecimals function
5 changes: 5 additions & 0 deletions .changeset/short-elephants-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xchainjs/xchain-thorchain': patch
---

getAssetDecimals function
15 changes: 15 additions & 0 deletions .changeset/thick-sloths-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@xchainjs/xchain-mayachain': major
---

Breaking changes
- `getPrivateKey` is now async and response is Uint8Array type
- `getPubKey` is now async and response is Uint8Array type
- `getDepositTransaction` is deprecated in favour of `getTransactionData`
- `fetchTransaction` removed
- `setClientUrl` removed
- `getClientUrl` removed
- `setExplorerUrls` removed
- `getCosmosClient` removed
- `setChainId` removed
- `getChainId` removed
5 changes: 3 additions & 2 deletions packages/xchain-cosmos-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export enum MsgTypes {
* Generic implementation of the XChainClient interface chains built with cosmos-sdk (https://docs.cosmos.network/) using the dependencies of the official @cosmjs monorepo.
*/
export default abstract class Client extends BaseXChainClient implements XChainClient {
private readonly defaultDecimals: number
private readonly defaultFee: BaseAmount
protected startgateClient: CachedValue<StargateClient>
protected prefix: string
protected readonly defaultDecimals: number
protected readonly clientUrls: Record<Network, string>
protected readonly baseDenom: string
protected readonly registry: Registry
Expand Down Expand Up @@ -315,7 +315,7 @@ export default abstract class Client extends BaseXChainClient implements XChainC
if (asset) {
balances.push({
asset,
amount: baseAmount(balance.amount, this.defaultDecimals),
amount: baseAmount(balance.amount, this.getAssetDecimals(asset)),
})
}
})
Expand Down Expand Up @@ -429,6 +429,7 @@ export default abstract class Client extends BaseXChainClient implements XChainC
abstract getExplorerTxUrl(txID: string): string
abstract assetFromDenom(denom: string): Asset | null
abstract getDenom(asset: Asset): string | null
public abstract getAssetDecimals(asset: Asset): number
protected abstract getMsgTypeUrlByType(msgType: MsgTypes): string
protected abstract getStandardFee(asset: Asset): StdFee
protected abstract getPrefix(network: Network): string
Expand Down
6 changes: 5 additions & 1 deletion packages/xchain-kujira/__tests__/kujira-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Network } from '@xchainjs/xchain-client'

import { Client as KujiraClient } from '../src/client'
import { DEFAULT_FEE } from '../src/const'
import { AssetKUJI, AssetUSK, DEFAULT_FEE } from '../src/const'

let xchainClient: KujiraClient
const phraseOne = 'atom green various power must another rent imitate gadget creek fat then'
Expand All @@ -17,6 +17,10 @@ describe('Kujira client Integration Tests', () => {
const isValid = xchainClient.validateAddress('asdadasd')
expect(isValid).toBe(false)
})
it('should get asset decimals', async () => {
expect(xchainClient.getAssetDecimals(AssetKUJI)).toBe(6)
expect(xchainClient.getAssetDecimals(AssetUSK)).toBe(6)
})
it('should validate valid addreses', async () => {
const isValid = xchainClient.validateAddress('kujira1es76p8qspctcxhex79c32nng9fvhuxjn4z6u7k')
expect(isValid).toBe(true)
Expand Down
10 changes: 5 additions & 5 deletions packages/xchain-kujira/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
"prepublishOnly": "yarn build"
},
"dependencies": {
"@cosmjs/amino": "0.31.1",
"@cosmjs/encoding": "0.31.1",
"@cosmjs/proto-signing": "0.31.1",
"@cosmjs/stargate": "0.31.1",
"@xchainjs/xchain-cosmos-sdk": "0.2.2"
"@xchainjs/xchain-cosmos-sdk": "0.2.2",
"cosmjs-types": "0.8.0"
},
"devDependencies": {
"@cosmjs/amino": "0.31.1",
"@cosmjs/proto-signing": "0.31.1",
"@xchainjs/xchain-client": "^0.16.1",
"@xchainjs/xchain-util": "^0.13.2",
"cosmjs-types": "0.8.0"
"@xchainjs/xchain-util": "^0.13.2"
},
"publishConfig": {
"access": "public"
Expand Down
14 changes: 13 additions & 1 deletion packages/xchain-kujira/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Client as CosmosSdkClient, CosmosSdkClientParams, MsgTypes } from '@xch
import { Address, Asset, eqAsset } from '@xchainjs/xchain-util'
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx'

import { AssetKUJI, AssetUSK, KUJI_DECIMAL, MSG_SEND_TYPE_URL, USK_ASSET_DENOM } from './const'
import { AssetKUJI, AssetUSK, KUJI_DECIMAL, MSG_SEND_TYPE_URL, USK_ASSET_DENOM, USK_DECIMAL } from './const'
import { defaultClientConfig, getDefaultExplorers } from './utils'

export type KujiraClientParams = Partial<CosmosSdkClientParams>
Expand Down Expand Up @@ -37,6 +37,18 @@ export class Client extends CosmosSdkClient {
return assetInfo
}

/**
* Returns the number of the decimals of known assets
*
* @param {Asset} asset - Asset of which return the number of decimals
* @returns {number} the number of decimals of the assets
*/
public getAssetDecimals(asset: Asset): number {
if (eqAsset(asset, AssetKUJI)) return KUJI_DECIMAL
if (eqAsset(asset, AssetUSK)) return USK_DECIMAL
return this.defaultDecimals
}

getDenom(asset: Asset): string | null {
if (eqAsset(asset, AssetKUJI)) return this.baseDenom
if (eqAsset(asset, AssetUSK)) return USK_ASSET_DENOM
Expand Down
5 changes: 5 additions & 0 deletions packages/xchain-kujira/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ export const USK_ASSET_DENOM = 'factory/kujira1qk00h5atutpsv900x202pxx42npjr9thg
*/
export const AssetUSK: Asset = { chain: KUJIChain, symbol: 'USK', ticker: 'USK', synth: false }

/**
* USK asset number of decimals
*/
export const USK_DECIMAL = 6

export const MSG_SEND_TYPE_URL = '/cosmos.bank.v1beta1.MsgSend' as const
3 changes: 1 addition & 2 deletions packages/xchain-mayachain-amm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@xchainjs/xchain-ethereum": "0.31.5",
"@xchainjs/xchain-kujira": "0.1.10",
"@xchainjs/xchain-mayachain-query": "0.1.7",
"@xchainjs/xchain-mayachain": "0.2.16",
"@xchainjs/xchain-thorchain": "1.0.2",
"@xchainjs/xchain-wallet": "0.1.4"
},
Expand All @@ -52,7 +53,6 @@
"@xchainjs/xchain-mayanode": "^0.1.3",
"@xchainjs/xchain-mayachain-query": "^0.1.7",
"@xchainjs/xchain-evm": "^0.4.4",
"@xchainjs/xchain-mayachain": "^0.2.16",
"@xchainjs/xchain-mayamidgard": "^0.1.1",
"@xchainjs/xchain-util": "^0.13.1",
"@xchainjs/xchain-utxo": "^0.1.2",
Expand All @@ -77,7 +77,6 @@
"@xchainjs/xchain-mayanode": "^0.1.3",
"@xchainjs/xchain-mayachain-query": "^0.1.7",
"@xchainjs/xchain-evm": "^0.4.4",
"@xchainjs/xchain-mayachain": "^0.2.16",
"@xchainjs/xchain-mayamidgard": "^0.1.1",
"@xchainjs/xchain-util": "^0.13.1",
"@xchainjs/xchain-utxo": "^0.1.2",
Expand Down
Loading
Loading