From 4f9d16a618eab5d0c7ad3acdf7580a88817648b5 Mon Sep 17 00:00:00 2001 From: 0xp3gasus <0xp3gasus@proton.me> Date: Thu, 25 Jan 2024 12:00:39 +0100 Subject: [PATCH 1/3] USK asset support --- packages/xchain-cosmos-sdk/src/client.ts | 2 +- packages/xchain-kujira/src/client.ts | 4 +++- packages/xchain-kujira/src/const.ts | 10 ++++++++++ packages/xchain-kujira/src/index.ts | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/xchain-cosmos-sdk/src/client.ts b/packages/xchain-cosmos-sdk/src/client.ts index 137534643..347c3bc79 100644 --- a/packages/xchain-cosmos-sdk/src/client.ts +++ b/packages/xchain-cosmos-sdk/src/client.ts @@ -356,7 +356,7 @@ export default abstract class Client extends BaseXChainClient implements XChainC }) // TODO: Support fee configuration (subsided fee) - const denom = this.getDenom(params.asset || this.getAssetInfo().asset) + const denom = this.getDenom(this.getAssetInfo().asset) const defaultGasPrice = GasPrice.fromString(`0.025${denom}`) const defaultSendFee: StdFee = calculateFee(90_000, defaultGasPrice) diff --git a/packages/xchain-kujira/src/client.ts b/packages/xchain-kujira/src/client.ts index 91788ba72..fffba01f3 100644 --- a/packages/xchain-kujira/src/client.ts +++ b/packages/xchain-kujira/src/client.ts @@ -2,7 +2,7 @@ import { AssetInfo } from '@xchainjs/xchain-client' import { Client as CosmosSdkClient, CosmosSdkClientParams } from '@xchainjs/xchain-cosmos-sdk' import { Address, Asset, eqAsset } from '@xchainjs/xchain-util' -import { AssetKUJI, KUJI_DECIMAL } from './const' +import { AssetKUJI, AssetUSK, KUJI_DECIMAL, USK_ASSET_DENOM } from './const' import { defaultClientConfig, getDefaultExplorers } from './utils' export type KujiraClientParams = Partial @@ -25,11 +25,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, diff --git a/packages/xchain-kujira/src/const.ts b/packages/xchain-kujira/src/const.ts index e3653ae35..d9b2048a8 100644 --- a/packages/xchain-kujira/src/const.ts +++ b/packages/xchain-kujira/src/const.ts @@ -9,3 +9,13 @@ export const DEFAULT_FEE = baseAmount(5000, KUJI_DECIMAL) 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 } diff --git a/packages/xchain-kujira/src/index.ts b/packages/xchain-kujira/src/index.ts index 4f9183495..213045e8b 100644 --- a/packages/xchain-kujira/src/index.ts +++ b/packages/xchain-kujira/src/index.ts @@ -1,3 +1,3 @@ export * from './client' -export { KUJIChain } from './const' +export { KUJIChain, AssetKUJI, AssetUSK } from './const' export { defaultClientConfig as defaultKujiParams } from './utils' From d58fdfd31572b41f183c05b9b52d5f53d1a1a9f8 Mon Sep 17 00:00:00 2001 From: 0xp3gasus <0xp3gasus@proton.me> Date: Thu, 25 Jan 2024 12:06:16 +0100 Subject: [PATCH 2/3] e2e tests --- .../__e2e__/kujira-client.e2e.ts | 12 ++++++++- .../__e2e__/mayachainAmm.e2e.ts | 26 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/packages/xchain-kujira/__e2e__/kujira-client.e2e.ts b/packages/xchain-kujira/__e2e__/kujira-client.e2e.ts index a7e300a4d..bc0c89da6 100644 --- a/packages/xchain-kujira/__e2e__/kujira-client.e2e.ts +++ b/packages/xchain-kujira/__e2e__/kujira-client.e2e.ts @@ -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 @@ -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', diff --git a/packages/xchain-mayachain-amm/__e2e__/mayachainAmm.e2e.ts b/packages/xchain-mayachain-amm/__e2e__/mayachainAmm.e2e.ts index 90c2a463c..db3eee7fc 100644 --- a/packages/xchain-mayachain-amm/__e2e__/mayachainAmm.e2e.ts +++ b/packages/xchain-mayachain-amm/__e2e__/mayachainAmm.e2e.ts @@ -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' @@ -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, @@ -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, From c7b9b7d86909db741ec4486af49af7e200bb94f9 Mon Sep 17 00:00:00 2001 From: 0xp3gasus <0xp3gasus@proton.me> Date: Thu, 25 Jan 2024 12:18:58 +0100 Subject: [PATCH 3/3] Changeset version files --- .changeset/cyan-dryers-knock.md | 5 +++++ .changeset/six-beans-pretend.md | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 .changeset/cyan-dryers-knock.md create mode 100644 .changeset/six-beans-pretend.md diff --git a/.changeset/cyan-dryers-knock.md b/.changeset/cyan-dryers-knock.md new file mode 100644 index 000000000..303723bff --- /dev/null +++ b/.changeset/cyan-dryers-knock.md @@ -0,0 +1,5 @@ +--- +'@xchainjs/xchain-kujira': patch +--- + +USK asset support diff --git a/.changeset/six-beans-pretend.md b/.changeset/six-beans-pretend.md new file mode 100644 index 000000000..ac5581ced --- /dev/null +++ b/.changeset/six-beans-pretend.md @@ -0,0 +1,5 @@ +--- +'@xchainjs/xchain-cosmos-sdk': patch +--- + +Native asset for fee in transfer method