Skip to content

Commit

Permalink
refactor: add currency and abstract value to support international cu…
Browse files Browse the repository at this point in the history
…rrencies and stablecoins
  • Loading branch information
jblewnormal committed Nov 14, 2024
1 parent 8ca3519 commit 2da1d1b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@normalfinance/utils",
"version": "1.6.2",
"version": "1.6.3",
"description": "A Typescript modules for frequently used types, utilities, constants, and more across Normal repositories.",
"homepage": "https://github.com/normalfinance/utils#readme",
"bugs": {
Expand Down Expand Up @@ -46,7 +46,8 @@
"lint:misc": "prettier '**/*.json' '**/*.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
"prepack": "./scripts/prepack.sh",
"test": "jest && jest-it-up",
"test:watch": "jest --watch"
"test:watch": "jest --watch",
"publish": "npm publish --access public"
},
"dependencies": {
"customerio-node": "^4.1.1",
Expand Down
7 changes: 5 additions & 2 deletions src/types/exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ export type ExchangeBalance = {
asset: string;
amount: string;
};

export type PortfolioItem = ExchangeBalance & {
currency: string;
price: string;
usdValue: string;
value: string;
oneHourChange: string;
oneDayChange: string;
oneWeekChange: string;
Expand All @@ -21,7 +23,8 @@ export type ExchangeOrder = {
orderId: string;
side: string;
amount: string;
usdValue: string;
currency: string;
value: string;
price: string;
fee: string;
status: string;
Expand Down
24 changes: 24 additions & 0 deletions src/utils/exchange.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ExchangeIndexQuoteCurrencies } from '../constants';
import type { Exchange } from '../database';

export const FeeAsset = 'SOL';
Expand All @@ -6,3 +7,26 @@ export const getFeeAddress = (exchangeType: Exchange['type']) =>
exchangeType === 'coinbase'
? '[email protected]'
: '7cbDHP5ksonpWJXmTWGsuD8yKVTxC4RfZ26JCYbSxRqX';

/**
* Returns a base and quote asset from a non-delimited string.
* @param exchangeType - The exchange the string came from.
* @param symbol - The combined asset pair string.
* @returns The base and quote assets.
*/
export const parseAssetsFromCombinedSymbol = (
exchangeType: Exchange['type'],
symbol: string,
): { baseAsset: string; quoteAsset: string } => {
let baseAsset = symbol.toUpperCase();
let quoteAsset = '';

for (const currency in ExchangeIndexQuoteCurrencies[exchangeType]) {
if (baseAsset.includes(currency)) {
quoteAsset = currency;
baseAsset = baseAsset.replace(currency, '');
}
}

return { baseAsset, quoteAsset };
};

0 comments on commit 2da1d1b

Please sign in to comment.