otomato-sdk 1.5.48 → 1.5.49
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/dist/src/utils/helpers.js +15 -12
- package/package.json +1 -1
|
@@ -13,8 +13,17 @@ export function convertToTokenUnits(amount, chainId, contractAddress) {
|
|
|
13
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14
14
|
const token = yield getToken(chainId, contractAddress);
|
|
15
15
|
const decimals = token.decimals;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// Calculate the result as a number first
|
|
17
|
+
const result = amount * Math.pow(10, decimals);
|
|
18
|
+
console.log("result", result);
|
|
19
|
+
// Check if the result is an integer
|
|
20
|
+
if (!Number.isInteger(result)) {
|
|
21
|
+
console.log("throwing");
|
|
22
|
+
throw new Error(`Conversion resulted in a non-integer value: ${result}. Please provide an amount that results in a whole number of token units.`);
|
|
23
|
+
}
|
|
24
|
+
console.log("is an integer");
|
|
25
|
+
// If we've reached here, the result is an integer, so we can safely convert to BigInt
|
|
26
|
+
return BigInt(Math.round(result));
|
|
18
27
|
});
|
|
19
28
|
}
|
|
20
29
|
export function convertToTokenUnitsFromSymbol(amount, chainId, symbol) {
|
|
@@ -29,22 +38,16 @@ export function convertTokenUnitsFromSymbol(amount, chainId, symbol) {
|
|
|
29
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
39
|
const token = yield getTokenFromSymbol(chainId, symbol);
|
|
31
40
|
const decimals = token.decimals;
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
const adjustedAmount = amount / divisor;
|
|
35
|
-
// Convert the result to a number
|
|
36
|
-
return Number(adjustedAmount);
|
|
41
|
+
// Convert to float using division
|
|
42
|
+
return Number(amount) / Math.pow(10, decimals);
|
|
37
43
|
});
|
|
38
44
|
}
|
|
39
45
|
export function convertTokenUnitsFromAddress(amount, chainId, contractAddress) {
|
|
40
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
47
|
const token = yield getToken(chainId, contractAddress);
|
|
42
48
|
const decimals = token.decimals;
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
const adjustedAmount = amount / divisor;
|
|
46
|
-
// Convert the result to a number
|
|
47
|
-
return Number(adjustedAmount);
|
|
49
|
+
// Convert to float using division
|
|
50
|
+
return Number(amount) / Math.pow(10, decimals);
|
|
48
51
|
});
|
|
49
52
|
}
|
|
50
53
|
/**
|