Skip to content

Commit

Permalink
chore: use constant for USK factory
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-chillios committed Jan 18, 2024
1 parent c2d9536 commit d6176ca
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
6 changes: 6 additions & 0 deletions .changeset/brown-dogs-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@swapkit/toolbox-cosmos": patch
"@swapkit/helpers": patch
---

Add USK factory filter
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"javascript.format.enable": false,
"javascript.preferences.importModuleSpecifier": "relative",
Expand Down
12 changes: 6 additions & 6 deletions packages/swapkit/helpers/src/helpers/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { RequestClient } from '../index.ts';
const getDecimalMethodHex = '0x313ce567';

export type CommonAssetString =
| 'MAYA.MAYA'
| 'ETH.THOR'
| 'ETH.vTHOR'
| `${Chain.Maya}.MAYA`
| `${Chain.Ethereum}.THOR`
| `${Chain.Ethereum}.vTHOR`
| `${Chain.Kujira}.USK`
| Chain;

Expand Down Expand Up @@ -113,9 +113,9 @@ export const getCommonAssetInfo = (
assetString: CommonAssetString,
): { identifier: string; decimal: number } => {
switch (assetString) {
case 'ETH.THOR':
case `${Chain.Ethereum}.THOR`:
return { identifier: 'ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044', decimal: 18 };
case 'ETH.vTHOR':
case `${Chain.Ethereum}.vTHOR`:
return { identifier: 'ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d', decimal: 18 };

case Chain.Cosmos:
Expand All @@ -126,7 +126,7 @@ export const getCommonAssetInfo = (
return { identifier: 'BSC.BNB', decimal: BaseDecimal[assetString] };
case Chain.Maya:
return { identifier: 'MAYA.CACAO', decimal: BaseDecimal.MAYA };
case 'MAYA.MAYA':
case `${Chain.Maya}.MAYA`:
return { identifier: 'MAYA.MAYA', decimal: 4 };

case `${Chain.Kujira}.USK`:
Expand Down
3 changes: 2 additions & 1 deletion packages/toolboxes/cosmos/src/toolbox/BaseCosmosToolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Chain, type ChainId, type DerivationPath } from '@swapkit/types';

import type { CosmosClient } from '../cosmosClient.ts';
import type { BaseCosmosToolboxType } from '../thorchainUtils/types/client-types.ts';
import { USK_KUJIRA_FACTORY_DENOM } from '../util.ts';

type Params = {
client: CosmosClient;
Expand Down Expand Up @@ -34,7 +35,7 @@ export const getAssetFromDenom = async (denom: string, amount: string) => {
case 'ukuji':
case 'kuji':
return AssetValue.fromChainOrSignature(Chain.Kujira, parseInt(amount) / 1e6);
case 'FACTORY/KUJIRA1QK00H5ATUTPSV900X202PXX42NPJR9THG58DNQPA72F2P7M2LUASE444A7/UUSK':
case USK_KUJIRA_FACTORY_DENOM:
// USK on Kujira
return AssetValue.fromChainOrSignature(`${Chain.Kujira}.USK`, parseInt(amount) / 1e6);

Expand Down
20 changes: 4 additions & 16 deletions packages/toolboxes/cosmos/src/toolbox/kujira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type AssetValue, SwapKitNumber } from '@swapkit/helpers';
import { ApiUrl, BaseDecimal, ChainId, DerivationPath } from '@swapkit/types';

import { CosmosClient } from '../cosmosClient.ts';
import type { KujiraToolboxType, ToolboxParams } from '../index.ts';
import { type KujiraToolboxType, type ToolboxParams, USK_KUJIRA_FACTORY_DENOM } from '../index.ts';
import type { TransferParams } from '../types.ts';

import {
Expand Down Expand Up @@ -51,21 +51,9 @@ export const KujiraToolbox = ({ server }: ToolboxParams = {}): KujiraToolboxType
return await Promise.all(
denomBalances
.filter(({ denom }) => {
if (!denom) {
return false;
}
if (denom.includes('IBC/')) {
return false;
}
// include USK from Kujira
if (
denom ===
'FACTORY/KUJIRA1QK00H5ATUTPSV900X202PXX42NPJR9THG58DNQPA72F2P7M2LUASE444A7/UUSK'
) {
return true;
}
// exclude all other FACTORY tokens
return !denom.startsWith('FACTORY');
if (!denom || denom.includes('IBC/')) return false;

return denom === USK_KUJIRA_FACTORY_DENOM || !denom.startsWith('FACTORY');
})
.map(({ denom, amount }) => getAssetFromDenom(denom, amount)),
);
Expand Down
3 changes: 3 additions & 0 deletions packages/toolboxes/cosmos/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { ChainId, FeeOption, RPCUrl } from '@swapkit/types';

import type { CosmosMaxSendableAmountParams } from './types.ts';

export const USK_KUJIRA_FACTORY_DENOM =
'FACTORY/KUJIRA1QK00H5ATUTPSV900X202PXX42NPJR9THG58DNQPA72F2P7M2LUASE444A7/UUSK';

const headers =
typeof window !== 'undefined'
? ({} as { [key: string]: string })
Expand Down

0 comments on commit d6176ca

Please sign in to comment.