@owney/sdk 0.7.26-beta.0 → 0.7.26-beta.2

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/index.cjs CHANGED
@@ -2208,7 +2208,21 @@ var CHAIN_NAMES = {
2208
2208
  function chainName(chainId) {
2209
2209
  return CHAIN_NAMES[chainId] ?? `chain ${chainId}`;
2210
2210
  }
2211
- async function ensureWalletOnChain(pub, wallet, expected) {
2211
+ var SETTLE_TIMEOUT_MS = 8e3;
2212
+ var POLL_INTERVAL_MS = 200;
2213
+ var wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2214
+ async function readChainId(pub) {
2215
+ try {
2216
+ return await pub.getChainId();
2217
+ } catch {
2218
+ return void 0;
2219
+ }
2220
+ }
2221
+ async function ensureWalletOnChain(pub, wallet, expected, options = {}) {
2222
+ const {
2223
+ settleTimeoutMs = SETTLE_TIMEOUT_MS,
2224
+ pollIntervalMs = POLL_INTERVAL_MS
2225
+ } = options;
2212
2226
  const actual = await pub.getChainId();
2213
2227
  if (actual === expected) return;
2214
2228
  try {
@@ -2224,14 +2238,18 @@ async function ensureWalletOnChain(pub, wallet, expected) {
2224
2238
  }
2225
2239
  );
2226
2240
  }
2227
- const after = await pub.getChainId();
2228
- if (after !== expected) {
2229
- throw new OwneyError(
2230
- "CHAIN_MISMATCH",
2231
- `Your wallet is still on ${chainName(after)}. Switch it to ${chainName(expected)} and try again.`,
2232
- { expectedChainId: expected, actualChainId: after }
2233
- );
2234
- }
2241
+ const deadline = Date.now() + settleTimeoutMs;
2242
+ let after = await readChainId(pub);
2243
+ while (after !== expected && Date.now() < deadline) {
2244
+ await wait(pollIntervalMs);
2245
+ after = await readChainId(pub);
2246
+ }
2247
+ if (after === expected) return;
2248
+ throw new OwneyError(
2249
+ "CHAIN_MISMATCH",
2250
+ `Your wallet is still on ${chainName(after ?? actual)}. Switch it to ${chainName(expected)} and try again.`,
2251
+ { expectedChainId: expected, actualChainId: after ?? actual }
2252
+ );
2235
2253
  }
2236
2254
 
2237
2255
  // src/lib/swap/swap-api.ts
@@ -2282,7 +2300,7 @@ function createSwapApi(baseUrl, apiKey) {
2282
2300
  /** Source assets the user may pay with, and each chain's deposit targets. */
2283
2301
  listTokens: () => request(baseUrl, apiKey, "/tokens"),
2284
2302
  /**
2285
- * Search one chain's payable-with assets by name, symbol or address.
2303
+ * Search the payable-with assets by name, symbol or address.
2286
2304
  *
2287
2305
  * Separate from `listTokens` on purpose: the full set is thousands of
2288
2306
  * tokens per chain, far too much to ship to a picker, so the short list
@@ -2295,8 +2313,10 @@ function createSwapApi(baseUrl, apiKey) {
2295
2313
  baseUrl,
2296
2314
  apiKey,
2297
2315
  `/tokens/search?${new URLSearchParams({
2298
- chainId: String(params.chainId),
2299
2316
  query: params.query,
2317
+ // Omitted, the routing API searches every supported chain — which is
2318
+ // what a picker wants, since its rows already span all three.
2319
+ ...params.chainId === void 0 ? {} : { chainId: String(params.chainId) },
2300
2320
  ...params.limit === void 0 ? {} : { limit: String(params.limit) }
2301
2321
  }).toString()}`
2302
2322
  ),
@@ -4429,7 +4449,7 @@ var OwneySDK = class {
4429
4449
  return this.swapApi().listTokens();
4430
4450
  }
4431
4451
  /**
4432
- * Search the assets a user may pay with on one chain.
4452
+ * Search the assets a user may pay with, across every supported chain.
4433
4453
  *
4434
4454
  * `getSwapTokens` returns the short list worth rendering unprompted. This
4435
4455
  * reaches everything else the routing API will accept — thousands per chain
@@ -4447,8 +4467,8 @@ var OwneySDK = class {
4447
4467
  const query = params.query.trim();
4448
4468
  if (!query) return { tokens: [] };
4449
4469
  return this.swapApi().searchTokens({
4450
- chainId: params.chainId,
4451
4470
  query,
4471
+ ...params.chainId === void 0 ? {} : { chainId: params.chainId },
4452
4472
  ...params.limit === void 0 ? {} : { limit: params.limit }
4453
4473
  });
4454
4474
  }
@@ -4573,7 +4593,7 @@ var OwneySDK = class {
4573
4593
  options.onSwapProgress?.("withdrawing");
4574
4594
  const withdraw = await this.withdraw({
4575
4595
  asset: options.from.symbol,
4576
- ...options.amount === void 0 ? {} : { amount: options.amount },
4596
+ ...options.amount === void 0 ? {} : { amount: (0, import_viem8.parseUnits)(options.amount, asset.decimals).toString() },
4577
4597
  ...options.agentId ? { agentId: options.agentId } : {}
4578
4598
  });
4579
4599
  const arrived = await awaitWithdrawalArrival({
package/dist/index.d.cts CHANGED
@@ -910,7 +910,7 @@ declare class OwneySDK {
910
910
  chains: SwapChainTokens[];
911
911
  }>;
912
912
  /**
913
- * Search the assets a user may pay with on one chain.
913
+ * Search the assets a user may pay with, across every supported chain.
914
914
  *
915
915
  * `getSwapTokens` returns the short list worth rendering unprompted. This
916
916
  * reaches everything else the routing API will accept — thousands per chain
@@ -925,7 +925,8 @@ declare class OwneySDK {
925
925
  * Returns nothing for a blank query rather than asking for the whole list.
926
926
  */
927
927
  searchSwapTokens(params: {
928
- chainId: number;
928
+ /** Omit to search every supported chain. */
929
+ chainId?: number;
929
930
  query: string;
930
931
  limit?: number;
931
932
  }): Promise<{
package/dist/index.d.ts CHANGED
@@ -910,7 +910,7 @@ declare class OwneySDK {
910
910
  chains: SwapChainTokens[];
911
911
  }>;
912
912
  /**
913
- * Search the assets a user may pay with on one chain.
913
+ * Search the assets a user may pay with, across every supported chain.
914
914
  *
915
915
  * `getSwapTokens` returns the short list worth rendering unprompted. This
916
916
  * reaches everything else the routing API will accept — thousands per chain
@@ -925,7 +925,8 @@ declare class OwneySDK {
925
925
  * Returns nothing for a blank query rather than asking for the whole list.
926
926
  */
927
927
  searchSwapTokens(params: {
928
- chainId: number;
928
+ /** Omit to search every supported chain. */
929
+ chainId?: number;
929
930
  query: string;
930
931
  limit?: number;
931
932
  }): Promise<{
package/dist/index.js CHANGED
@@ -2174,7 +2174,21 @@ var CHAIN_NAMES = {
2174
2174
  function chainName(chainId) {
2175
2175
  return CHAIN_NAMES[chainId] ?? `chain ${chainId}`;
2176
2176
  }
2177
- async function ensureWalletOnChain(pub, wallet, expected) {
2177
+ var SETTLE_TIMEOUT_MS = 8e3;
2178
+ var POLL_INTERVAL_MS = 200;
2179
+ var wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2180
+ async function readChainId(pub) {
2181
+ try {
2182
+ return await pub.getChainId();
2183
+ } catch {
2184
+ return void 0;
2185
+ }
2186
+ }
2187
+ async function ensureWalletOnChain(pub, wallet, expected, options = {}) {
2188
+ const {
2189
+ settleTimeoutMs = SETTLE_TIMEOUT_MS,
2190
+ pollIntervalMs = POLL_INTERVAL_MS
2191
+ } = options;
2178
2192
  const actual = await pub.getChainId();
2179
2193
  if (actual === expected) return;
2180
2194
  try {
@@ -2190,14 +2204,18 @@ async function ensureWalletOnChain(pub, wallet, expected) {
2190
2204
  }
2191
2205
  );
2192
2206
  }
2193
- const after = await pub.getChainId();
2194
- if (after !== expected) {
2195
- throw new OwneyError(
2196
- "CHAIN_MISMATCH",
2197
- `Your wallet is still on ${chainName(after)}. Switch it to ${chainName(expected)} and try again.`,
2198
- { expectedChainId: expected, actualChainId: after }
2199
- );
2200
- }
2207
+ const deadline = Date.now() + settleTimeoutMs;
2208
+ let after = await readChainId(pub);
2209
+ while (after !== expected && Date.now() < deadline) {
2210
+ await wait(pollIntervalMs);
2211
+ after = await readChainId(pub);
2212
+ }
2213
+ if (after === expected) return;
2214
+ throw new OwneyError(
2215
+ "CHAIN_MISMATCH",
2216
+ `Your wallet is still on ${chainName(after ?? actual)}. Switch it to ${chainName(expected)} and try again.`,
2217
+ { expectedChainId: expected, actualChainId: after ?? actual }
2218
+ );
2201
2219
  }
2202
2220
 
2203
2221
  // src/lib/swap/swap-api.ts
@@ -2248,7 +2266,7 @@ function createSwapApi(baseUrl, apiKey) {
2248
2266
  /** Source assets the user may pay with, and each chain's deposit targets. */
2249
2267
  listTokens: () => request(baseUrl, apiKey, "/tokens"),
2250
2268
  /**
2251
- * Search one chain's payable-with assets by name, symbol or address.
2269
+ * Search the payable-with assets by name, symbol or address.
2252
2270
  *
2253
2271
  * Separate from `listTokens` on purpose: the full set is thousands of
2254
2272
  * tokens per chain, far too much to ship to a picker, so the short list
@@ -2261,8 +2279,10 @@ function createSwapApi(baseUrl, apiKey) {
2261
2279
  baseUrl,
2262
2280
  apiKey,
2263
2281
  `/tokens/search?${new URLSearchParams({
2264
- chainId: String(params.chainId),
2265
2282
  query: params.query,
2283
+ // Omitted, the routing API searches every supported chain — which is
2284
+ // what a picker wants, since its rows already span all three.
2285
+ ...params.chainId === void 0 ? {} : { chainId: String(params.chainId) },
2266
2286
  ...params.limit === void 0 ? {} : { limit: String(params.limit) }
2267
2287
  }).toString()}`
2268
2288
  ),
@@ -3028,6 +3048,7 @@ function aggregateApyByChainAndAsset(agentApys, agentBalances) {
3028
3048
 
3029
3049
  // src/client.ts
3030
3050
  import {
3051
+ parseUnits as parseUnits2,
3031
3052
  createPublicClient as createPublicClient2,
3032
3053
  createWalletClient,
3033
3054
  custom,
@@ -4400,7 +4421,7 @@ var OwneySDK = class {
4400
4421
  return this.swapApi().listTokens();
4401
4422
  }
4402
4423
  /**
4403
- * Search the assets a user may pay with on one chain.
4424
+ * Search the assets a user may pay with, across every supported chain.
4404
4425
  *
4405
4426
  * `getSwapTokens` returns the short list worth rendering unprompted. This
4406
4427
  * reaches everything else the routing API will accept — thousands per chain
@@ -4418,8 +4439,8 @@ var OwneySDK = class {
4418
4439
  const query = params.query.trim();
4419
4440
  if (!query) return { tokens: [] };
4420
4441
  return this.swapApi().searchTokens({
4421
- chainId: params.chainId,
4422
4442
  query,
4443
+ ...params.chainId === void 0 ? {} : { chainId: params.chainId },
4423
4444
  ...params.limit === void 0 ? {} : { limit: params.limit }
4424
4445
  });
4425
4446
  }
@@ -4544,7 +4565,7 @@ var OwneySDK = class {
4544
4565
  options.onSwapProgress?.("withdrawing");
4545
4566
  const withdraw = await this.withdraw({
4546
4567
  asset: options.from.symbol,
4547
- ...options.amount === void 0 ? {} : { amount: options.amount },
4568
+ ...options.amount === void 0 ? {} : { amount: parseUnits2(options.amount, asset.decimals).toString() },
4548
4569
  ...options.agentId ? { agentId: options.agentId } : {}
4549
4570
  });
4550
4571
  const arrived = await awaitWithdrawalArrival({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.7.26-beta.0",
3
+ "version": "0.7.26-beta.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",