@owney/sdk 0.7.28-beta.3 → 0.7.28-beta.4

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
@@ -3074,6 +3074,10 @@ var DEFAULT_POLL_MS2 = 5e3;
3074
3074
  var MAX_BACKOFF_MS = 3e4;
3075
3075
  var backoffFor = (failures, base4) => Math.min(base4 * 2 ** Math.min(failures, 5), MAX_BACKOFF_MS);
3076
3076
  var DEFAULT_TIMEOUT_MS2 = 15 * 60 * 1e3;
3077
+ var NOT_FOUND_GRACE_MS = 2 * 60 * 1e3;
3078
+ function isNotFound(error) {
3079
+ return error instanceof OwneyError && error.details?.statusCode === 404;
3080
+ }
3077
3081
  async function runFusionOrder(deps, options) {
3078
3082
  const {
3079
3083
  orderHash,
@@ -3084,6 +3088,7 @@ async function runFusionOrder(deps, options) {
3084
3088
  } = options;
3085
3089
  const deadline = deps.now() + timeoutMs;
3086
3090
  let failures = 0;
3091
+ let notFoundSince;
3087
3092
  const published = /* @__PURE__ */ new Set();
3088
3093
  onStage?.("swapping");
3089
3094
  for (; ; ) {
@@ -3125,7 +3130,20 @@ async function runFusionOrder(deps, options) {
3125
3130
  try {
3126
3131
  ({ status } = await deps.orderStatus(orderHash));
3127
3132
  failures = 0;
3128
- } catch {
3133
+ notFoundSince = void 0;
3134
+ } catch (error) {
3135
+ if (isNotFound(error)) {
3136
+ notFoundSince ??= deps.now();
3137
+ if (deps.now() - notFoundSince >= NOT_FOUND_GRACE_MS) {
3138
+ throw new OwneyError(
3139
+ "SWAP_ORDER_NOT_FOUND",
3140
+ "The swap provider has no record of this order, so nothing was exchanged.",
3141
+ { orderHash }
3142
+ );
3143
+ }
3144
+ } else {
3145
+ notFoundSince = void 0;
3146
+ }
3129
3147
  failures += 1;
3130
3148
  await deps.sleep(backoffFor(failures, pollIntervalMs));
3131
3149
  continue;
@@ -3183,9 +3201,9 @@ async function runSameChainOrder(deps, options) {
3183
3201
  for (; ; ) {
3184
3202
  if (deps.now() >= deadline) {
3185
3203
  throw new OwneyError(
3186
- "SWAP_ORDER_EXPIRED",
3187
- "No one filled the swap in time. Nothing was exchanged and your funds are still in your wallet.",
3188
- { orderHash }
3204
+ "SWAP_REQUEST_FAILED",
3205
+ "Timed out waiting for the swap to fill. It may still complete \u2014 if it does, the swapped funds will be in your wallet. Check before retrying.",
3206
+ { orderHash, settlementUnconfirmed: true }
3189
3207
  );
3190
3208
  }
3191
3209
  let status;
@@ -3533,10 +3551,16 @@ async function runFusion(deps, options, walletAddress) {
3533
3551
  debugLog("owney-sdk", "swap: awaiting signature in wallet", {
3534
3552
  signingOnChain: quote.src.chainId
3535
3553
  });
3536
- const signature = await awaitWalletPrompt(
3537
- () => deps.signTypedData(built.typedData),
3538
- "sign the swap"
3539
- );
3554
+ let signature;
3555
+ try {
3556
+ signature = await awaitWalletPrompt(
3557
+ () => deps.signTypedData(built.typedData),
3558
+ "sign the swap"
3559
+ );
3560
+ } catch (error) {
3561
+ clearOrder(built.orderHash);
3562
+ throw error;
3563
+ }
3540
3564
  debugLog("owney-sdk", "swap: signed, submitting to relayer");
3541
3565
  await deps.api.submitOrder({
3542
3566
  srcChainId: quote.src.chainId,
@@ -3564,7 +3588,7 @@ async function runFusion(deps, options, walletAddress) {
3564
3588
  ...onStage ? { onStage } : {}
3565
3589
  });
3566
3590
  } catch (error) {
3567
- if (error instanceof OwneyError && (error.code === "SWAP_ORDER_REFUNDED" || error.code === "SWAP_ORDER_CANCELLED")) {
3591
+ if (error instanceof OwneyError && (error.code === "SWAP_ORDER_REFUNDED" || error.code === "SWAP_ORDER_CANCELLED" || error.code === "SWAP_ORDER_NOT_FOUND")) {
3568
3592
  clearOrder(built.orderHash);
3569
3593
  }
3570
3594
  throw error;
@@ -5799,7 +5823,7 @@ var OwneySDK = class {
5799
5823
  status: "completed"
5800
5824
  });
5801
5825
  } catch (error) {
5802
- if (error instanceof OwneyError && (error.code === "SWAP_ORDER_REFUNDED" || error.code === "SWAP_ORDER_CANCELLED")) {
5826
+ if (error instanceof OwneyError && (error.code === "SWAP_ORDER_REFUNDED" || error.code === "SWAP_ORDER_CANCELLED" || error.code === "SWAP_ORDER_NOT_FOUND")) {
5803
5827
  clearOrder(order.orderHash);
5804
5828
  updateWithdrawSwap(order.orderHash, { status: "refunded" });
5805
5829
  } else {
package/dist/index.d.cts CHANGED
@@ -964,7 +964,7 @@ type AgentApyOptions = {
964
964
  chainId?: number;
965
965
  };
966
966
 
967
- type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "WALLET_NOT_DEPLOYED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "CHAIN_MISMATCH" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_BALANCE_UNAVAILABLE" | "DEPOSIT_PARTIAL_FAILURE" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "DEPOSIT_INSUFFICIENT_BALANCE" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_NOTHING_TO_WITHDRAW" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "AGENT_RATE_LIMITED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "SPONSORED_CALLS_UNSUPPORTED" | "SPONSORED_CALLS_NO_ID" | "SPONSORED_CALLS_NO_RECEIPT" | "SWAP_DISABLED" | "SWAP_RATE_LIMITED" | "SWAP_REQUEST_FAILED" | "SWAP_QUOTE_FAILED" | "SWAP_UNSUPPORTED_PAIR" | "SWAP_APPROVAL_REQUIRED" | "SWAP_BELOW_DEPOSIT_MINIMUM" | "SWAP_DEPOSIT_PENDING" | "SWAP_WALLET_PROMPT_TIMEOUT" | "SWAP_INSUFFICIENT_GAS" | "SWAP_NATIVE_UNSUPPORTED" | "SWAP_ORDER_EXPIRED" | "SWAP_ORDER_REFUNDED" | "SWAP_ORDER_CANCELLED" | "WITHDRAW_ARRIVAL_TIMEOUT" | "WITHDRAW_SWAP_FAILED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "POOL_CATALOG_UNSUPPORTED" | "POOL_SELECTION_UNSUPPORTED" | "VALIDATION_INVALID_DAYS";
967
+ type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "WALLET_NOT_DEPLOYED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "CHAIN_MISMATCH" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_BALANCE_UNAVAILABLE" | "DEPOSIT_PARTIAL_FAILURE" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "DEPOSIT_INSUFFICIENT_BALANCE" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_NOTHING_TO_WITHDRAW" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "AGENT_RATE_LIMITED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "SPONSORED_CALLS_UNSUPPORTED" | "SPONSORED_CALLS_NO_ID" | "SPONSORED_CALLS_NO_RECEIPT" | "SWAP_DISABLED" | "SWAP_RATE_LIMITED" | "SWAP_REQUEST_FAILED" | "SWAP_QUOTE_FAILED" | "SWAP_UNSUPPORTED_PAIR" | "SWAP_APPROVAL_REQUIRED" | "SWAP_BELOW_DEPOSIT_MINIMUM" | "SWAP_DEPOSIT_PENDING" | "SWAP_WALLET_PROMPT_TIMEOUT" | "SWAP_INSUFFICIENT_GAS" | "SWAP_NATIVE_UNSUPPORTED" | "SWAP_ORDER_EXPIRED" | "SWAP_ORDER_REFUNDED" | "SWAP_ORDER_CANCELLED" | "SWAP_ORDER_NOT_FOUND" | "WITHDRAW_ARRIVAL_TIMEOUT" | "WITHDRAW_SWAP_FAILED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "POOL_CATALOG_UNSUPPORTED" | "POOL_SELECTION_UNSUPPORTED" | "VALIDATION_INVALID_DAYS";
968
968
  declare class OwneyError extends Error {
969
969
  readonly code: OwneyErrorCode;
970
970
  readonly details?: Record<string, unknown>;
package/dist/index.d.ts CHANGED
@@ -964,7 +964,7 @@ type AgentApyOptions = {
964
964
  chainId?: number;
965
965
  };
966
966
 
967
- type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "WALLET_NOT_DEPLOYED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "CHAIN_MISMATCH" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_BALANCE_UNAVAILABLE" | "DEPOSIT_PARTIAL_FAILURE" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "DEPOSIT_INSUFFICIENT_BALANCE" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_NOTHING_TO_WITHDRAW" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "AGENT_RATE_LIMITED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "SPONSORED_CALLS_UNSUPPORTED" | "SPONSORED_CALLS_NO_ID" | "SPONSORED_CALLS_NO_RECEIPT" | "SWAP_DISABLED" | "SWAP_RATE_LIMITED" | "SWAP_REQUEST_FAILED" | "SWAP_QUOTE_FAILED" | "SWAP_UNSUPPORTED_PAIR" | "SWAP_APPROVAL_REQUIRED" | "SWAP_BELOW_DEPOSIT_MINIMUM" | "SWAP_DEPOSIT_PENDING" | "SWAP_WALLET_PROMPT_TIMEOUT" | "SWAP_INSUFFICIENT_GAS" | "SWAP_NATIVE_UNSUPPORTED" | "SWAP_ORDER_EXPIRED" | "SWAP_ORDER_REFUNDED" | "SWAP_ORDER_CANCELLED" | "WITHDRAW_ARRIVAL_TIMEOUT" | "WITHDRAW_SWAP_FAILED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "POOL_CATALOG_UNSUPPORTED" | "POOL_SELECTION_UNSUPPORTED" | "VALIDATION_INVALID_DAYS";
967
+ type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "WALLET_NOT_DEPLOYED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "CHAIN_MISMATCH" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_BALANCE_UNAVAILABLE" | "DEPOSIT_PARTIAL_FAILURE" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "DEPOSIT_INSUFFICIENT_BALANCE" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_NOTHING_TO_WITHDRAW" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "AGENT_RATE_LIMITED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "SPONSORED_CALLS_UNSUPPORTED" | "SPONSORED_CALLS_NO_ID" | "SPONSORED_CALLS_NO_RECEIPT" | "SWAP_DISABLED" | "SWAP_RATE_LIMITED" | "SWAP_REQUEST_FAILED" | "SWAP_QUOTE_FAILED" | "SWAP_UNSUPPORTED_PAIR" | "SWAP_APPROVAL_REQUIRED" | "SWAP_BELOW_DEPOSIT_MINIMUM" | "SWAP_DEPOSIT_PENDING" | "SWAP_WALLET_PROMPT_TIMEOUT" | "SWAP_INSUFFICIENT_GAS" | "SWAP_NATIVE_UNSUPPORTED" | "SWAP_ORDER_EXPIRED" | "SWAP_ORDER_REFUNDED" | "SWAP_ORDER_CANCELLED" | "SWAP_ORDER_NOT_FOUND" | "WITHDRAW_ARRIVAL_TIMEOUT" | "WITHDRAW_SWAP_FAILED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "POOL_CATALOG_UNSUPPORTED" | "POOL_SELECTION_UNSUPPORTED" | "VALIDATION_INVALID_DAYS";
968
968
  declare class OwneyError extends Error {
969
969
  readonly code: OwneyErrorCode;
970
970
  readonly details?: Record<string, unknown>;
package/dist/index.js CHANGED
@@ -3044,6 +3044,10 @@ var DEFAULT_POLL_MS2 = 5e3;
3044
3044
  var MAX_BACKOFF_MS = 3e4;
3045
3045
  var backoffFor = (failures, base4) => Math.min(base4 * 2 ** Math.min(failures, 5), MAX_BACKOFF_MS);
3046
3046
  var DEFAULT_TIMEOUT_MS2 = 15 * 60 * 1e3;
3047
+ var NOT_FOUND_GRACE_MS = 2 * 60 * 1e3;
3048
+ function isNotFound(error) {
3049
+ return error instanceof OwneyError && error.details?.statusCode === 404;
3050
+ }
3047
3051
  async function runFusionOrder(deps, options) {
3048
3052
  const {
3049
3053
  orderHash,
@@ -3054,6 +3058,7 @@ async function runFusionOrder(deps, options) {
3054
3058
  } = options;
3055
3059
  const deadline = deps.now() + timeoutMs;
3056
3060
  let failures = 0;
3061
+ let notFoundSince;
3057
3062
  const published = /* @__PURE__ */ new Set();
3058
3063
  onStage?.("swapping");
3059
3064
  for (; ; ) {
@@ -3095,7 +3100,20 @@ async function runFusionOrder(deps, options) {
3095
3100
  try {
3096
3101
  ({ status } = await deps.orderStatus(orderHash));
3097
3102
  failures = 0;
3098
- } catch {
3103
+ notFoundSince = void 0;
3104
+ } catch (error) {
3105
+ if (isNotFound(error)) {
3106
+ notFoundSince ??= deps.now();
3107
+ if (deps.now() - notFoundSince >= NOT_FOUND_GRACE_MS) {
3108
+ throw new OwneyError(
3109
+ "SWAP_ORDER_NOT_FOUND",
3110
+ "The swap provider has no record of this order, so nothing was exchanged.",
3111
+ { orderHash }
3112
+ );
3113
+ }
3114
+ } else {
3115
+ notFoundSince = void 0;
3116
+ }
3099
3117
  failures += 1;
3100
3118
  await deps.sleep(backoffFor(failures, pollIntervalMs));
3101
3119
  continue;
@@ -3153,9 +3171,9 @@ async function runSameChainOrder(deps, options) {
3153
3171
  for (; ; ) {
3154
3172
  if (deps.now() >= deadline) {
3155
3173
  throw new OwneyError(
3156
- "SWAP_ORDER_EXPIRED",
3157
- "No one filled the swap in time. Nothing was exchanged and your funds are still in your wallet.",
3158
- { orderHash }
3174
+ "SWAP_REQUEST_FAILED",
3175
+ "Timed out waiting for the swap to fill. It may still complete \u2014 if it does, the swapped funds will be in your wallet. Check before retrying.",
3176
+ { orderHash, settlementUnconfirmed: true }
3159
3177
  );
3160
3178
  }
3161
3179
  let status;
@@ -3503,10 +3521,16 @@ async function runFusion(deps, options, walletAddress) {
3503
3521
  debugLog("owney-sdk", "swap: awaiting signature in wallet", {
3504
3522
  signingOnChain: quote.src.chainId
3505
3523
  });
3506
- const signature = await awaitWalletPrompt(
3507
- () => deps.signTypedData(built.typedData),
3508
- "sign the swap"
3509
- );
3524
+ let signature;
3525
+ try {
3526
+ signature = await awaitWalletPrompt(
3527
+ () => deps.signTypedData(built.typedData),
3528
+ "sign the swap"
3529
+ );
3530
+ } catch (error) {
3531
+ clearOrder(built.orderHash);
3532
+ throw error;
3533
+ }
3510
3534
  debugLog("owney-sdk", "swap: signed, submitting to relayer");
3511
3535
  await deps.api.submitOrder({
3512
3536
  srcChainId: quote.src.chainId,
@@ -3534,7 +3558,7 @@ async function runFusion(deps, options, walletAddress) {
3534
3558
  ...onStage ? { onStage } : {}
3535
3559
  });
3536
3560
  } catch (error) {
3537
- if (error instanceof OwneyError && (error.code === "SWAP_ORDER_REFUNDED" || error.code === "SWAP_ORDER_CANCELLED")) {
3561
+ if (error instanceof OwneyError && (error.code === "SWAP_ORDER_REFUNDED" || error.code === "SWAP_ORDER_CANCELLED" || error.code === "SWAP_ORDER_NOT_FOUND")) {
3538
3562
  clearOrder(built.orderHash);
3539
3563
  }
3540
3564
  throw error;
@@ -5780,7 +5804,7 @@ var OwneySDK = class {
5780
5804
  status: "completed"
5781
5805
  });
5782
5806
  } catch (error) {
5783
- if (error instanceof OwneyError && (error.code === "SWAP_ORDER_REFUNDED" || error.code === "SWAP_ORDER_CANCELLED")) {
5807
+ if (error instanceof OwneyError && (error.code === "SWAP_ORDER_REFUNDED" || error.code === "SWAP_ORDER_CANCELLED" || error.code === "SWAP_ORDER_NOT_FOUND")) {
5784
5808
  clearOrder(order.orderHash);
5785
5809
  updateWithdrawSwap(order.orderHash, { status: "refunded" });
5786
5810
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.7.28-beta.3",
3
+ "version": "0.7.28-beta.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",