@pioneer-platform/helpers 4.0.4 → 4.0.6
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/__tests__/test-module.js +25 -8
- package/lib/modules/assetValue.d.ts +9 -9
- package/lib/modules/assetValue.js +254 -208
- package/lib/modules/bigIntArithmetics.d.ts +2 -6
- package/lib/modules/bigIntArithmetics.js +509 -210
- package/lib/modules/swapKitNumber.js +2 -1
- package/package.json +1 -1
- package/src/modules/assetValue.ts +273 -263
- package/src/modules/bigIntArithmetics.ts +520 -264
- package/src/modules/swapKitNumber.ts +3 -3
@@ -17,6 +17,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
18
18
|
exports.SwapKitNumber = void 0;
|
19
19
|
var bigIntArithmetics_1 = require("./bigIntArithmetics");
|
20
|
+
var DEFAULT_DECIMAL = 8;
|
20
21
|
var SwapKitNumber = /** @class */ (function (_super) {
|
21
22
|
__extends(SwapKitNumber, _super);
|
22
23
|
function SwapKitNumber() {
|
@@ -28,7 +29,7 @@ var SwapKitNumber = /** @class */ (function (_super) {
|
|
28
29
|
SwapKitNumber.fromBigInt = function (value, decimal) {
|
29
30
|
return new SwapKitNumber({
|
30
31
|
decimal: decimal,
|
31
|
-
value: (0, bigIntArithmetics_1.formatBigIntToSafeValue)({ value: value, bigIntDecimal: decimal, decimal: decimal }),
|
32
|
+
value: (0, bigIntArithmetics_1.formatBigIntToSafeValue)({ value: value, bigIntDecimal: (0, bigIntArithmetics_1.toMultiplier)(decimal || DEFAULT_DECIMAL), decimal: decimal }),
|
32
33
|
});
|
33
34
|
};
|
34
35
|
return SwapKitNumber;
|
package/package.json
CHANGED
@@ -11,7 +11,6 @@ import type {
|
|
11
11
|
TraderjoeList,
|
12
12
|
UniswapList,
|
13
13
|
WoofiList,
|
14
|
-
//@ts-ignore
|
15
14
|
} from '@coinmasters/tokens';
|
16
15
|
import { BaseDecimal, Chain } from '@coinmasters/types';
|
17
16
|
|
@@ -23,348 +22,359 @@ import type { NumberPrimitives } from './bigIntArithmetics';
|
|
23
22
|
import { BigIntArithmetics, formatBigIntToSafeValue } from './bigIntArithmetics';
|
24
23
|
import type { SwapKitValueType } from './swapKitNumber';
|
25
24
|
|
25
|
+
const TAG = " | assetValue | ";
|
26
|
+
|
26
27
|
type TokenTax = { buy: number; sell: number };
|
27
28
|
|
28
29
|
function safeValue(value: NumberPrimitives, decimal: number) {
|
30
|
+
let tag = TAG + " | safeValue | ";
|
29
31
|
try {
|
30
32
|
if (typeof value === 'bigint') {
|
31
|
-
return
|
33
|
+
return value;
|
34
|
+
} else if (typeof value === 'number') {
|
35
|
+
return BigInt(Math.round(value * Math.pow(10, decimal)));
|
36
|
+
} else if (typeof value === 'string') {
|
37
|
+
return BigInt(Math.round(parseFloat(value) * Math.pow(10, decimal)));
|
32
38
|
}
|
33
|
-
return
|
39
|
+
return BigInt(0);
|
34
40
|
} catch (error) {
|
35
|
-
console.error('Error in safeValue:', error);
|
36
|
-
return 0;
|
41
|
+
console.error(tag + 'Error in safeValue:', error);
|
42
|
+
return BigInt(0);
|
37
43
|
}
|
38
44
|
}
|
39
45
|
|
40
|
-
// const safeValue = (value: NumberPrimitives, decimal: number) =>
|
41
|
-
// typeof value === 'bigint'
|
42
|
-
// ? formatBigIntToSafeValue({ value, bigIntDecimal: decimal, decimal })
|
43
|
-
// : value;
|
44
|
-
|
45
46
|
type AssetValueParams = { decimal: number; value: SwapKitValueType; tax?: TokenTax } & (
|
46
|
-
|
47
|
-
|
48
|
-
);
|
47
|
+
| { chain: Chain; symbol: string }
|
48
|
+
| { identifier: string }
|
49
|
+
);
|
49
50
|
|
50
51
|
type TCTokenNames = (typeof ThorchainList)['tokens'][number]['identifier'];
|
51
52
|
|
52
53
|
type TokenNames =
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
54
|
+
| TCTokenNames
|
55
|
+
| (typeof CoinGeckoList)['tokens'][number]['identifier']
|
56
|
+
| (typeof MayaList)['tokens'][number]['identifier']
|
57
|
+
| (typeof PancakeswapETHList)['tokens'][number]['identifier']
|
58
|
+
| (typeof PancakeswapList)['tokens'][number]['identifier']
|
59
|
+
| (typeof PangolinList)['tokens'][number]['identifier']
|
60
|
+
| (typeof StargateARBList)['tokens'][number]['identifier']
|
61
|
+
| (typeof SushiswapList)['tokens'][number]['identifier']
|
62
|
+
| (typeof TraderjoeList)['tokens'][number]['identifier']
|
63
|
+
| (typeof WoofiList)['tokens'][number]['identifier']
|
64
|
+
| (typeof UniswapList)['tokens'][number]['identifier']
|
65
|
+
| (typeof PioneerList)['tokens'][number]['identifier'];
|
65
66
|
|
66
67
|
let staticTokensMap:
|
67
|
-
|
68
|
-
|
68
|
+
| Map<TokenNames, { tax?: TokenTax; decimal: number; identifier: string }>
|
69
|
+
| undefined;
|
69
70
|
|
70
71
|
const getStaticToken = (identifier: TokenNames) => {
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
let tag = TAG + " | getStaticToken | ";
|
73
|
+
try {
|
74
|
+
if (!staticTokensMap) {
|
75
|
+
throw new Error('Static assets not loaded, call await AssetValue.loadStaticAssets() first');
|
76
|
+
}
|
77
|
+
const tokenInfo = staticTokensMap.get(identifier.toUpperCase() as TokenNames);
|
77
78
|
|
78
|
-
|
79
|
+
return tokenInfo || { decimal: BaseDecimal.THOR, identifier: '' };
|
80
|
+
} catch (error) {
|
81
|
+
console.error(tag + 'Error in getStaticToken:', error);
|
82
|
+
}
|
79
83
|
};
|
80
84
|
|
81
85
|
const createAssetValue = async (assetString: string, value: NumberPrimitives = 0) => {
|
82
|
-
|
86
|
+
let tag = TAG + " | createAssetValue | ";
|
87
|
+
try {
|
88
|
+
validateIdentifier(assetString);
|
89
|
+
console.log(tag + 'assetString', assetString);
|
83
90
|
|
84
|
-
|
85
|
-
|
91
|
+
//@ts-ignore
|
92
|
+
const decimal = await getDecimal(getAssetInfo(assetString));
|
93
|
+
console.log(tag + 'decimal', decimal);
|
86
94
|
|
87
|
-
|
95
|
+
const parsedValue = safeValue(value, decimal);
|
96
|
+
console.log(tag + 'parsedValue', parsedValue);
|
97
|
+
|
98
|
+
// @ts-ignore
|
99
|
+
return new AssetValue({ decimal, value: parsedValue, identifier: assetString });
|
100
|
+
} catch (error) {
|
101
|
+
console.error(tag + 'Error in createAssetValue:', error);
|
102
|
+
}
|
88
103
|
};
|
89
104
|
|
90
105
|
export class AssetValue extends BigIntArithmetics {
|
91
106
|
address?: string;
|
92
107
|
caip?: string;
|
108
|
+
//@ts-ignore
|
93
109
|
chain: Chain;
|
94
110
|
isGasAsset = false;
|
95
111
|
isSynthetic = false;
|
112
|
+
//@ts-ignore
|
96
113
|
symbol: string;
|
97
114
|
tax?: TokenTax;
|
115
|
+
//@ts-ignore
|
98
116
|
ticker: string;
|
99
117
|
type: ReturnType<typeof getAssetType>;
|
100
118
|
|
101
|
-
|
119
|
+
//@ts-ignore
|
102
120
|
constructor(params: AssetValueParams) {
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
121
|
+
let tag = TAG + " | constructor | ";
|
122
|
+
try {
|
123
|
+
const identifier =
|
124
|
+
'identifier' in params ? params.identifier : `${params.chain}.${params.symbol}`;
|
125
|
+
|
126
|
+
let value;
|
127
|
+
if (params.value instanceof BigIntArithmetics) {
|
128
|
+
value = params.value;
|
129
|
+
} else {
|
130
|
+
value = { decimal: params.decimal, value: safeValue(params.value, params.decimal) };
|
131
|
+
}
|
132
|
+
// @ts-ignore
|
133
|
+
super(value);
|
134
|
+
|
135
|
+
const assetInfo:any = getAssetInfo(identifier);
|
136
|
+
this.type = getAssetType(assetInfo);
|
137
|
+
this.chain = assetInfo.chain;
|
138
|
+
this.ticker = assetInfo.ticker;
|
139
|
+
this.symbol = assetInfo.symbol;
|
140
|
+
this.address = assetInfo.address;
|
141
|
+
this.isSynthetic = assetInfo.isSynthetic;
|
142
|
+
// @ts-ignore
|
143
|
+
this.isGasAsset = assetInfo.isGasAsset;
|
144
|
+
this.tax = params.tax;
|
145
|
+
} catch (error) {
|
146
|
+
console.error(tag + 'Error in constructor:', error);
|
112
147
|
}
|
113
|
-
// console.log('value: ', value);
|
114
|
-
super(value);
|
115
|
-
|
116
|
-
// super(
|
117
|
-
// params.value instanceof BigIntArithmetics
|
118
|
-
// ? params.value
|
119
|
-
// : { decimal: params.decimal, value: params.value },
|
120
|
-
// );
|
121
|
-
|
122
|
-
const assetInfo = getAssetInfo(identifier);
|
123
|
-
// console.log('assetInfo: ', assetInfo);
|
124
|
-
this.type = getAssetType(assetInfo);
|
125
|
-
this.chain = assetInfo.chain;
|
126
|
-
this.ticker = assetInfo.ticker;
|
127
|
-
this.symbol = assetInfo.symbol;
|
128
|
-
this.address = assetInfo.address;
|
129
|
-
this.isSynthetic = assetInfo.isSynthetic;
|
130
|
-
// @ts-ignore
|
131
|
-
this.isGasAsset = assetInfo.isGasAsset;
|
132
|
-
|
133
|
-
this.tax = params.tax;
|
134
148
|
}
|
135
149
|
|
136
150
|
toString(short = false) {
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
151
|
+
let tag = TAG + " | toString | ";
|
152
|
+
try {
|
153
|
+
const shortFormat = this.isSynthetic ? this.symbol : this.ticker;
|
154
|
+
|
155
|
+
return short
|
156
|
+
? shortFormat
|
157
|
+
: `${this.chain}.${this.symbol}`;
|
158
|
+
} catch (error) {
|
159
|
+
console.error(tag + 'Error in toString:', error);
|
160
|
+
}
|
144
161
|
}
|
145
162
|
|
146
163
|
toUrl() {
|
147
|
-
|
164
|
+
let tag = TAG + " | toUrl | ";
|
165
|
+
try {
|
166
|
+
return this.isSynthetic ? `${this.chain}.${this.symbol.replace('/', '.')}` : this.toString();
|
167
|
+
} catch (error) {
|
168
|
+
console.error(tag + 'Error in toUrl:', error);
|
169
|
+
}
|
148
170
|
}
|
149
171
|
|
150
172
|
eq({ chain, symbol }: { chain: Chain; symbol: string }) {
|
151
|
-
|
173
|
+
let tag = TAG + " | eq | ";
|
174
|
+
try {
|
175
|
+
return this.chain === chain && this.symbol === symbol;
|
176
|
+
} catch (error) {
|
177
|
+
console.error(tag + 'Error in eq:', error);
|
178
|
+
}
|
152
179
|
}
|
153
180
|
|
154
181
|
static async fromString(assetString: string, value: NumberPrimitives = 0) {
|
155
|
-
|
182
|
+
let tag = TAG + " | fromString | ";
|
183
|
+
try {
|
184
|
+
return createAssetValue(assetString, value);
|
185
|
+
} catch (error) {
|
186
|
+
console.error(tag + 'Error in fromString:', error);
|
187
|
+
}
|
156
188
|
}
|
157
189
|
|
158
|
-
// static fromStringSync(assetString: string, value: NumberPrimitives = 0) {
|
159
|
-
// const { isSynthetic, symbol, chain, isGasAsset, ticker, address } = getAssetInfo(assetString);
|
160
|
-
// console.log('getAssetInfo: ', { isSynthetic, symbol, chain, isGasAsset, ticker, address });
|
161
|
-
// const { tax, decimal, identifier: tokenIdentifier } = getStaticToken(assetString as unknown as TokenNames);
|
162
|
-
// console.log('getStaticToken: ', { tax, decimal, tokenIdentifier });
|
163
|
-
//
|
164
|
-
// // Convert value to a BigInt if necessary
|
165
|
-
// let safeValue = (val: NumberPrimitives, decimal: number): BigInt => {
|
166
|
-
// if (typeof val === 'bigint') {
|
167
|
-
// return val;
|
168
|
-
// } else if (typeof val === 'number') {
|
169
|
-
// return BigInt(val * Math.pow(10, decimal));
|
170
|
-
// } else {
|
171
|
-
// return BigInt(0);
|
172
|
-
// }
|
173
|
-
// };
|
174
|
-
//
|
175
|
-
// const parsedValue = safeValue(value, decimal);
|
176
|
-
// console.log('parsedValue: ', parsedValue);
|
177
|
-
//
|
178
|
-
// let asset: AssetValue | undefined;
|
179
|
-
//
|
180
|
-
// if (tokenIdentifier) {
|
181
|
-
// console.log('tokenIdentifier is truthy'); // Indicates tokenIdentifier has a value considered true in a boolean context
|
182
|
-
// asset = new AssetValue({
|
183
|
-
// tax,
|
184
|
-
// decimal,
|
185
|
-
// identifier: tokenIdentifier,
|
186
|
-
// value: parsedValue,
|
187
|
-
// });
|
188
|
-
// } else if (isSynthetic) {
|
189
|
-
// console.log('isSynthetic is true'); // Indicates the asset is synthetic
|
190
|
-
// asset = new AssetValue({
|
191
|
-
// tax,
|
192
|
-
// decimal: 8, // Synthetic assets use a fixed decimal value
|
193
|
-
// identifier: assetString,
|
194
|
-
// value: parsedValue,
|
195
|
-
// });
|
196
|
-
// } else {
|
197
|
-
// asset = undefined;
|
198
|
-
// }
|
199
|
-
//
|
200
|
-
// return asset;
|
201
|
-
// }
|
202
|
-
|
203
190
|
static fromStringSync(assetString: string, value: NumberPrimitives = 0) {
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
identifier: tokenIdentifier,
|
210
|
-
} = getStaticToken(assetString as unknown as TokenNames);
|
211
|
-
// console.log('getStaticToken: ', { tax, decimal, tokenIdentifier });
|
212
|
-
// console.log('value: ', value);
|
213
|
-
// console.log('decimal: ', decimal);
|
214
|
-
const parsedValue = safeValue(value, decimal);
|
215
|
-
// console.log('parsedValue: ', parsedValue);
|
216
|
-
let asset: AssetValue | undefined;
|
217
|
-
|
218
|
-
if (tokenIdentifier) {
|
219
|
-
console.log('tokenIdentifier is truthy'); // Indicates tokenIdentifier has a value considered true in a boolean context
|
220
|
-
asset = new AssetValue({
|
191
|
+
let tag = TAG + " | fromStringSync | ";
|
192
|
+
try {
|
193
|
+
//@ts-ignore
|
194
|
+
const { isSynthetic, symbol, chain, isGasAsset, ticker, address } = getAssetInfo(assetString);
|
195
|
+
const {
|
221
196
|
tax,
|
222
197
|
decimal,
|
223
198
|
identifier: tokenIdentifier,
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
199
|
+
}:any = getStaticToken(assetString as unknown as TokenNames);
|
200
|
+
const parsedValue = safeValue(value, decimal);
|
201
|
+
let asset: AssetValue | undefined;
|
202
|
+
|
203
|
+
if (tokenIdentifier) {
|
204
|
+
asset = new AssetValue({
|
205
|
+
tax,
|
206
|
+
decimal,
|
207
|
+
identifier: tokenIdentifier,
|
208
|
+
// @ts-ignore
|
209
|
+
value: parsedValue,
|
210
|
+
});
|
211
|
+
} else if (isSynthetic) {
|
212
|
+
asset = new AssetValue({
|
213
|
+
tax,
|
214
|
+
decimal: 8, // Synthetic assets use a fixed decimal value
|
215
|
+
identifier: assetString,
|
216
|
+
// @ts-ignore
|
217
|
+
value: parsedValue,
|
218
|
+
});
|
219
|
+
} else {
|
220
|
+
asset = undefined;
|
221
|
+
}
|
222
|
+
|
223
|
+
return asset;
|
224
|
+
} catch (error) {
|
225
|
+
console.error(tag + 'Error in fromStringSync:', error);
|
237
226
|
}
|
238
|
-
|
239
|
-
return asset;
|
240
227
|
}
|
241
228
|
|
242
229
|
static async fromIdentifier(
|
243
|
-
|
244
|
-
|
230
|
+
assetString: `${Chain}.${string}` | `${Chain}/${string}` | `${Chain}.${string}-${string}`,
|
231
|
+
value: NumberPrimitives = 0,
|
245
232
|
) {
|
246
|
-
|
233
|
+
let tag = TAG + " | fromIdentifier | ";
|
234
|
+
try {
|
235
|
+
return createAssetValue(assetString, value);
|
236
|
+
} catch (error) {
|
237
|
+
console.error(tag + 'Error in fromIdentifier:', error);
|
238
|
+
}
|
247
239
|
}
|
248
240
|
|
249
241
|
static fromIdentifierSync(identifier: TokenNames, value: NumberPrimitives = 0) {
|
250
|
-
|
251
|
-
|
242
|
+
let tag = TAG + " | fromIdentifierSync | ";
|
243
|
+
try {
|
244
|
+
//@ts-ignore
|
245
|
+
const { decimal, identifier: tokenIdentifier } = getStaticToken(identifier);
|
246
|
+
const parsedValue = safeValue(value, decimal);
|
252
247
|
|
253
|
-
|
248
|
+
// @ts-ignore
|
249
|
+
return new AssetValue({ decimal, identifier: tokenIdentifier, value: parsedValue });
|
250
|
+
} catch (error) {
|
251
|
+
console.error(tag + 'Error in fromIdentifierSync:', error);
|
252
|
+
}
|
254
253
|
}
|
255
254
|
|
256
255
|
static fromChainOrSignature(assetString: CommonAssetString, value: NumberPrimitives = 0) {
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
256
|
+
let tag = TAG + " | fromChainOrSignature | ";
|
257
|
+
try {
|
258
|
+
const { decimal, identifier } = getCommonAssetInfo(assetString);
|
259
|
+
if (!decimal || !identifier) throw Error('unknown coin! ' + assetString);
|
260
|
+
const parsedValue = safeValue(value, decimal);
|
261
|
+
console.log(tag + "parsedValue: ", parsedValue);
|
262
|
+
console.log(tag + "decimal: ", decimal);
|
263
|
+
console.log(tag + "identifier: ", identifier);
|
264
|
+
|
265
|
+
// @ts-ignore
|
266
|
+
return new AssetValue({ value: parsedValue, decimal, identifier });
|
267
|
+
} catch (error) {
|
268
|
+
console.error(tag + 'Error in fromChainOrSignature:', error);
|
269
|
+
}
|
262
270
|
}
|
263
271
|
|
264
272
|
static async loadStaticAssets() {
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
...tokensPackage
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
273
|
+
let tag = TAG + " | loadStaticAssets | ";
|
274
|
+
try {
|
275
|
+
return new Promise<{ ok: true } | { ok: false; message: string; error: any }>(
|
276
|
+
async (resolve, reject) => {
|
277
|
+
try {
|
278
|
+
const {
|
279
|
+
ThorchainList: _ThorchainList,
|
280
|
+
NativeList,
|
281
|
+
...tokensPackage
|
282
|
+
} = await import('@coinmasters/tokens');
|
283
|
+
|
284
|
+
const tokensMap = [NativeList, ...Object.values(tokensPackage)].reduce(
|
285
|
+
(acc, { tokens }: any) => {
|
286
|
+
if (!tokens) {
|
287
|
+
console.warn(tag + "No tokens found in the current package, skipping.");
|
288
|
+
return acc;
|
289
|
+
}
|
290
|
+
|
291
|
+
// @ts-ignore
|
292
|
+
tokens.forEach(({ identifier, chain, ...rest }) => {
|
293
|
+
const decimal = 'decimals' in rest ? rest.decimals : BaseDecimal[chain as Chain];
|
294
|
+
|
295
|
+
acc.set(identifier as TokenNames, { identifier, decimal });
|
296
|
+
});
|
297
|
+
|
287
298
|
return acc;
|
288
|
-
}
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
} catch (error) {
|
309
|
-
console.error("Error loading static assets:", error);
|
310
|
-
reject({
|
311
|
-
ok: false,
|
312
|
-
error,
|
313
|
-
message: "Couldn't load static assets. Ensure you have installed @coinmasters/tokens package",
|
314
|
-
});
|
315
|
-
}
|
316
|
-
},
|
317
|
-
);
|
299
|
+
},
|
300
|
+
new Map<TokenNames, { decimal: number; identifier: string }>(),
|
301
|
+
);
|
302
|
+
|
303
|
+
staticTokensMap = tokensMap;
|
304
|
+
|
305
|
+
resolve({ ok: true });
|
306
|
+
} catch (error) {
|
307
|
+
console.error(tag + "Error loading static assets:", error);
|
308
|
+
reject({
|
309
|
+
ok: false,
|
310
|
+
error,
|
311
|
+
message: "Couldn't load static assets. Ensure you have installed @coinmasters/tokens package",
|
312
|
+
});
|
313
|
+
}
|
314
|
+
},
|
315
|
+
);
|
316
|
+
} catch (error) {
|
317
|
+
console.error(tag + 'Error in loadStaticAssets:', error);
|
318
|
+
}
|
318
319
|
}
|
319
320
|
}
|
320
321
|
|
321
322
|
export const getMinAmountByChain = (chain: Chain) => {
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
323
|
+
let tag = TAG + " | getMinAmountByChain | ";
|
324
|
+
try {
|
325
|
+
const asset:any = AssetValue.fromChainOrSignature(chain);
|
326
|
+
|
327
|
+
switch (chain) {
|
328
|
+
case Chain.Bitcoin:
|
329
|
+
case Chain.Litecoin:
|
330
|
+
case Chain.Dash:
|
331
|
+
case Chain.Zcash:
|
332
|
+
case Chain.BitcoinCash:
|
333
|
+
return asset.set(0.00010001);
|
334
|
+
|
335
|
+
case Chain.Dogecoin:
|
336
|
+
return asset.set(1.00000001);
|
337
|
+
|
338
|
+
case Chain.Base:
|
339
|
+
case Chain.Arbitrum:
|
340
|
+
case Chain.Avalanche:
|
341
|
+
case Chain.Ethereum:
|
342
|
+
return asset.set(0.00000001);
|
343
|
+
|
344
|
+
case Chain.THORChain:
|
345
|
+
case Chain.Mayachain:
|
346
|
+
return asset.set(0.0000000001);
|
347
|
+
|
348
|
+
default:
|
349
|
+
return asset.set(0.00000001);
|
350
|
+
}
|
351
|
+
} catch (error) {
|
352
|
+
console.error(tag + 'Error in getMinAmountByChain:', error);
|
348
353
|
}
|
349
354
|
};
|
350
355
|
|
351
356
|
const getAssetInfo = (identifier: string) => {
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
identifier.
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
357
|
+
let tag = TAG + " | getAssetInfo | ";
|
358
|
+
try {
|
359
|
+
const isSynthetic = identifier.slice(0, 14).includes('/');
|
360
|
+
const [synthChain, synthSymbol] = identifier.split('.').pop()!.split('/');
|
361
|
+
const adjustedIdentifier =
|
362
|
+
identifier.includes('.') && !isSynthetic ? identifier : `${Chain.THORChain}.${synthSymbol}`;
|
363
|
+
|
364
|
+
const [chain, symbol] = adjustedIdentifier.split('.') as [Chain, string];
|
365
|
+
const [ticker, address] = (isSynthetic ? synthSymbol : symbol).split('-') as [string, string?];
|
366
|
+
|
367
|
+
return {
|
368
|
+
address: address?.toLowerCase(),
|
369
|
+
chain,
|
370
|
+
isGasAsset: isGasAsset({ chain, symbol }),
|
371
|
+
isSynthetic,
|
372
|
+
symbol:
|
373
|
+
(isSynthetic ? `${synthChain}/` : '') +
|
374
|
+
(address ? `${ticker}-${address?.toLowerCase() ?? ''}` : symbol),
|
375
|
+
ticker,
|
376
|
+
};
|
377
|
+
} catch (error) {
|
378
|
+
console.error(tag + 'Error in getAssetInfo:', error);
|
379
|
+
}
|
370
380
|
};
|