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.
@@ -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
- const adjustedAmount = ethers.parseUnits(amount.toString(), decimals);
17
- return adjustedAmount;
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
- // Divide by 10^decimals to get the original amount
33
- const divisor = BigInt(10) ** BigInt(decimals);
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
- // Divide by 10^decimals to get the original amount
44
- const divisor = BigInt(10) ** BigInt(decimals);
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
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "otomato-sdk",
3
- "version": "1.5.48",
3
+ "version": "1.5.49",
4
4
  "description": "An SDK for building and managing automations on Otomato",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/types/src/index.d.ts",