@owney/sdk 0.7.4 → 0.7.5

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
@@ -2001,6 +2001,41 @@ async function readErc20Balance(publicClient, token, owner) {
2001
2001
  });
2002
2002
  }
2003
2003
 
2004
+ // src/lib/chain-guard.ts
2005
+ var CHAIN_NAMES = {
2006
+ 1: "Ethereum",
2007
+ 8453: "Base",
2008
+ 42161: "Arbitrum"
2009
+ };
2010
+ function chainName(chainId) {
2011
+ return CHAIN_NAMES[chainId] ?? `chain ${chainId}`;
2012
+ }
2013
+ async function ensureWalletOnChain(pub, wallet, expected) {
2014
+ const actual = await pub.getChainId();
2015
+ if (actual === expected) return;
2016
+ try {
2017
+ await wallet.switchChain({ id: expected });
2018
+ } catch (error) {
2019
+ throw new OwneyError(
2020
+ "CHAIN_MISMATCH",
2021
+ `Your wallet is on ${chainName(actual)}. Switch it to ${chainName(expected)} and try again.`,
2022
+ {
2023
+ expectedChainId: expected,
2024
+ actualChainId: actual,
2025
+ cause: error instanceof Error ? error.message : String(error)
2026
+ }
2027
+ );
2028
+ }
2029
+ const after = await pub.getChainId();
2030
+ if (after !== expected) {
2031
+ throw new OwneyError(
2032
+ "CHAIN_MISMATCH",
2033
+ `Your wallet is still on ${chainName(after)}. Switch it to ${chainName(expected)} and try again.`,
2034
+ { expectedChainId: expected, actualChainId: after }
2035
+ );
2036
+ }
2037
+ }
2038
+
2004
2039
  // src/lib/sponsored-deposit.ts
2005
2040
  var AUTH_WINDOW_SECONDS = 15 * 60;
2006
2041
  function makeSponsoredDepositCallback(deps) {
@@ -2016,6 +2051,7 @@ function makeSponsoredDepositCallback(deps) {
2016
2051
  }
2017
2052
  const pub = deps.getPublicClient(cid);
2018
2053
  const wallet = deps.getWalletClient(cid);
2054
+ await ensureWalletOnChain(pub, wallet, cid);
2019
2055
  try {
2020
2056
  const balance = await readErc20Balance(pub, token, deps.ownerAddress);
2021
2057
  if (balance < BigInt(amount)) {
@@ -2027,6 +2063,10 @@ function makeSponsoredDepositCallback(deps) {
2027
2063
  }
2028
2064
  } catch (err) {
2029
2065
  if (err instanceof OwneyError) throw err;
2066
+ console.warn(
2067
+ "[owney-sdk] Deposit balance pre-check failed (non-fatal):",
2068
+ err instanceof Error ? err.message : String(err)
2069
+ );
2030
2070
  }
2031
2071
  const { tokenName, tokenVersion } = await readTokenMeta(pub, token);
2032
2072
  const validAfter = 0n;
@@ -2090,6 +2130,8 @@ function makeSponsoredWethCallback(deps) {
2090
2130
  }
2091
2131
  const amountWei = BigInt(amount);
2092
2132
  const pub = deps.getPublicClient(cid);
2133
+ const wallet = deps.getWalletClient(cid);
2134
+ await ensureWalletOnChain(pub, wallet, cid);
2093
2135
  try {
2094
2136
  const balance = await readErc20Balance(pub, token, deps.ownerAddress);
2095
2137
  if (balance < amountWei) {
@@ -2101,6 +2143,10 @@ function makeSponsoredWethCallback(deps) {
2101
2143
  }
2102
2144
  } catch (err) {
2103
2145
  if (err instanceof OwneyError) throw err;
2146
+ console.warn(
2147
+ "[owney-sdk] WETH balance pre-check failed (non-fatal):",
2148
+ err instanceof Error ? err.message : String(err)
2149
+ );
2104
2150
  }
2105
2151
  const allowance = await readPermit2Allowance(pub, token, deps.ownerAddress);
2106
2152
  if (allowance < amountWei) {
@@ -2128,7 +2174,6 @@ function makeSponsoredWethCallback(deps) {
2128
2174
  deadline
2129
2175
  }
2130
2176
  });
2131
- const wallet = deps.getWalletClient(cid);
2132
2177
  const signature = await wallet.signTypedData({
2133
2178
  account: deps.ownerAddress,
2134
2179
  ...typedData
package/dist/index.d.cts CHANGED
@@ -609,7 +609,7 @@ declare class OwneySDK {
609
609
  getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
610
610
  }
611
611
 
612
- 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" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "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_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_SAIL_ERROR" | "API_SAIL_TIMEOUT" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
612
+ 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_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_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_SAIL_ERROR" | "API_SAIL_TIMEOUT" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
613
613
  declare class OwneyError extends Error {
614
614
  readonly code: OwneyErrorCode;
615
615
  readonly details?: Record<string, unknown>;
package/dist/index.d.ts CHANGED
@@ -609,7 +609,7 @@ declare class OwneySDK {
609
609
  getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
610
610
  }
611
611
 
612
- 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" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "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_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_SAIL_ERROR" | "API_SAIL_TIMEOUT" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
612
+ 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_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_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_SAIL_ERROR" | "API_SAIL_TIMEOUT" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
613
613
  declare class OwneyError extends Error {
614
614
  readonly code: OwneyErrorCode;
615
615
  readonly details?: Record<string, unknown>;
package/dist/index.js CHANGED
@@ -1972,6 +1972,41 @@ async function readErc20Balance(publicClient, token, owner) {
1972
1972
  });
1973
1973
  }
1974
1974
 
1975
+ // src/lib/chain-guard.ts
1976
+ var CHAIN_NAMES = {
1977
+ 1: "Ethereum",
1978
+ 8453: "Base",
1979
+ 42161: "Arbitrum"
1980
+ };
1981
+ function chainName(chainId) {
1982
+ return CHAIN_NAMES[chainId] ?? `chain ${chainId}`;
1983
+ }
1984
+ async function ensureWalletOnChain(pub, wallet, expected) {
1985
+ const actual = await pub.getChainId();
1986
+ if (actual === expected) return;
1987
+ try {
1988
+ await wallet.switchChain({ id: expected });
1989
+ } catch (error) {
1990
+ throw new OwneyError(
1991
+ "CHAIN_MISMATCH",
1992
+ `Your wallet is on ${chainName(actual)}. Switch it to ${chainName(expected)} and try again.`,
1993
+ {
1994
+ expectedChainId: expected,
1995
+ actualChainId: actual,
1996
+ cause: error instanceof Error ? error.message : String(error)
1997
+ }
1998
+ );
1999
+ }
2000
+ const after = await pub.getChainId();
2001
+ if (after !== expected) {
2002
+ throw new OwneyError(
2003
+ "CHAIN_MISMATCH",
2004
+ `Your wallet is still on ${chainName(after)}. Switch it to ${chainName(expected)} and try again.`,
2005
+ { expectedChainId: expected, actualChainId: after }
2006
+ );
2007
+ }
2008
+ }
2009
+
1975
2010
  // src/lib/sponsored-deposit.ts
1976
2011
  var AUTH_WINDOW_SECONDS = 15 * 60;
1977
2012
  function makeSponsoredDepositCallback(deps) {
@@ -1987,6 +2022,7 @@ function makeSponsoredDepositCallback(deps) {
1987
2022
  }
1988
2023
  const pub = deps.getPublicClient(cid);
1989
2024
  const wallet = deps.getWalletClient(cid);
2025
+ await ensureWalletOnChain(pub, wallet, cid);
1990
2026
  try {
1991
2027
  const balance = await readErc20Balance(pub, token, deps.ownerAddress);
1992
2028
  if (balance < BigInt(amount)) {
@@ -1998,6 +2034,10 @@ function makeSponsoredDepositCallback(deps) {
1998
2034
  }
1999
2035
  } catch (err) {
2000
2036
  if (err instanceof OwneyError) throw err;
2037
+ console.warn(
2038
+ "[owney-sdk] Deposit balance pre-check failed (non-fatal):",
2039
+ err instanceof Error ? err.message : String(err)
2040
+ );
2001
2041
  }
2002
2042
  const { tokenName, tokenVersion } = await readTokenMeta(pub, token);
2003
2043
  const validAfter = 0n;
@@ -2061,6 +2101,8 @@ function makeSponsoredWethCallback(deps) {
2061
2101
  }
2062
2102
  const amountWei = BigInt(amount);
2063
2103
  const pub = deps.getPublicClient(cid);
2104
+ const wallet = deps.getWalletClient(cid);
2105
+ await ensureWalletOnChain(pub, wallet, cid);
2064
2106
  try {
2065
2107
  const balance = await readErc20Balance(pub, token, deps.ownerAddress);
2066
2108
  if (balance < amountWei) {
@@ -2072,6 +2114,10 @@ function makeSponsoredWethCallback(deps) {
2072
2114
  }
2073
2115
  } catch (err) {
2074
2116
  if (err instanceof OwneyError) throw err;
2117
+ console.warn(
2118
+ "[owney-sdk] WETH balance pre-check failed (non-fatal):",
2119
+ err instanceof Error ? err.message : String(err)
2120
+ );
2075
2121
  }
2076
2122
  const allowance = await readPermit2Allowance(pub, token, deps.ownerAddress);
2077
2123
  if (allowance < amountWei) {
@@ -2099,7 +2145,6 @@ function makeSponsoredWethCallback(deps) {
2099
2145
  deadline
2100
2146
  }
2101
2147
  });
2102
- const wallet = deps.getWalletClient(cid);
2103
2148
  const signature = await wallet.signTypedData({
2104
2149
  account: deps.ownerAddress,
2105
2150
  ...typedData
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.7.4",
3
+ "version": "0.7.5",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",