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

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.
@@ -93,11 +93,12 @@ export class AssetValue extends BigIntArithmetics {
93
93
  const tokenInfo = staticTokensMap.get(assetString.toUpperCase() as TokenNames);
94
94
 
95
95
  if (isSynthetic) return createSyntheticAssetValue(assetString, value);
96
- if (!tokenInfo) {
97
- console.error(
98
- `Asset ${assetString} is not loaded. Use AssetValue.loadStaticAssets() to load it`,
99
- );
100
- }
96
+ // TODO: write logger that will only run in dev mode with some flag
97
+ // if (!tokenInfo) {
98
+ // console.error(
99
+ // `Asset ${assetString} is not loaded. Use AssetValue.loadStaticAssets() to load it`,
100
+ // );
101
+ // }
101
102
 
102
103
  const { tax, decimal, identifier } = tokenInfo || {
103
104
  decimal: BaseDecimal[chain],
@@ -116,11 +117,12 @@ export class AssetValue extends BigIntArithmetics {
116
117
  const tokenInfo = staticTokensMap.get(assetString);
117
118
 
118
119
  if (isSynthetic) return createSyntheticAssetValue(assetString, value);
119
- if (!tokenInfo) {
120
- console.error(
121
- `Asset ${assetString} is not loaded. - Loading with base Chain. Use AssetValue.loadStaticAssets() to load it`,
122
- );
123
- }
120
+ // TODO: write logger that will only run in dev mode with some flag
121
+ // if (!tokenInfo) {
122
+ // console.error(
123
+ // `Asset ${assetString} is not loaded. - Loading with base Chain. Use AssetValue.loadStaticAssets() to load it`,
124
+ // );
125
+ // }
124
126
 
125
127
  const { tax, decimal, identifier } = tokenInfo || {
126
128
  decimal: BaseDecimal[chain],
@@ -202,12 +204,17 @@ async function createAssetValue(identifier: string, value: NumberPrimitives = 0)
202
204
  }
203
205
 
204
206
  function createSyntheticAssetValue(identifier: string, value: NumberPrimitives = 0) {
205
- const [symbol, ticker] = identifier.split('/');
207
+ const [synthChain, symbol] =
208
+ identifier.split('.')[0].toUpperCase() === Chain.THORChain
209
+ ? identifier.split('.').slice(1)!.join().split('/')
210
+ : identifier.split('/');
211
+
212
+ if (!synthChain || !symbol) throw new Error('Invalid asset identifier');
206
213
 
207
214
  return new AssetValue({
208
215
  decimal: 8,
209
216
  value: safeValue(value, 8),
210
- identifier: `${Chain.THORChain}.${symbol}/${ticker}`,
217
+ identifier: `${Chain.THORChain}.${synthChain}/${symbol}`,
211
218
  });
212
219
  }
213
220
 
@@ -219,7 +226,13 @@ function safeValue(value: NumberPrimitives, decimal: number) {
219
226
 
220
227
  function getAssetInfo(identifier: string) {
221
228
  const isSynthetic = identifier.slice(0, 14).includes('/');
222
- const [synthChain, synthSymbol] = identifier.split('.').pop()!.split('/');
229
+ const [synthChain, synthSymbol] =
230
+ identifier.split('.')[0].toUpperCase() === Chain.THORChain
231
+ ? identifier.split('.').slice(1)!.join().split('/')
232
+ : identifier.split('/');
233
+
234
+ if (isSynthetic && (!synthChain || !synthSymbol)) throw new Error('Invalid asset identifier');
235
+
223
236
  const adjustedIdentifier =
224
237
  identifier.includes('.') && !isSynthetic ? identifier : `${Chain.THORChain}.${synthSymbol}`;
225
238