Skip to content

Commit

Permalink
USK asset support (#1011)
Browse files Browse the repository at this point in the history
* USK asset support

* e2e tests

* Changeset version files
  • Loading branch information
0xp3gasus authored Jan 25, 2024
1 parent 754fe1a commit 6e86d90
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-dryers-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xchainjs/xchain-kujira': patch
---

USK asset support
5 changes: 5 additions & 0 deletions .changeset/six-beans-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xchainjs/xchain-cosmos-sdk': patch
---

Native asset for fee in transfer method
2 changes: 1 addition & 1 deletion packages/xchain-cosmos-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export default abstract class Client extends BaseXChainClient implements XChainC
const tx = await signingClient.signAndBroadcast(
sender,
messages,
this.getStandardFee(params.asset || this.getAssetInfo().asset),
this.getStandardFee(this.getAssetInfo().asset),
unsignedTx.body.memo,
)

Expand Down
12 changes: 11 additions & 1 deletion packages/xchain-kujira/__e2e__/kujira-client.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Network, TxParams } from '@xchainjs/xchain-client'
import { assetAmount, assetToBase, assetToString, baseAmount } from '@xchainjs/xchain-util'

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

let xchainClient: KujiraClient

Expand Down Expand Up @@ -63,6 +63,16 @@ describe('Kujira client Integration Tests', () => {
const txHash = await xchainClient.transfer(txDate)
console.log('txHash', txHash)
})
it('Try USK asset transfer', async () => {
const txData: TxParams = {
asset: AssetUSK,
amount: assetToBase(assetAmount(1, 6)),
recipient: await xchainClient.getAddressAsync(0),
memo: 'usk test',
}
const txHash = await xchainClient.transfer(txData)
console.log('txHash', txHash)
})
it('Prepare transaction', async () => {
const unsignedRawTx = await xchainClient.prepareTx({
sender: 'kujira1es76p8qspctcxhex79c32nng9fvhuxjn4z6u7k',
Expand Down
4 changes: 3 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, KUJI_DECIMAL, MSG_SEND_TYPE_URL } from './const'
import { AssetKUJI, AssetUSK, KUJI_DECIMAL, MSG_SEND_TYPE_URL, USK_ASSET_DENOM } from './const'
import { defaultClientConfig, getDefaultExplorers } from './utils'

export type KujiraClientParams = Partial<CosmosSdkClientParams>
Expand All @@ -30,11 +30,13 @@ export class Client extends CosmosSdkClient {

getDenom(asset: Asset): string | null {
if (eqAsset(asset, AssetKUJI)) return this.baseDenom
if (eqAsset(asset, AssetUSK)) return USK_ASSET_DENOM
return null
}

assetFromDenom(denom: string): Asset | null {
if (denom === this.baseDenom) return AssetKUJI
if (denom === USK_ASSET_DENOM) return AssetUSK
return {
chain: AssetKUJI.chain,
symbol: denom,
Expand Down
10 changes: 10 additions & 0 deletions packages/xchain-kujira/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,14 @@ export const KUJIChain = 'KUJI' as const

export const AssetKUJI: Asset = { chain: KUJIChain, symbol: 'KUJI', ticker: 'KUJI', synth: false }

/**
* USK denom
*/
export const USK_ASSET_DENOM = 'factory/kujira1qk00h5atutpsv900x202pxx42npjr9thg58dnqpa72f2p7m2luase444a7/uusk' as const

/**
* USK Asset
*/
export const AssetUSK: Asset = { chain: KUJIChain, symbol: 'USK', ticker: 'USK', synth: false }

export const MSG_SEND_TYPE_URL = '/cosmos.bank.v1beta1.MsgSend' as const
2 changes: 1 addition & 1 deletion packages/xchain-kujira/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './client'
export { KUJIChain } from './const'
export { KUJIChain, AssetKUJI, AssetUSK } from './const'
export { defaultClientConfig as defaultKujiParams } from './utils'
26 changes: 25 additions & 1 deletion packages/xchain-mayachain-amm/__e2e__/mayachainAmm.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AssetBTC, Client as BtcClient, defaultBTCParams as defaultBtcParams } f
import { Network } from '@xchainjs/xchain-client'
import { Client as DashClient, defaultDashParams } from '@xchainjs/xchain-dash'
import { AssetETH, Client as EthClient, defaultEthParams } from '@xchainjs/xchain-ethereum'
import { Client as KujiraClient, defaultKujiParams } from '@xchainjs/xchain-kujira'
import { AssetUSK, Client as KujiraClient, defaultKujiParams } from '@xchainjs/xchain-kujira'
import { AssetCacao, Client as MayaClient } from '@xchainjs/xchain-mayachain'
import { MayachainQuery, QuoteSwap } from '@xchainjs/xchain-mayachain-query'
import { AssetRuneNative, Client as ThorClient } from '@xchainjs/xchain-thorchain'
Expand Down Expand Up @@ -158,6 +158,18 @@ describe('MayachainAmm e2e tests', () => {
printQuoteSwap(quoteSwap)
})

it(`Should estimate swap from USK to Rune`, async () => {
const quoteSwap = await mayachainAmm.estimateSwap({
fromAsset: AssetUSK,
fromAddress: await wallet.getAddress('KUJI'),
destinationAsset: AssetRuneNative,
destinationAddress: await wallet.getAddress('THOR'),
amount: new CryptoAmount(assetToBase(assetAmount(1, 6)), AssetUSK),
})

printQuoteSwap(quoteSwap)
})

it('Should validate swap from ERC20 to BTC without errors', async () => {
const errors = await mayachainAmm.validateSwap({
fromAsset: ETH_USDT,
Expand Down Expand Up @@ -194,6 +206,18 @@ describe('MayachainAmm e2e tests', () => {
console.log(txSubmitted)
})

it('Should do non protocol asset swap. USK -> Rune', async () => {
const txSubmitted = await mayachainAmm.doSwap({
fromAsset: AssetUSK,
fromAddress: await wallet.getAddress('KUJI'),
destinationAsset: AssetRuneNative,
destinationAddress: await wallet.getAddress('THOR'),
amount: new CryptoAmount(assetToBase(assetAmount(1, 6)), AssetUSK),
})

console.log(txSubmitted)
})

it('Should do protocol asset swap. Cacao -> Rune', async () => {
const txSubmitted = await mayachainAmm.doSwap({
fromAsset: AssetCacao,
Expand Down

0 comments on commit 6e86d90

Please sign in to comment.