@swapkit/helpers 1.0.0-rc.54 → 1.0.0-rc.55

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.
@@ -89,17 +89,20 @@ export class AssetValue extends BigIntArithmetics {
89
89
  }
90
90
 
91
91
  static fromStringSync(assetString: string, value: NumberPrimitives = 0) {
92
- const { isSynthetic } = getAssetInfo(assetString);
92
+ const { chain, isSynthetic } = getAssetInfo(assetString);
93
93
  const tokenInfo = staticTokensMap.get(assetString.toUpperCase() as TokenNames);
94
94
 
95
+ if (isSynthetic) return createSyntheticAssetValue(assetString, value);
95
96
  if (!tokenInfo) {
96
97
  console.error(
97
98
  `Asset ${assetString} is not loaded. Use AssetValue.loadStaticAssets() to load it`,
98
99
  );
99
- return undefined;
100
100
  }
101
101
 
102
- const { tax, decimal, identifier } = tokenInfo;
102
+ const { tax, decimal, identifier } = tokenInfo || {
103
+ decimal: BaseDecimal[chain],
104
+ identifier: assetString,
105
+ };
103
106
  return new AssetValue({
104
107
  tax,
105
108
  value: safeValue(value, decimal),
@@ -109,16 +112,20 @@ export class AssetValue extends BigIntArithmetics {
109
112
  }
110
113
 
111
114
  static fromIdentifierSync(assetString: TokenNames, value: NumberPrimitives = 0) {
115
+ const { chain, isSynthetic } = getAssetInfo(assetString);
112
116
  const tokenInfo = staticTokensMap.get(assetString);
113
117
 
118
+ if (isSynthetic) return createSyntheticAssetValue(assetString, value);
114
119
  if (!tokenInfo) {
115
120
  console.error(
116
- `Asset ${assetString} is not loaded. Use AssetValue.loadStaticAssets() to load it`,
121
+ `Asset ${assetString} is not loaded. - Loading with base Chain. Use AssetValue.loadStaticAssets() to load it`,
117
122
  );
118
- return undefined;
119
123
  }
120
124
 
121
- const { tax, decimal, identifier } = tokenInfo;
125
+ const { tax, decimal, identifier } = tokenInfo || {
126
+ decimal: BaseDecimal[chain],
127
+ identifier: assetString,
128
+ };
122
129
  return new AssetValue({ tax, decimal, identifier, value: safeValue(value, decimal) });
123
130
  }
124
131
 
@@ -194,6 +201,16 @@ async function createAssetValue(identifier: string, value: NumberPrimitives = 0)
194
201
  return new AssetValue({ decimal, value: safeValue(value, decimal), identifier });
195
202
  }
196
203
 
204
+ function createSyntheticAssetValue(identifier: string, value: NumberPrimitives = 0) {
205
+ const [symbol, ticker] = identifier.split('/');
206
+
207
+ return new AssetValue({
208
+ decimal: 8,
209
+ value: safeValue(value, 8),
210
+ identifier: `${Chain.THORChain}.${symbol}/${ticker}`,
211
+ });
212
+ }
213
+
197
214
  function safeValue(value: NumberPrimitives, decimal: number) {
198
215
  return typeof value === 'bigint'
199
216
  ? formatBigIntToSafeValue({ value, bigIntDecimal: decimal, decimal })