@reyaxyz/common 0.278.0 → 0.278.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,5 +6,5 @@
6
6
 
7
7
  | Statements | Branches | Functions | Lines |
8
8
  | --------------------------- | ----------------------- | ------------------------- | ----------------- |
9
- | ![Statements](https://img.shields.io/badge/statements-19.68%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-17.14%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-10%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-21.18%25-red.svg?style=flat) |
9
+ | ![Statements](https://img.shields.io/badge/statements-19.73%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-16.78%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-9.9%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-21.3%25-red.svg?style=flat) |
10
10
 
@@ -2,5 +2,6 @@ export * from './token-getters';
2
2
  export * from './batch-token-getters';
3
3
  export * from './token-info-getters';
4
4
  export * from './utils';
5
+ export * from './normalize';
5
6
  export * from './token-info';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["utils/token/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["utils/token/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { TradingApi } from '../../trading-api-types';
2
+ export declare const normalizeDecimals: (value: string | null | undefined, decimals: number) => string | null | undefined;
3
+ export declare const normalizeAccountBalance: (accountBalance: TradingApi['wallet/:address/accounts/balances']['response'][0]) => {
4
+ account_id: number | null;
5
+ collateral: string | null;
6
+ balance?: string | null | undefined;
7
+ delta?: string | null | undefined;
8
+ };
9
+ //# sourceMappingURL=normalize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"/","sources":["utils/token/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD,eAAO,MAAM,iBAAiB,UACrB,MAAM,GAAG,IAAI,GAAG,SAAS,YACtB,MAAM,8BASjB,CAAC;AAEF,eAAO,MAAM,uBAAuB,mBAClB,UAAU,CAAC,mCAAmC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;;;;;CAW/E,CAAC"}
@@ -18,5 +18,6 @@ __exportStar(require("./token-getters"), exports);
18
18
  __exportStar(require("./batch-token-getters"), exports);
19
19
  __exportStar(require("./token-info-getters"), exports);
20
20
  __exportStar(require("./utils"), exports);
21
+ __exportStar(require("./normalize"), exports);
21
22
  __exportStar(require("./token-info"), exports);
22
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["utils/token/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,wDAAsC;AACtC,uDAAqC;AACrC,0CAAwB;AACxB,+CAA6B","sourcesContent":["export * from './token-getters';\nexport * from './batch-token-getters';\nexport * from './token-info-getters';\nexport * from './utils';\nexport * from './token-info';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["utils/token/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,wDAAsC;AACtC,uDAAqC;AACrC,0CAAwB;AACxB,8CAA4B;AAC5B,+CAA6B","sourcesContent":["export * from './token-getters';\nexport * from './batch-token-getters';\nexport * from './token-info-getters';\nexport * from './utils';\nexport * from './normalize';\nexport * from './token-info';\n"]}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.normalizeAccountBalance = exports.normalizeDecimals = void 0;
15
+ var token_info_getters_1 = require("./token-info-getters");
16
+ var normalizeDecimals = function (value, decimals) {
17
+ if (!value)
18
+ return value;
19
+ var padLength = 18 - decimals;
20
+ if (!padLength)
21
+ return value;
22
+ if (padLength < 0) {
23
+ return value.slice(0, padLength) || '0';
24
+ }
25
+ return value + ''.padStart(padLength, '0');
26
+ };
27
+ exports.normalizeDecimals = normalizeDecimals;
28
+ var normalizeAccountBalance = function (accountBalance) {
29
+ if (!accountBalance.collateral) {
30
+ return accountBalance;
31
+ }
32
+ var decimals = (0, token_info_getters_1.getTokenInfoByAddress)(accountBalance.collateral).decimals;
33
+ return __assign(__assign({}, accountBalance), { balance: (0, exports.normalizeDecimals)(accountBalance.balance, decimals), delta: (0, exports.normalizeDecimals)(accountBalance.delta, decimals) });
34
+ };
35
+ exports.normalizeAccountBalance = normalizeAccountBalance;
36
+ //# sourceMappingURL=normalize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.js","sourceRoot":"/","sources":["utils/token/normalize.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,2DAA6D;AAEtD,IAAM,iBAAiB,GAAG,UAC/B,KAAgC,EAChC,QAAgB;IAEhB,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACzB,IAAM,SAAS,GAAG,EAAE,GAAG,QAAQ,CAAC;IAChC,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7B,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,IAAI,GAAG,CAAC;IAC1C,CAAC;IACD,OAAO,KAAK,GAAG,EAAE,CAAC,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AAC7C,CAAC,CAAC;AAXW,QAAA,iBAAiB,qBAW5B;AAEK,IAAM,uBAAuB,GAAG,UACrC,cAA8E;IAE9E,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC;QAC/B,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,IAAM,QAAQ,GAAG,IAAA,0CAAqB,EAAC,cAAc,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC;IAC3E,6BACK,cAAc,KACjB,OAAO,EAAE,IAAA,yBAAiB,EAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,EAC5D,KAAK,EAAE,IAAA,yBAAiB,EAAC,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,IACxD;AACJ,CAAC,CAAC;AAZW,QAAA,uBAAuB,2BAYlC","sourcesContent":["import { TradingApi } from '../../trading-api-types';\nimport { getTokenInfoByAddress } from './token-info-getters';\n\nexport const normalizeDecimals = (\n value: string | null | undefined,\n decimals: number,\n) => {\n if (!value) return value;\n const padLength = 18 - decimals;\n if (!padLength) return value;\n if (padLength < 0) {\n return value.slice(0, padLength) || '0';\n }\n return value + ''.padStart(padLength, '0');\n};\n\nexport const normalizeAccountBalance = (\n accountBalance: TradingApi['wallet/:address/accounts/balances']['response'][0],\n) => {\n if (!accountBalance.collateral) {\n return accountBalance;\n }\n const decimals = getTokenInfoByAddress(accountBalance.collateral).decimals;\n return {\n ...accountBalance,\n balance: normalizeDecimals(accountBalance.balance, decimals),\n delta: normalizeDecimals(accountBalance.delta, decimals),\n };\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/common",
3
- "version": "0.278.0",
3
+ "version": "0.278.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -44,5 +44,5 @@
44
44
  "generate:coverage-badges": "npx istanbul-badges-readme --silent"
45
45
  },
46
46
  "packageManager": "pnpm@8.3.1",
47
- "gitHead": "f0acdcb4121213f22dc71a5d9e484a7728071d40"
47
+ "gitHead": "b228b66a062ad32cf7d286ef57f9412fbb6eeeb0"
48
48
  }
@@ -2,4 +2,5 @@ export * from './token-getters';
2
2
  export * from './batch-token-getters';
3
3
  export * from './token-info-getters';
4
4
  export * from './utils';
5
+ export * from './normalize';
5
6
  export * from './token-info';
@@ -0,0 +1,29 @@
1
+ import { TradingApi } from '../../trading-api-types';
2
+ import { getTokenInfoByAddress } from './token-info-getters';
3
+
4
+ export const normalizeDecimals = (
5
+ value: string | null | undefined,
6
+ decimals: number,
7
+ ) => {
8
+ if (!value) return value;
9
+ const padLength = 18 - decimals;
10
+ if (!padLength) return value;
11
+ if (padLength < 0) {
12
+ return value.slice(0, padLength) || '0';
13
+ }
14
+ return value + ''.padStart(padLength, '0');
15
+ };
16
+
17
+ export const normalizeAccountBalance = (
18
+ accountBalance: TradingApi['wallet/:address/accounts/balances']['response'][0],
19
+ ) => {
20
+ if (!accountBalance.collateral) {
21
+ return accountBalance;
22
+ }
23
+ const decimals = getTokenInfoByAddress(accountBalance.collateral).decimals;
24
+ return {
25
+ ...accountBalance,
26
+ balance: normalizeDecimals(accountBalance.balance, decimals),
27
+ delta: normalizeDecimals(accountBalance.delta, decimals),
28
+ };
29
+ };