otomato-sdk 2.0.648 → 2.0.649

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.
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = '2.0.648';
1
+ export const SDK_VERSION = '2.0.649';
2
2
  export function compareVersions(v1, v2) {
3
3
  // Split the version strings into parts
4
4
  const v1Parts = v1.split('.').map(Number);
@@ -178,7 +178,7 @@ export async function getUserProtocolBalances(params) {
178
178
  'function convertToAssets(uint256) view returns (uint256)',
179
179
  ];
180
180
  const results = [];
181
- await Promise.allSettled(addressesToCheck.map(async ({ protocol, token }) => {
181
+ const settled = await Promise.allSettled(addressesToCheck.map(async ({ protocol, token }) => {
182
182
  const contract = new ethers.Contract(token, readABI, provider);
183
183
  const [rawBalanceBN, decimals, symbol] = await Promise.all([
184
184
  contract.balanceOf(address),
@@ -218,5 +218,26 @@ export async function getUserProtocolBalances(params) {
218
218
  underlyingBalance, // computed by getBalanceInUnderlying
219
219
  });
220
220
  }));
221
+ // A rejected entry is discarded from `results` above — log it so a failed
222
+ // read is never silently indistinguishable from "this protocol has no
223
+ // balance". See otomato-dapp#3046.
224
+ settled.forEach((outcome, i) => {
225
+ if (outcome.status === 'rejected') {
226
+ const { protocol, token } = addressesToCheck[i];
227
+ const reason = outcome.reason instanceof Error ? outcome.reason.message : String(outcome.reason);
228
+ console.error(`getUserProtocolBalances: balance read failed for protocol=${protocol} token=${token} chainId=${chainId}: ${reason}`);
229
+ }
230
+ });
231
+ // If every read rejected, `results` is `[]` for the same reason a genuinely
232
+ // empty wallet would be — a caller cannot tell "no positions" from "the RPC
233
+ // is down" (otomato-dapp#3046). Surface it instead of returning silently.
234
+ const allFailed = settled.length > 0 && settled.every((s) => s.status === 'rejected');
235
+ if (allFailed) {
236
+ const firstRejected = settled.find((s) => s.status === 'rejected');
237
+ const reason = firstRejected.reason instanceof Error ? firstRejected.reason.message : String(firstRejected.reason);
238
+ throw new Error(`getUserProtocolBalances: all ${settled.length} balance read(s) failed for chainId=${chainId} ` +
239
+ `address=${address} contractAddress=${contractAddress} — likely an RPC failure, not an empty portfolio. ` +
240
+ `First error: ${reason}`);
241
+ }
221
242
  return results;
222
243
  }
@@ -1,2 +1,2 @@
1
- export declare const SDK_VERSION = "2.0.648";
1
+ export declare const SDK_VERSION = "2.0.649";
2
2
  export declare function compareVersions(v1: string, v2: string): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "otomato-sdk",
3
- "version": "2.0.648",
3
+ "version": "2.0.649",
4
4
  "description": "An SDK for building and managing automations on Otomato",
5
5
  "repository": {
6
6
  "type": "git",