@shapeshiftoss/utils 1.0.0 → 1.0.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.
Files changed (137) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -0
  2. package/dist/cjs/assertUnreachable.js +7 -0
  3. package/dist/cjs/assetData/assetData.test.js +136 -0
  4. package/dist/{assetData → cjs/assetData}/baseAssets.d.ts +1 -0
  5. package/dist/cjs/assetData/baseAssets.js +319 -0
  6. package/dist/cjs/assetData/constants.js +13 -0
  7. package/dist/{assetData → cjs/assetData}/decodeAssetData.d.ts +1 -1
  8. package/dist/cjs/assetData/decodeAssetData.js +106 -0
  9. package/dist/cjs/assetData/decodeRelatedAssetIndex.js +14 -0
  10. package/dist/cjs/assetData/encodeAssetData.js +72 -0
  11. package/dist/cjs/assetData/encodeRelatedAssetIndex.js +20 -0
  12. package/dist/cjs/assetData/getBaseAsset.js +48 -0
  13. package/dist/cjs/assetData/index.js +23 -0
  14. package/dist/cjs/assetData/relatedAssetIndex.test.js +32 -0
  15. package/dist/cjs/assetData/types.js +2 -0
  16. package/dist/cjs/baseUnits/baseUnits.js +32 -0
  17. package/dist/cjs/baseUnits/baseUnits.test.js +32 -0
  18. package/dist/cjs/basisPoints.js +48 -0
  19. package/dist/{bignumber → cjs/bignumber}/bignumber.d.ts +1 -1
  20. package/dist/cjs/bignumber/bignumber.js +27 -0
  21. package/dist/cjs/bignumber/bignumber.test.js +52 -0
  22. package/dist/cjs/chainIdToFeeAsset.js +9 -0
  23. package/dist/cjs/chainIdToFeeAssetId.js +48 -0
  24. package/dist/cjs/createThrottle.js +36 -0
  25. package/dist/cjs/getAssetNamespaceFromChainId.js +34 -0
  26. package/dist/cjs/getChainShortName.js +47 -0
  27. package/dist/cjs/getNativeFeeAssetReference.js +67 -0
  28. package/dist/cjs/historyTimeframe.js +36 -0
  29. package/dist/cjs/index.js +61 -0
  30. package/dist/cjs/makeAsset/makeAsset.js +45 -0
  31. package/dist/cjs/makeAsset/makeAsset.test.js +47 -0
  32. package/dist/cjs/package.json +1 -0
  33. package/dist/cjs/promises.js +9 -0
  34. package/dist/cjs/sha256.js +9 -0
  35. package/dist/{timeout.d.ts → cjs/timeout.d.ts} +4 -0
  36. package/dist/cjs/timeout.js +34 -0
  37. package/dist/{treasury.d.ts → cjs/treasury.d.ts} +1 -1
  38. package/dist/cjs/treasury.js +33 -0
  39. package/dist/cjs/unfreeze.js +10 -0
  40. package/dist/cjs/utxo.js +6 -0
  41. package/dist/esm/.tsbuildinfo +1 -0
  42. package/dist/esm/assertUnreachable.d.ts +1 -0
  43. package/dist/{assetData → esm/assetData}/assetData.test.js +16 -2
  44. package/dist/esm/assetData/baseAssets.d.ts +21 -0
  45. package/dist/{assetData → esm/assetData}/baseAssets.js +18 -4
  46. package/dist/esm/assetData/constants.d.ts +1 -0
  47. package/dist/esm/assetData/decodeAssetData.d.ts +7 -0
  48. package/dist/{assetData → esm/assetData}/decodeAssetData.js +12 -4
  49. package/dist/esm/assetData/decodeRelatedAssetIndex.d.ts +3 -0
  50. package/dist/esm/assetData/encodeAssetData.d.ts +4 -0
  51. package/dist/{assetData → esm/assetData}/encodeAssetData.js +2 -2
  52. package/dist/esm/assetData/encodeRelatedAssetIndex.d.ts +3 -0
  53. package/dist/esm/assetData/getBaseAsset.d.ts +3 -0
  54. package/dist/{assetData → esm/assetData}/getBaseAsset.js +2 -2
  55. package/dist/esm/assetData/index.d.ts +7 -0
  56. package/dist/esm/assetData/index.js +7 -0
  57. package/dist/esm/assetData/relatedAssetIndex.test.d.ts +1 -0
  58. package/dist/{assetData → esm/assetData}/relatedAssetIndex.test.js +2 -2
  59. package/dist/esm/assetData/types.d.ts +28 -0
  60. package/dist/esm/assetData/types.js +1 -0
  61. package/dist/esm/baseUnits/baseUnits.d.ts +5 -0
  62. package/dist/{baseUnits → esm/baseUnits}/baseUnits.js +1 -1
  63. package/dist/esm/baseUnits/baseUnits.test.d.ts +1 -0
  64. package/dist/{baseUnits → esm/baseUnits}/baseUnits.test.js +1 -1
  65. package/dist/esm/basisPoints.d.ts +23 -0
  66. package/dist/{basisPoints.js → esm/basisPoints.js} +1 -1
  67. package/dist/esm/bignumber/bignumber.d.ts +11 -0
  68. package/dist/{bignumber → esm/bignumber}/bignumber.js +1 -1
  69. package/dist/esm/bignumber/bignumber.test.d.ts +1 -0
  70. package/dist/{bignumber → esm/bignumber}/bignumber.test.js +1 -1
  71. package/dist/esm/chainIdToFeeAsset.d.ts +3 -0
  72. package/dist/{chainIdToFeeAsset.js → esm/chainIdToFeeAsset.js} +1 -1
  73. package/dist/esm/chainIdToFeeAssetId.d.ts +2 -0
  74. package/dist/{chainIdToFeeAssetId.js → esm/chainIdToFeeAssetId.js} +1 -1
  75. package/dist/esm/createThrottle.d.ts +9 -0
  76. package/dist/esm/getAssetNamespaceFromChainId.d.ts +3 -0
  77. package/dist/{getAssetNamespaceFromChainId.js → esm/getAssetNamespaceFromChainId.js} +1 -2
  78. package/dist/esm/getChainShortName.d.ts +2 -0
  79. package/dist/{getChainShortName.js → esm/getChainShortName.js} +1 -1
  80. package/dist/esm/getNativeFeeAssetReference.d.ts +2 -0
  81. package/dist/esm/historyTimeframe.d.ts +6 -0
  82. package/dist/{historyTimeframe.js → esm/historyTimeframe.js} +1 -1
  83. package/dist/esm/index.d.ts +24 -0
  84. package/dist/{index.js → esm/index.js} +19 -19
  85. package/dist/esm/makeAsset/makeAsset.d.ts +10 -0
  86. package/dist/{makeAsset → esm/makeAsset}/makeAsset.js +4 -2
  87. package/dist/esm/makeAsset/makeAsset.test.d.ts +1 -0
  88. package/dist/{makeAsset → esm/makeAsset}/makeAsset.test.js +1 -1
  89. package/dist/esm/promises.d.ts +4 -0
  90. package/dist/esm/sha256.d.ts +1 -0
  91. package/dist/esm/timeout.d.ts +7 -0
  92. package/dist/{timeout.js → esm/timeout.js} +11 -0
  93. package/dist/esm/treasury.d.ts +15 -0
  94. package/dist/{treasury.js → esm/treasury.js} +1 -1
  95. package/dist/esm/unfreeze.d.ts +4 -0
  96. package/dist/esm/utxo.d.ts +2 -0
  97. package/package.json +21 -9
  98. package/dist/assetData/index.js +0 -7
  99. /package/dist/{assertUnreachable.d.ts → cjs/assertUnreachable.d.ts} +0 -0
  100. /package/dist/{assetData → cjs/assetData}/assetData.test.d.ts +0 -0
  101. /package/dist/{assetData → cjs/assetData}/constants.d.ts +0 -0
  102. /package/dist/{assetData → cjs/assetData}/decodeRelatedAssetIndex.d.ts +0 -0
  103. /package/dist/{assetData → cjs/assetData}/encodeAssetData.d.ts +0 -0
  104. /package/dist/{assetData → cjs/assetData}/encodeRelatedAssetIndex.d.ts +0 -0
  105. /package/dist/{assetData → cjs/assetData}/getBaseAsset.d.ts +0 -0
  106. /package/dist/{assetData → cjs/assetData}/index.d.ts +0 -0
  107. /package/dist/{assetData → cjs/assetData}/relatedAssetIndex.test.d.ts +0 -0
  108. /package/dist/{assetData → cjs/assetData}/types.d.ts +0 -0
  109. /package/dist/{baseUnits → cjs/baseUnits}/baseUnits.d.ts +0 -0
  110. /package/dist/{baseUnits → cjs/baseUnits}/baseUnits.test.d.ts +0 -0
  111. /package/dist/{basisPoints.d.ts → cjs/basisPoints.d.ts} +0 -0
  112. /package/dist/{bignumber → cjs/bignumber}/bignumber.test.d.ts +0 -0
  113. /package/dist/{chainIdToFeeAsset.d.ts → cjs/chainIdToFeeAsset.d.ts} +0 -0
  114. /package/dist/{chainIdToFeeAssetId.d.ts → cjs/chainIdToFeeAssetId.d.ts} +0 -0
  115. /package/dist/{createThrottle.d.ts → cjs/createThrottle.d.ts} +0 -0
  116. /package/dist/{getAssetNamespaceFromChainId.d.ts → cjs/getAssetNamespaceFromChainId.d.ts} +0 -0
  117. /package/dist/{getChainShortName.d.ts → cjs/getChainShortName.d.ts} +0 -0
  118. /package/dist/{getNativeFeeAssetReference.d.ts → cjs/getNativeFeeAssetReference.d.ts} +0 -0
  119. /package/dist/{historyTimeframe.d.ts → cjs/historyTimeframe.d.ts} +0 -0
  120. /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
  121. /package/dist/{makeAsset → cjs/makeAsset}/makeAsset.d.ts +0 -0
  122. /package/dist/{makeAsset → cjs/makeAsset}/makeAsset.test.d.ts +0 -0
  123. /package/dist/{promises.d.ts → cjs/promises.d.ts} +0 -0
  124. /package/dist/{sha256.d.ts → cjs/sha256.d.ts} +0 -0
  125. /package/dist/{unfreeze.d.ts → cjs/unfreeze.d.ts} +0 -0
  126. /package/dist/{utxo.d.ts → cjs/utxo.d.ts} +0 -0
  127. /package/dist/{assertUnreachable.js → esm/assertUnreachable.js} +0 -0
  128. /package/dist/{assetData/types.js → esm/assetData/assetData.test.d.ts} +0 -0
  129. /package/dist/{assetData → esm/assetData}/constants.js +0 -0
  130. /package/dist/{assetData → esm/assetData}/decodeRelatedAssetIndex.js +0 -0
  131. /package/dist/{assetData → esm/assetData}/encodeRelatedAssetIndex.js +0 -0
  132. /package/dist/{createThrottle.js → esm/createThrottle.js} +0 -0
  133. /package/dist/{getNativeFeeAssetReference.js → esm/getNativeFeeAssetReference.js} +0 -0
  134. /package/dist/{promises.js → esm/promises.js} +0 -0
  135. /package/dist/{sha256.js → esm/sha256.js} +0 -0
  136. /package/dist/{unfreeze.js → esm/unfreeze.js} +0 -0
  137. /package/dist/{utxo.js → esm/utxo.js} +0 -0
@@ -0,0 +1,21 @@
1
+ import type { Asset } from '@shapeshiftoss/types';
2
+ export declare const ethereum: Readonly<Asset>;
3
+ export declare const bitcoin: Readonly<Asset>;
4
+ export declare const bitcoincash: Readonly<Asset>;
5
+ export declare const dogecoin: Readonly<Asset>;
6
+ export declare const litecoin: Readonly<Asset>;
7
+ export declare const atom: Readonly<Asset>;
8
+ export declare const avax: Readonly<Asset>;
9
+ export declare const thorchain: Readonly<Asset>;
10
+ export declare const tcy: Readonly<Asset>;
11
+ export declare const ruji: Readonly<Asset>;
12
+ export declare const maya: Readonly<Asset>;
13
+ export declare const mayachain: Readonly<Asset>;
14
+ export declare const optimism: Readonly<Asset>;
15
+ export declare const bnbsmartchain: Readonly<Asset>;
16
+ export declare const polygon: Readonly<Asset>;
17
+ export declare const gnosis: Readonly<Asset>;
18
+ export declare const arbitrum: Readonly<Asset>;
19
+ export declare const arbitrumNova: Readonly<Asset>;
20
+ export declare const base: Readonly<Asset>;
21
+ export declare const solana: Readonly<Asset>;
@@ -120,7 +120,21 @@ export const tcy = Object.freeze({
120
120
  symbol: 'TCY',
121
121
  precision: 8,
122
122
  color: '#33FF99',
123
- icon: 'https://raw.githubusercontent.com/shapeshift/web/develop/scripts/generateAssetData/thorchain/icons/tcy-icon.png',
123
+ icon: 'https://raw.githubusercontent.com/shapeshift/web/develop/src/assets/tcy-icon.png',
124
+ explorer: 'https://viewblock.io/thorchain',
125
+ explorerAddressLink: 'https://viewblock.io/thorchain/address/',
126
+ explorerTxLink: 'https://viewblock.io/thorchain/tx/',
127
+ relatedAssetKey: null,
128
+ });
129
+ export const ruji = Object.freeze({
130
+ assetId: caip.rujiAssetId,
131
+ chainId: caip.thorchainChainId,
132
+ name: 'Rujira',
133
+ networkName: 'THORChain',
134
+ symbol: 'RUJI',
135
+ precision: 8,
136
+ color: '#D800D8',
137
+ icon: 'https://raw.githubusercontent.com/shapeshift/web/develop/src/assets/ruji-icon.png',
124
138
  explorer: 'https://viewblock.io/thorchain',
125
139
  explorerAddressLink: 'https://viewblock.io/thorchain/address/',
126
140
  explorerTxLink: 'https://viewblock.io/thorchain/tx/',
@@ -134,7 +148,7 @@ export const maya = Object.freeze({
134
148
  symbol: 'MAYA',
135
149
  precision: 4,
136
150
  color: '#00FFA0',
137
- icon: 'https://raw.githubusercontent.com/shapeshift/web/develop/scripts/generateAssetData/thorchain/icons/maya.png',
151
+ icon: 'https://raw.githubusercontent.com/shapeshift/web/develop/src/assets/maya.png',
138
152
  explorer: 'https://mayascan.org',
139
153
  explorerAddressLink: 'https://mayascan.org/address/',
140
154
  explorerTxLink: 'https://mayascan.org/tx/',
@@ -148,8 +162,8 @@ export const mayachain = Object.freeze({
148
162
  symbol: 'CACAO',
149
163
  precision: 10,
150
164
  color: '#63FDD9',
151
- icon: 'https://gitlab.com/mayachain/frontend/mayachain-explorer-v2/-/raw/main/assets/images/cacao.png',
152
- networkIcon: 'https://gitlab.com/uploads/-/system/project/avatar/36018613/maya_logo.png',
165
+ icon: 'https://raw.githubusercontent.com/shapeshift/web/develop/src/assets/cacao.png',
166
+ networkIcon: 'https://raw.githubusercontent.com/shapeshift/web/develop/src/assets/mayachain.png',
153
167
  explorer: 'https://mayascan.org',
154
168
  explorerAddressLink: 'https://mayascan.org/address/',
155
169
  explorerTxLink: 'https://mayascan.org/tx/',
@@ -0,0 +1 @@
1
+ export declare const FIELDS: readonly ["assetIdx", "name", "precision", "color", "icon", "symbol", "relatedAssetKey", "isPool"];
@@ -0,0 +1,7 @@
1
+ import type { AssetId } from '@shapeshiftoss/caip';
2
+ import type { Asset } from '@shapeshiftoss/types';
3
+ import type { EncodedAssetData } from './types.js';
4
+ export declare const decodeAssetData: (encodedAssetData: EncodedAssetData, shouldAddNetworkName?: boolean) => {
5
+ assetData: Record<AssetId, Asset>;
6
+ sortedAssetIds: AssetId[];
7
+ };
@@ -1,8 +1,8 @@
1
1
  import { fromAssetId } from '@shapeshiftoss/caip';
2
2
  import { pick } from 'lodash';
3
- import { assertUnreachable } from '../assertUnreachable';
4
- import { FIELDS } from './constants';
5
- import { getBaseAsset } from './getBaseAsset';
3
+ import { assertUnreachable } from '../assertUnreachable.js';
4
+ import { FIELDS } from './constants.js';
5
+ import { getBaseAsset } from './getBaseAsset.js';
6
6
  const decodeAssetId = (encodedAssetId, assetIdPrefixes) => {
7
7
  // Performance sensitive. `lastIndexOf` + `substring` faster than `split`
8
8
  const colonIndex = encodedAssetId.lastIndexOf(':');
@@ -11,7 +11,7 @@ const decodeAssetId = (encodedAssetId, assetIdPrefixes) => {
11
11
  // Performance sensitive. String concatenation faster than template literal
12
12
  return assetIdPrefixes[prefixIdx] + ':' + assetReference;
13
13
  };
14
- export const decodeAssetData = (encodedAssetData) => {
14
+ export const decodeAssetData = (encodedAssetData, shouldAddNetworkName = false) => {
15
15
  const { assetIdPrefixes, encodedAssetIds, encodedAssets } = encodedAssetData;
16
16
  const sortedAssetIds = encodedAssetIds.map(encodedAssetId => decodeAssetId(encodedAssetId, assetIdPrefixes));
17
17
  const assetData = encodedAssets.reduce((acc, encodedAsset, idx) => {
@@ -55,7 +55,15 @@ export const decodeAssetData = (encodedAssetData) => {
55
55
  const assetIdx = value;
56
56
  const relatedAssetId = assetIdx === null ? null : sortedAssetIds[assetIdx];
57
57
  // if (relatedAssetId === undefined) throw Error()
58
+ if (relatedAssetId &&
59
+ relatedAssetId !== asset.assetId &&
60
+ baseAsset.networkName &&
61
+ shouldAddNetworkName) {
62
+ asset.name = `${asset.name} on ${baseAsset.networkName}`;
63
+ }
58
64
  asset.relatedAssetKey = relatedAssetId;
65
+ asset.isPrimary = relatedAssetId === null || relatedAssetId === asset.assetId;
66
+ asset.isChainSpecific = relatedAssetId === null;
59
67
  break;
60
68
  }
61
69
  case 'name':
@@ -0,0 +1,3 @@
1
+ import type { AssetId } from '@shapeshiftoss/caip';
2
+ import type { EncodedRelatedAssetIndex } from './types.js';
3
+ export declare const decodeRelatedAssetIndex: (encodedRelatedAssetIndex: EncodedRelatedAssetIndex, sortedAssetIds: AssetId[]) => Record<AssetId, AssetId[]>;
@@ -0,0 +1,4 @@
1
+ import type { AssetId } from '@shapeshiftoss/caip';
2
+ import type { AssetsById } from '@shapeshiftoss/types';
3
+ import type { EncodedAssetData } from './types.js';
4
+ export declare const encodeAssetData: (sortedAssetIds: AssetId[], assetsById: AssetsById) => EncodedAssetData;
@@ -1,5 +1,5 @@
1
- import { assertUnreachable } from '../assertUnreachable';
2
- import { FIELDS } from './constants';
1
+ import { assertUnreachable } from '../assertUnreachable.js';
2
+ import { FIELDS } from './constants.js';
3
3
  const encodeAssetIds = (sortedAssetIds) => {
4
4
  const assetIdPrefixes = [];
5
5
  const encodedAssetIds = [];
@@ -0,0 +1,3 @@
1
+ import type { AssetId } from '@shapeshiftoss/caip';
2
+ import type { EncodedRelatedAssetIndex } from './types.js';
3
+ export declare const encodeRelatedAssetIndex: (relatedAssetIndex: Record<AssetId, AssetId[]>, sortedAssetIds: AssetId[]) => EncodedRelatedAssetIndex;
@@ -0,0 +1,3 @@
1
+ import type { ChainId } from '@shapeshiftoss/caip';
2
+ import type { Asset } from '@shapeshiftoss/types';
3
+ export declare const getBaseAsset: (chainId: ChainId) => Readonly<Asset>;
@@ -1,6 +1,6 @@
1
1
  import { KnownChainIds } from '@shapeshiftoss/types';
2
- import { assertUnreachable } from '../assertUnreachable';
3
- import { arbitrum, arbitrumNova, atom, avax, base, bitcoin, bitcoincash, bnbsmartchain, dogecoin, ethereum, gnosis, litecoin, mayachain, optimism, polygon, solana, thorchain, } from './baseAssets';
2
+ import { assertUnreachable } from '../assertUnreachable.js';
3
+ import { arbitrum, arbitrumNova, atom, avax, base, bitcoin, bitcoincash, bnbsmartchain, dogecoin, ethereum, gnosis, litecoin, mayachain, optimism, polygon, solana, thorchain, } from './baseAssets.js';
4
4
  export const getBaseAsset = (chainId) => {
5
5
  const knownChainId = chainId;
6
6
  switch (knownChainId) {
@@ -0,0 +1,7 @@
1
+ export * from './encodeAssetData.js';
2
+ export * from './decodeAssetData.js';
3
+ export * from './baseAssets.js';
4
+ export * from './getBaseAsset.js';
5
+ export * from './encodeRelatedAssetIndex.js';
6
+ export * from './decodeRelatedAssetIndex.js';
7
+ export * from './types.js';
@@ -0,0 +1,7 @@
1
+ export * from './encodeAssetData.js';
2
+ export * from './decodeAssetData.js';
3
+ export * from './baseAssets.js';
4
+ export * from './getBaseAsset.js';
5
+ export * from './encodeRelatedAssetIndex.js';
6
+ export * from './decodeRelatedAssetIndex.js';
7
+ export * from './types.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { decodeRelatedAssetIndex } from './decodeRelatedAssetIndex';
3
- import { encodeRelatedAssetIndex } from './encodeRelatedAssetIndex';
2
+ import { decodeRelatedAssetIndex } from './decodeRelatedAssetIndex.js';
3
+ import { encodeRelatedAssetIndex } from './encodeRelatedAssetIndex.js';
4
4
  // Order of these is deliberately shuffled to test sorting is preserved
5
5
  const mockSortedAssetIds = [
6
6
  'eip155:1/erc20:0xeeecd285f60e802ecb6d8d8d37790c887f9a4b33',
@@ -0,0 +1,28 @@
1
+ import type { FIELDS } from './constants.js';
2
+ export type Field = (typeof FIELDS)[number];
3
+ export type FieldToType = {
4
+ assetIdx: number;
5
+ name: string;
6
+ precision: number;
7
+ color: string;
8
+ icon: string[];
9
+ symbol: string;
10
+ relatedAssetKey: number | null;
11
+ isPool: 0 | 1;
12
+ };
13
+ export type EncodedAsset = [
14
+ FieldToType['assetIdx'],
15
+ FieldToType['name'],
16
+ FieldToType['precision'],
17
+ FieldToType['color'],
18
+ FieldToType['icon'],
19
+ FieldToType['symbol'],
20
+ FieldToType['relatedAssetKey'],
21
+ FieldToType['isPool']
22
+ ];
23
+ export type EncodedAssetData = {
24
+ assetIdPrefixes: string[];
25
+ encodedAssetIds: string[];
26
+ encodedAssets: EncodedAsset[];
27
+ };
28
+ export type EncodedRelatedAssetIndex = Record<number, number[]>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import BigNumber from 'bignumber.js';
2
+ import type { BN } from '../bignumber/bignumber.js';
3
+ export declare const fromBaseUnit: (value: BigNumber.Value, precision: number, displayDecimals?: number) => string;
4
+ export declare const toBaseUnit: (amount: BigNumber.Value | undefined, precision: number, roundingMode?: BigNumber.RoundingMode) => string;
5
+ export declare const firstNonZeroDecimal: (number: BN) => string | undefined;
@@ -1,5 +1,5 @@
1
1
  import BigNumber from 'bignumber.js';
2
- import { bn, bnOrZero } from '../bignumber/bignumber';
2
+ import { bn, bnOrZero } from '../bignumber/bignumber.js';
3
3
  // Converts from base unit to a precision/ish number
4
4
  // - If no displayDecimals are provided, it will use the full precision of the number being converted
5
5
  // - If displayDecimals are provided, it will use that precision, to return e.g a human, precision, or number stripped to any arbitrary decimal places
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { fromBaseUnit } from './baseUnits';
2
+ import { fromBaseUnit } from './baseUnits.js';
3
3
  describe('@/lib/math', () => {
4
4
  describe('fromBaseUnit', () => {
5
5
  it('should correctly convert and round down with given displayDecimals', () => {
@@ -0,0 +1,23 @@
1
+ import type { BigNumber } from './bignumber/bignumber.js';
2
+ export declare const convertBasisPointsToDecimalPercentage: (basisPoints: BigNumber.Value) => BigNumber;
3
+ export declare const convertDecimalPercentageToBasisPoints: (decimalPercentage: BigNumber.Value) => BigNumber;
4
+ export declare const convertBasisPointsToPercentage: (basisPoints: BigNumber.Value) => BigNumber;
5
+ export declare const convertPercentageToBasisPoints: (percentage: BigNumber.Value) => BigNumber;
6
+ /**
7
+ * Subtracts basis point amount from a given value.
8
+ *
9
+ * @param value The value to subtract basis points from.
10
+ * @param basisPoints The number of basis points to subtract.
11
+ * @param roundingMode
12
+ * @returns The new number that is the input value minus the basis points of the value.
13
+ */
14
+ export declare const subtractBasisPointAmount: (value: string, basisPoints: BigNumber.Value, roundingMode?: BigNumber.RoundingMode) => string;
15
+ /**
16
+ * Adds basis point amount from a given value.
17
+ *
18
+ * @param value The value to subtract basis points from.
19
+ * @param basisPoints The number of basis points to subtract.
20
+ * @param roundingMode
21
+ * @returns The new number that is the input value minus the basis points of the value.
22
+ */
23
+ export declare const addBasisPointAmount: (value: string, basisPoints: BigNumber.Value, roundingMode?: BigNumber.RoundingMode) => string;
@@ -1,4 +1,4 @@
1
- import { bn, bnOrZero } from './bignumber/bignumber';
1
+ import { bn, bnOrZero } from './bignumber/bignumber.js';
2
2
  export const convertBasisPointsToDecimalPercentage = (basisPoints) => bnOrZero(basisPoints).div(10000);
3
3
  export const convertDecimalPercentageToBasisPoints = (decimalPercentage) => bnOrZero(decimalPercentage).times(10000);
4
4
  export const convertBasisPointsToPercentage = (basisPoints) => bnOrZero(basisPoints).div(100);
@@ -0,0 +1,11 @@
1
+ import BigNumber from 'bignumber.js';
2
+ export { default as BigNumber } from 'bignumber.js';
3
+ export type BN = BigNumber;
4
+ export declare const bn: (n: BigNumber.Value, base?: number) => BN;
5
+ export declare const bnOrZero: (n: BigNumber.Value | null | undefined) => BN;
6
+ export declare const positiveOrZero: (n: BigNumber.Value | null | undefined) => BN;
7
+ export declare const convertPrecision: ({ value, inputExponent, outputExponent, }: {
8
+ value: BigNumber.Value;
9
+ inputExponent?: number | undefined;
10
+ outputExponent?: number | undefined;
11
+ }) => BigNumber;
@@ -1,5 +1,5 @@
1
1
  import BigNumber from 'bignumber.js';
2
- export * from 'bignumber.js';
2
+ export { default as BigNumber } from 'bignumber.js';
3
3
  export const bn = (n, base = 10) => new BigNumber(n, base);
4
4
  export const bnOrZero = (n) => {
5
5
  const value = bn(n || 0);
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { BigNumber, bn, bnOrZero, convertPrecision } from './bignumber';
2
+ import { BigNumber, bn, bnOrZero, convertPrecision } from './bignumber.js';
3
3
  describe('bignumber', () => {
4
4
  describe('bnOrZero', () => {
5
5
  it('returns an instance of bignumber', () => {
@@ -0,0 +1,3 @@
1
+ import type { AssetId, ChainId } from '@shapeshiftoss/caip';
2
+ import type { Asset } from '@shapeshiftoss/types';
3
+ export declare const chainIdToFeeAsset: (assetsById: Partial<Record<AssetId, Asset>>, chainId: ChainId) => Asset | undefined;
@@ -1,4 +1,4 @@
1
- import { chainIdToFeeAssetId } from './chainIdToFeeAssetId';
1
+ import { chainIdToFeeAssetId } from './chainIdToFeeAssetId.js';
2
2
  export const chainIdToFeeAsset = (assetsById, chainId) => {
3
3
  const assetId = chainIdToFeeAssetId(chainId);
4
4
  return assetsById[assetId];
@@ -0,0 +1,2 @@
1
+ import type { AssetId, ChainId } from '@shapeshiftoss/caip';
2
+ export declare const chainIdToFeeAssetId: (_chainId: ChainId) => AssetId;
@@ -1,6 +1,6 @@
1
1
  import { arbitrumAssetId, arbitrumNovaAssetId, avalancheAssetId, baseAssetId, bchAssetId, bscAssetId, btcAssetId, cosmosAssetId, dogeAssetId, ethAssetId, gnosisAssetId, ltcAssetId, mayachainAssetId, optimismAssetId, polygonAssetId, solAssetId, thorchainAssetId, } from '@shapeshiftoss/caip';
2
2
  import { KnownChainIds } from '@shapeshiftoss/types';
3
- import { assertUnreachable } from './assertUnreachable';
3
+ import { assertUnreachable } from './assertUnreachable.js';
4
4
  export const chainIdToFeeAssetId = (_chainId) => {
5
5
  const chainId = _chainId;
6
6
  switch (chainId) {
@@ -0,0 +1,9 @@
1
+ export declare const createThrottle: ({ capacity, costPerReq, drainPerInterval, intervalMs, }: {
2
+ capacity: number;
3
+ costPerReq: number;
4
+ drainPerInterval: number;
5
+ intervalMs: number;
6
+ }) => {
7
+ throttle: () => Promise<void>;
8
+ clear: () => void;
9
+ };
@@ -0,0 +1,3 @@
1
+ import type { AssetNamespace } from '@shapeshiftoss/caip';
2
+ import { KnownChainIds } from '@shapeshiftoss/types';
3
+ export declare const getAssetNamespaceFromChainId: (chainId: KnownChainIds) => AssetNamespace;
@@ -1,6 +1,6 @@
1
1
  import { ASSET_NAMESPACE } from '@shapeshiftoss/caip';
2
2
  import { KnownChainIds } from '@shapeshiftoss/types';
3
- import { assertUnreachable } from './assertUnreachable';
3
+ import { assertUnreachable } from './assertUnreachable.js';
4
4
  export const getAssetNamespaceFromChainId = (chainId) => {
5
5
  switch (chainId) {
6
6
  case KnownChainIds.BnbSmartChainMainnet:
@@ -17,7 +17,6 @@ export const getAssetNamespaceFromChainId = (chainId) => {
17
17
  case KnownChainIds.BaseMainnet:
18
18
  return ASSET_NAMESPACE.erc20;
19
19
  case KnownChainIds.CosmosMainnet:
20
- return ASSET_NAMESPACE.ibc;
21
20
  case KnownChainIds.BitcoinMainnet:
22
21
  case KnownChainIds.BitcoinCashMainnet:
23
22
  case KnownChainIds.DogecoinMainnet:
@@ -0,0 +1,2 @@
1
+ import { KnownChainIds } from '@shapeshiftoss/types';
2
+ export declare const getChainShortName: (chainId: KnownChainIds) => "AVA" | "OP" | "ETH" | "POLY" | "GNO" | "BNB" | "ARB" | "ARB-Nova" | "BAS" | "BTC" | "BCH" | "COSM" | "THOR" | "MAYA" | "DOGE" | "LTC" | "SOL" | undefined;
@@ -1,5 +1,5 @@
1
1
  import { KnownChainIds } from '@shapeshiftoss/types';
2
- import { assertUnreachable } from './assertUnreachable';
2
+ import { assertUnreachable } from './assertUnreachable.js';
3
3
  export const getChainShortName = (chainId) => {
4
4
  switch (chainId) {
5
5
  case KnownChainIds.AvalancheMainnet:
@@ -0,0 +1,2 @@
1
+ import type { AssetReference, ChainNamespace, ChainReference } from '@shapeshiftoss/caip';
2
+ export declare const getNativeFeeAssetReference: (chainNamespace: ChainNamespace, chainReference: ChainReference) => AssetReference;
@@ -0,0 +1,6 @@
1
+ import { HistoryTimeframe } from '@shapeshiftoss/types';
2
+ import dayjs from 'dayjs';
3
+ export declare const getHistoryTimeframeBounds: (timeframe: HistoryTimeframe, end?: dayjs.Dayjs) => {
4
+ start: dayjs.Dayjs;
5
+ end: dayjs.Dayjs;
6
+ };
@@ -1,6 +1,6 @@
1
1
  import { HistoryTimeframe } from '@shapeshiftoss/types';
2
2
  import dayjs from 'dayjs';
3
- import { assertUnreachable } from './assertUnreachable';
3
+ import { assertUnreachable } from './assertUnreachable.js';
4
4
  export const getHistoryTimeframeBounds = (timeframe, end = dayjs().endOf('day')) => {
5
5
  let start = end; // Shut up typescript.
6
6
  switch (timeframe) {
@@ -0,0 +1,24 @@
1
+ import type { AssetId } from '@shapeshiftoss/caip';
2
+ export * from './makeAsset/makeAsset.js';
3
+ export * from './assertUnreachable.js';
4
+ export * from './sha256.js';
5
+ export * from './chainIdToFeeAsset.js';
6
+ export * from './chainIdToFeeAssetId.js';
7
+ export * from './utxo.js';
8
+ export * from './bignumber/bignumber.js';
9
+ export * from './basisPoints.js';
10
+ export * from './baseUnits/baseUnits.js';
11
+ export * from './promises.js';
12
+ export * from './treasury.js';
13
+ export * from './timeout.js';
14
+ export * from './createThrottle.js';
15
+ export * from './historyTimeframe.js';
16
+ export * from './getNativeFeeAssetReference.js';
17
+ export * from './assetData/index.js';
18
+ export * from './unfreeze.js';
19
+ export * from './getAssetNamespaceFromChainId.js';
20
+ export * from './getChainShortName.js';
21
+ export declare const isSome: <T>(option: T | null | undefined) => option is T;
22
+ export declare const isToken: (assetId: AssetId) => boolean;
23
+ export declare const isSplToken: (assetId: AssetId) => boolean;
24
+ export declare const contractAddressOrUndefined: (assetId: AssetId) => import("@shapeshiftoss/caip").AssetReference | undefined;
@@ -1,24 +1,24 @@
1
1
  import { ASSET_NAMESPACE, fromAssetId } from '@shapeshiftoss/caip';
2
2
  import { isNull, isUndefined } from 'lodash';
3
- export * from './makeAsset/makeAsset';
4
- export * from './assertUnreachable';
5
- export * from './sha256';
6
- export * from './chainIdToFeeAsset';
7
- export * from './chainIdToFeeAssetId';
8
- export * from './utxo';
9
- export * from './bignumber/bignumber';
10
- export * from './basisPoints';
11
- export * from './baseUnits/baseUnits';
12
- export * from './promises';
13
- export * from './treasury';
14
- export * from './timeout';
15
- export * from './createThrottle';
16
- export * from './historyTimeframe';
17
- export * from './getNativeFeeAssetReference';
18
- export * from './assetData';
19
- export * from './unfreeze';
20
- export * from './getAssetNamespaceFromChainId';
21
- export * from './getChainShortName';
3
+ export * from './makeAsset/makeAsset.js';
4
+ export * from './assertUnreachable.js';
5
+ export * from './sha256.js';
6
+ export * from './chainIdToFeeAsset.js';
7
+ export * from './chainIdToFeeAssetId.js';
8
+ export * from './utxo.js';
9
+ export * from './bignumber/bignumber.js';
10
+ export * from './basisPoints.js';
11
+ export * from './baseUnits/baseUnits.js';
12
+ export * from './promises.js';
13
+ export * from './treasury.js';
14
+ export * from './timeout.js';
15
+ export * from './createThrottle.js';
16
+ export * from './historyTimeframe.js';
17
+ export * from './getNativeFeeAssetReference.js';
18
+ export * from './assetData/index.js';
19
+ export * from './unfreeze.js';
20
+ export * from './getAssetNamespaceFromChainId.js';
21
+ export * from './getChainShortName.js';
22
22
  export const isSome = (option) => !isUndefined(option) && !isNull(option);
23
23
  export const isToken = (assetId) => {
24
24
  switch (fromAssetId(assetId).assetNamespace) {
@@ -0,0 +1,10 @@
1
+ import type { AssetId } from '@shapeshiftoss/caip';
2
+ import type { Asset } from '@shapeshiftoss/types';
3
+ export type MinimalAsset = Partial<Asset> & Pick<Asset, 'assetId' | 'symbol' | 'name' | 'precision'>;
4
+ /**
5
+ * utility to create an asset from minimal asset data from external sources at runtime
6
+ * e.g. zapper/zerion/etherscan
7
+ * required fields are assetId, symbol, name, precision
8
+ * the rest can be inferred from existing data
9
+ */
10
+ export declare const makeAsset: (assetsById: Partial<Record<AssetId, Asset>>, minimalAsset: MinimalAsset) => Asset;
@@ -1,6 +1,6 @@
1
1
  import { fromAssetId } from '@shapeshiftoss/caip';
2
- import { chainIdToFeeAsset } from '../chainIdToFeeAsset';
3
- import { sha256 } from '../sha256';
2
+ import { chainIdToFeeAsset } from '../chainIdToFeeAsset.js';
3
+ import { sha256 } from '../sha256.js';
4
4
  /**
5
5
  * utility to create an asset from minimal asset data from external sources at runtime
6
6
  * e.g. zapper/zerion/etherscan
@@ -35,5 +35,7 @@ export const makeAsset = (assetsById, minimalAsset) => {
35
35
  color,
36
36
  icon,
37
37
  relatedAssetKey: null,
38
+ isPrimary: true,
39
+ isChainSpecific: true,
38
40
  });
39
41
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,6 @@
1
1
  import { ASSET_NAMESPACE, ethAssetId, ethChainId, toAssetId } from '@shapeshiftoss/caip';
2
2
  import { describe, expect, it } from 'vitest';
3
- import { makeAsset } from './makeAsset';
3
+ import { makeAsset } from './makeAsset.js';
4
4
  const ETH = {
5
5
  assetId: ethAssetId,
6
6
  chainId: ethChainId,
@@ -0,0 +1,4 @@
1
+ import type { Result } from '@sniptt/monads';
2
+ export declare const isFulfilled: <T>(promise: PromiseSettledResult<T>) => promise is PromiseFulfilledResult<T>;
3
+ export declare const isRejected: <T>(promise: PromiseSettledResult<T>) => promise is PromiseRejectedResult;
4
+ export declare const isResolvedErr: <U, V, T extends Result<U, V>>(promise: PromiseSettledResult<T>) => promise is PromiseRejectedResult;
@@ -0,0 +1 @@
1
+ export declare const sha256: (input: string) => string;
@@ -0,0 +1,7 @@
1
+ import type { Result } from '@sniptt/monads';
2
+ export declare const timeout: <SuccessType, FallbackType>(promise: Promise<SuccessType>, timeoutMs: number, fallbackValue: FallbackType) => Promise<SuccessType | FallbackType>;
3
+ export declare const timeoutMonadic: <Left, Right>(promise: Promise<Result<Left, Right>>, timeoutMs: number, timeoutRight: Right) => Promise<Result<Left, Right>>;
4
+ export declare const timeoutMonadicWithOriginal: <Ok, ErrType>(promise: Promise<Result<Ok, ErrType>>, timeoutMs: number, timeoutErr: ErrType) => {
5
+ timed: Promise<Result<Ok, ErrType>>;
6
+ original: Promise<Result<Ok, ErrType>>;
7
+ };
@@ -15,3 +15,14 @@ export const timeoutMonadic = (promise, timeoutMs, timeoutRight) => {
15
15
  }, timeoutMs)),
16
16
  ]);
17
17
  };
18
+ export const timeoutMonadicWithOriginal = (promise, timeoutMs, timeoutErr) => {
19
+ return {
20
+ timed: Promise.race([
21
+ promise,
22
+ new Promise(resolve => setTimeout(() => {
23
+ resolve(Err(timeoutErr));
24
+ }, timeoutMs)),
25
+ ]),
26
+ original: promise,
27
+ };
28
+ };
@@ -0,0 +1,15 @@
1
+ import type { ChainId } from '@shapeshiftoss/caip';
2
+ import { KnownChainIds } from '@shapeshiftoss/types';
3
+ export declare const treasuryChainIds: readonly [KnownChainIds.EthereumMainnet, KnownChainIds.AvalancheMainnet, KnownChainIds.OptimismMainnet, KnownChainIds.BnbSmartChainMainnet, KnownChainIds.PolygonMainnet, KnownChainIds.GnosisMainnet, KnownChainIds.ArbitrumMainnet, KnownChainIds.BaseMainnet, KnownChainIds.SolanaMainnet, KnownChainIds.BitcoinMainnet];
4
+ export type TreasuryChainId = (typeof treasuryChainIds)[number];
5
+ export declare const isTreasuryChainId: (chainId: ChainId) => chainId is KnownChainIds.EthereumMainnet | KnownChainIds.AvalancheMainnet | KnownChainIds.OptimismMainnet | KnownChainIds.BnbSmartChainMainnet | KnownChainIds.PolygonMainnet | KnownChainIds.GnosisMainnet | KnownChainIds.ArbitrumMainnet | KnownChainIds.BaseMainnet | KnownChainIds.BitcoinMainnet | KnownChainIds.SolanaMainnet;
6
+ export declare const DAO_TREASURY_ETHEREUM_MAINNET = "0x90a48d5cf7343b08da12e067680b4c6dbfe551be";
7
+ export declare const DAO_TREASURY_OPTIMISM = "0x6268d07327f4fb7380732dc6d63d95F88c0E083b";
8
+ export declare const DAO_TREASURY_AVALANCHE = "0x74d63F31C2335b5b3BA7ad2812357672b2624cEd";
9
+ export declare const DAO_TREASURY_POLYGON = "0xB5F944600785724e31Edb90F9DFa16dBF01Af000";
10
+ export declare const DAO_TREASURY_GNOSIS = "0xb0E3175341794D1dc8E5F02a02F9D26989EbedB3";
11
+ export declare const DAO_TREASURY_BSC = "0x8b92b1698b57bEDF2142297e9397875ADBb2297E";
12
+ export declare const DAO_TREASURY_ARBITRUM = "0x38276553F8fbf2A027D901F8be45f00373d8Dd48";
13
+ export declare const DAO_TREASURY_BASE = "0x9c9aA90363630d4ab1D9dbF416cc3BBC8d3Ed502";
14
+ export declare const DAO_TREASURY_SOLANA = "Bh7R3MeJ98D7Ersxh7TgVQVQUSmDMqwrFVHH9DLfb4u3";
15
+ export declare const DAO_TREASURY_BITCOIN = "bc1qr2whxtd0gvqnctcxlynwejp6fvntv0mtxkv0dlv02vyale8h69ysm6l32n";
@@ -25,5 +25,5 @@ export const DAO_TREASURY_GNOSIS = '0xb0E3175341794D1dc8E5F02a02F9D26989EbedB3';
25
25
  export const DAO_TREASURY_BSC = '0x8b92b1698b57bEDF2142297e9397875ADBb2297E';
26
26
  export const DAO_TREASURY_ARBITRUM = '0x38276553F8fbf2A027D901F8be45f00373d8Dd48';
27
27
  export const DAO_TREASURY_BASE = '0x9c9aA90363630d4ab1D9dbF416cc3BBC8d3Ed502';
28
- export const DAO_TREASURY_SOLANA = 'C7RTJbss7R1r7j8NUNYbasUXfbPJR99PMhqznvCiU43N';
28
+ export const DAO_TREASURY_SOLANA = 'Bh7R3MeJ98D7Ersxh7TgVQVQUSmDMqwrFVHH9DLfb4u3';
29
29
  export const DAO_TREASURY_BITCOIN = 'bc1qr2whxtd0gvqnctcxlynwejp6fvntv0mtxkv0dlv02vyale8h69ysm6l32n';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Creates a shallow clone to allow mutation of a readonly object
3
+ */
4
+ export declare const unfreeze: <T>(obj: Readonly<T>) => T;
@@ -0,0 +1,2 @@
1
+ import type { ChainId } from '@shapeshiftoss/caip';
2
+ export declare const isUtxoChainId: (chainId: ChainId) => boolean;