@owney/sdk 0.7.26-beta.8 → 0.7.26

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/README.md CHANGED
@@ -134,6 +134,13 @@ Deposit funds into a specific agent, or split equally across all agents if `agen
134
134
  | `options.depositCallback` | `DepositCallback` | Callback that performs the token transfer and returns a tx hash |
135
135
  | `options.agentId` | `AgentId` (optional) | Target agent. Omit to split equally across all agents. |
136
136
 
137
+ Zyfai's native transfer path uses `sendDeposit()`. It returns after the token
138
+ transfer confirms and the deposit is registered, while balance credit may still
139
+ be queued. Balance reads reflect subsequent credit and allocation; the deposit
140
+ call does not wait for `waitForDepositCredit()`.
141
+ A successful deposit result confirms the transfer; it does not guarantee that
142
+ the funds are already credited or earning yield.
143
+
137
144
  Returns: `OwneyDepositResult` (single agent) or `OwneyMultiDepositResult` (all agents)
138
145
 
139
146
  ```typescript
package/dist/index.cjs CHANGED
@@ -1352,7 +1352,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
1352
1352
  * chain/account switch fires the provider's `accountsChanged` →
1353
1353
  * `disconnectAccount` (nulls walletClient + authenticatedUserId) while our
1354
1354
  * own `connectAuth` guard still believes this chain is connected and
1355
- * early-returns. Without this, authenticated calls (depositFunds,
1355
+ * early-returns. Without this, authenticated calls (sendDeposit,
1356
1356
  * withdrawFunds) fail with "No account connected".
1357
1357
  */
1358
1358
  async ensureConnected(state, chainId) {
@@ -1930,7 +1930,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
1930
1930
  return { txHash, smartWallet, amount };
1931
1931
  }
1932
1932
  await this.ensureWalletDeployed(this.getAddress(), validChainId);
1933
- const raw = await this.sdk.depositFunds(
1933
+ const raw = await this.sdk.sendDeposit(
1934
1934
  this.getAddress(),
1935
1935
  validChainId,
1936
1936
  amount,
@@ -2499,9 +2499,24 @@ async function wrapNative(deps, options) {
2499
2499
  message: error instanceof Error ? error.message : String(error)
2500
2500
  });
2501
2501
  }
2502
+ let approvalPending = true;
2503
+ if (options.spender && deps.readAllowance) {
2504
+ try {
2505
+ const allowance = await deps.readAllowance(wrapper, options.spender);
2506
+ approvalPending = allowance < requested;
2507
+ } catch (error) {
2508
+ debugLog(
2509
+ "owney-sdk",
2510
+ "wrap: allowance read failed, assuming an approve",
2511
+ {
2512
+ message: error instanceof Error ? error.message : String(error)
2513
+ }
2514
+ );
2515
+ }
2516
+ }
2502
2517
  const measured = await deps.getMaxFeePerGas();
2503
2518
  const gasPrice = measured > MIN_WALLET_GAS_PRICE ? measured : MIN_WALLET_GAS_PRICE;
2504
- const reserve = (wrapGas + APPROVE_GAS) * gasPrice * GAS_SAFETY;
2519
+ const reserve = (wrapGas + (approvalPending ? APPROVE_GAS : 0n)) * gasPrice * GAS_SAFETY;
2505
2520
  const spendable = balance > reserve ? balance - reserve : 0n;
2506
2521
  const wrapped = requested < spendable ? requested : spendable;
2507
2522
  debugLog("owney-sdk", "wrap: sizing", {
@@ -2509,6 +2524,7 @@ async function wrapNative(deps, options) {
2509
2524
  requested: requested.toString(),
2510
2525
  measuredGasPrice: measured.toString(),
2511
2526
  reservedAtGasPrice: gasPrice.toString(),
2527
+ approvalPending,
2512
2528
  reserve: reserve.toString(),
2513
2529
  wrapped: wrapped.toString()
2514
2530
  });
@@ -3102,7 +3118,7 @@ async function runSameChainFusion(deps, options, walletAddress) {
3102
3118
  const isNativeSource = quote.src.address.toLowerCase().startsWith("0xeeee");
3103
3119
  const amount = isNativeSource ? BigInt(quote.src.amount) : await affordableAmount(deps, BigInt(quote.src.amount));
3104
3120
  const permit = await authoriseSpend(deps, options, amount, isNativeSource);
3105
- onStage?.("quoting");
3121
+ onStage?.("building");
3106
3122
  debugLog("owney-sdk", "swap: building same-chain fusion order");
3107
3123
  const built = await deps.api.buildOrder({
3108
3124
  from: {
@@ -3184,7 +3200,7 @@ async function runFusion(deps, options, walletAddress) {
3184
3200
  const amount = await affordableAmount(deps, BigInt(quote.src.amount));
3185
3201
  const permit = await authoriseSpend(deps, options, amount, false);
3186
3202
  const { secrets, secretHashes } = mintSecrets(quote.secretsCount ?? 1);
3187
- onStage?.("quoting");
3203
+ onStage?.("building");
3188
3204
  debugLog("owney-sdk", "swap: building fusion order", {
3189
3205
  secrets: secretHashes.length
3190
3206
  });
@@ -5012,13 +5028,25 @@ var OwneySDK = class {
5012
5028
  }
5013
5029
  return hash;
5014
5030
  },
5015
- ensureChain: (id) => this.ensureSwapChain(id)
5031
+ ensureChain: (id) => this.ensureSwapChain(id),
5032
+ // Read through the same public client as every other sizing input, so
5033
+ // a wallet sitting on the wrong chain cannot answer for this one.
5034
+ readAllowance: (token, spender) => publicClient.readContract({
5035
+ address: token,
5036
+ abi: ERC20_ALLOWANCE_ABI,
5037
+ functionName: "allowance",
5038
+ args: [walletAddress, spender]
5039
+ })
5016
5040
  },
5017
5041
  {
5018
5042
  chainId,
5019
5043
  wrapper: wrapper.address,
5020
5044
  nativeSymbol: quote.src.symbol,
5021
5045
  requested: BigInt(quote.src.amount),
5046
+ // Lets the reserve skip the approve's gas when one is already in
5047
+ // place. Absent on a quote that names no spender, which keeps the
5048
+ // full reserve (ROUT-242, comment 16234).
5049
+ ...quote.spender ? { spender: quote.spender } : {},
5022
5050
  onSubmitted: () => onStage?.("wrapped")
5023
5051
  }
5024
5052
  );
package/dist/index.d.cts CHANGED
@@ -220,7 +220,7 @@ type SwapOrderStatus = "pending" | "executed" | "expired" | "cancelled" | "refun
220
220
  * of the flow and the one place a user would otherwise think nothing is
221
221
  * happening.
222
222
  */
223
- type SwapStage = "withdrawing" | "withdrawn" | "quoting" | "wrapping" | "wrapped" | "approving" | "signing" | "swapping" | "swapped" | "depositing" | "refunding" | "refunded";
223
+ type SwapStage = "withdrawing" | "withdrawn" | "quoting" | "wrapping" | "wrapped" | "approving" | "building" | "signing" | "swapping" | "swapped" | "depositing" | "refunding" | "refunded";
224
224
  /**
225
225
  * Which way the funds travel, which decides what each side may be.
226
226
  *
package/dist/index.d.ts CHANGED
@@ -220,7 +220,7 @@ type SwapOrderStatus = "pending" | "executed" | "expired" | "cancelled" | "refun
220
220
  * of the flow and the one place a user would otherwise think nothing is
221
221
  * happening.
222
222
  */
223
- type SwapStage = "withdrawing" | "withdrawn" | "quoting" | "wrapping" | "wrapped" | "approving" | "signing" | "swapping" | "swapped" | "depositing" | "refunding" | "refunded";
223
+ type SwapStage = "withdrawing" | "withdrawn" | "quoting" | "wrapping" | "wrapped" | "approving" | "building" | "signing" | "swapping" | "swapped" | "depositing" | "refunding" | "refunded";
224
224
  /**
225
225
  * Which way the funds travel, which decides what each side may be.
226
226
  *
package/dist/index.js CHANGED
@@ -1312,7 +1312,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
1312
1312
  * chain/account switch fires the provider's `accountsChanged` →
1313
1313
  * `disconnectAccount` (nulls walletClient + authenticatedUserId) while our
1314
1314
  * own `connectAuth` guard still believes this chain is connected and
1315
- * early-returns. Without this, authenticated calls (depositFunds,
1315
+ * early-returns. Without this, authenticated calls (sendDeposit,
1316
1316
  * withdrawFunds) fail with "No account connected".
1317
1317
  */
1318
1318
  async ensureConnected(state, chainId) {
@@ -1890,7 +1890,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
1890
1890
  return { txHash, smartWallet, amount };
1891
1891
  }
1892
1892
  await this.ensureWalletDeployed(this.getAddress(), validChainId);
1893
- const raw = await this.sdk.depositFunds(
1893
+ const raw = await this.sdk.sendDeposit(
1894
1894
  this.getAddress(),
1895
1895
  validChainId,
1896
1896
  amount,
@@ -2459,9 +2459,24 @@ async function wrapNative(deps, options) {
2459
2459
  message: error instanceof Error ? error.message : String(error)
2460
2460
  });
2461
2461
  }
2462
+ let approvalPending = true;
2463
+ if (options.spender && deps.readAllowance) {
2464
+ try {
2465
+ const allowance = await deps.readAllowance(wrapper, options.spender);
2466
+ approvalPending = allowance < requested;
2467
+ } catch (error) {
2468
+ debugLog(
2469
+ "owney-sdk",
2470
+ "wrap: allowance read failed, assuming an approve",
2471
+ {
2472
+ message: error instanceof Error ? error.message : String(error)
2473
+ }
2474
+ );
2475
+ }
2476
+ }
2462
2477
  const measured = await deps.getMaxFeePerGas();
2463
2478
  const gasPrice = measured > MIN_WALLET_GAS_PRICE ? measured : MIN_WALLET_GAS_PRICE;
2464
- const reserve = (wrapGas + APPROVE_GAS) * gasPrice * GAS_SAFETY;
2479
+ const reserve = (wrapGas + (approvalPending ? APPROVE_GAS : 0n)) * gasPrice * GAS_SAFETY;
2465
2480
  const spendable = balance > reserve ? balance - reserve : 0n;
2466
2481
  const wrapped = requested < spendable ? requested : spendable;
2467
2482
  debugLog("owney-sdk", "wrap: sizing", {
@@ -2469,6 +2484,7 @@ async function wrapNative(deps, options) {
2469
2484
  requested: requested.toString(),
2470
2485
  measuredGasPrice: measured.toString(),
2471
2486
  reservedAtGasPrice: gasPrice.toString(),
2487
+ approvalPending,
2472
2488
  reserve: reserve.toString(),
2473
2489
  wrapped: wrapped.toString()
2474
2490
  });
@@ -3072,7 +3088,7 @@ async function runSameChainFusion(deps, options, walletAddress) {
3072
3088
  const isNativeSource = quote.src.address.toLowerCase().startsWith("0xeeee");
3073
3089
  const amount = isNativeSource ? BigInt(quote.src.amount) : await affordableAmount(deps, BigInt(quote.src.amount));
3074
3090
  const permit = await authoriseSpend(deps, options, amount, isNativeSource);
3075
- onStage?.("quoting");
3091
+ onStage?.("building");
3076
3092
  debugLog("owney-sdk", "swap: building same-chain fusion order");
3077
3093
  const built = await deps.api.buildOrder({
3078
3094
  from: {
@@ -3154,7 +3170,7 @@ async function runFusion(deps, options, walletAddress) {
3154
3170
  const amount = await affordableAmount(deps, BigInt(quote.src.amount));
3155
3171
  const permit = await authoriseSpend(deps, options, amount, false);
3156
3172
  const { secrets, secretHashes } = mintSecrets(quote.secretsCount ?? 1);
3157
- onStage?.("quoting");
3173
+ onStage?.("building");
3158
3174
  debugLog("owney-sdk", "swap: building fusion order", {
3159
3175
  secrets: secretHashes.length
3160
3176
  });
@@ -4993,13 +5009,25 @@ var OwneySDK = class {
4993
5009
  }
4994
5010
  return hash;
4995
5011
  },
4996
- ensureChain: (id) => this.ensureSwapChain(id)
5012
+ ensureChain: (id) => this.ensureSwapChain(id),
5013
+ // Read through the same public client as every other sizing input, so
5014
+ // a wallet sitting on the wrong chain cannot answer for this one.
5015
+ readAllowance: (token, spender) => publicClient.readContract({
5016
+ address: token,
5017
+ abi: ERC20_ALLOWANCE_ABI,
5018
+ functionName: "allowance",
5019
+ args: [walletAddress, spender]
5020
+ })
4997
5021
  },
4998
5022
  {
4999
5023
  chainId,
5000
5024
  wrapper: wrapper.address,
5001
5025
  nativeSymbol: quote.src.symbol,
5002
5026
  requested: BigInt(quote.src.amount),
5027
+ // Lets the reserve skip the approve's gas when one is already in
5028
+ // place. Absent on a quote that names no spender, which keeps the
5029
+ // full reserve (ROUT-242, comment 16234).
5030
+ ...quote.spender ? { spender: quote.spender } : {},
5003
5031
  onSubmitted: () => onStage?.("wrapped")
5004
5032
  }
5005
5033
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.7.26-beta.8",
3
+ "version": "0.7.26",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "test:watch": "vitest"
24
24
  },
25
25
  "dependencies": {
26
- "@zyfai/sdk": "0.2.55",
26
+ "@zyfai/sdk": "0.3.1",
27
27
  "siwe": "^3.0.0",
28
28
  "viem": "^2.48.1"
29
29
  },