otomato-sdk 1.5.65 → 1.5.66

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.
@@ -36,7 +36,6 @@ class RPCServices {
36
36
  getTokenDetails(chainId, contractAddress) {
37
37
  return __awaiter(this, void 0, void 0, function* () {
38
38
  const rpcUrl = this.getRPC(chainId); // Get the RPC URL for the chain
39
- // Create a provider using ethers.js
40
39
  const provider = new ethers.JsonRpcProvider(rpcUrl);
41
40
  // Define the contract ABI for the read-only functions (decimals, name, symbol)
42
41
  const erc20ABI = [
@@ -44,14 +43,33 @@ class RPCServices {
44
43
  'function name() view returns (string)',
45
44
  'function symbol() view returns (string)',
46
45
  ];
47
- // Create a contract instance
48
46
  const contract = new ethers.Contract(contractAddress, erc20ABI, provider);
49
- // Fetch the decimals, name, and symbol in parallel using Promise.all
47
+ const maxRetries = 3; // Max number of retries
48
+ const retryDelay = (attempt) => Math.pow(2, attempt) * 1000; // Exponential backoff delay (in milliseconds)
49
+ // Define a helper function to retry the RPC call
50
+ const fetchWithRetry = (fn, retries) => __awaiter(this, void 0, void 0, function* () {
51
+ let attempt = 0;
52
+ while (attempt <= retries) {
53
+ try {
54
+ return yield fn();
55
+ }
56
+ catch (error) {
57
+ if (attempt === retries) {
58
+ throw new Error(`Error fetching token details ${contractAddress} on chain ${chainId}`);
59
+ }
60
+ attempt++;
61
+ console.warn(`Attempt ${attempt} to fetch token details failed. Retrying in ${retryDelay(attempt)}ms...`);
62
+ yield new Promise(resolve => setTimeout(resolve, retryDelay(attempt)));
63
+ }
64
+ }
65
+ throw new Error('Max retries exceeded');
66
+ });
67
+ // Fetch the decimals, name, and symbol with retries
50
68
  try {
51
69
  const [decimals, name, symbol] = yield Promise.all([
52
- contract.decimals(),
53
- contract.name(),
54
- contract.symbol(),
70
+ fetchWithRetry(() => contract.decimals(), maxRetries),
71
+ fetchWithRetry(() => contract.name(), maxRetries),
72
+ fetchWithRetry(() => contract.symbol(), maxRetries),
55
73
  ]);
56
74
  const token = {
57
75
  contractAddress,
@@ -15,13 +15,10 @@ export function convertToTokenUnits(amount, chainId, contractAddress) {
15
15
  const decimals = token.decimals;
16
16
  // Calculate the result as a number first
17
17
  const result = amount * Math.pow(10, decimals);
18
- console.log("result", result);
19
18
  // Check if the result is an integer
20
19
  if (!Number.isInteger(result)) {
21
- console.log("throwing");
22
20
  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
21
  }
24
- console.log("is an integer");
25
22
  // If we've reached here, the result is an integer, so we can safely convert to BigInt
26
23
  return BigInt(Math.round(result));
27
24
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "otomato-sdk",
3
- "version": "1.5.65",
3
+ "version": "1.5.66",
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",