@owney/sdk 0.6.8-beta.1 → 0.6.8-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
@@ -1051,7 +1051,14 @@ var ZyfaiAgent = class {
1051
1051
  amount
1052
1052
  );
1053
1053
  const tokenAddress = asset === "WETH" ? WETH_ADDRESS_BY_CHAIN[validChainId] : void 0;
1054
- await (tokenAddress ? this.sdk.logDeposit(validChainId, txHash, amount, tokenAddress) : this.sdk.logDeposit(validChainId, txHash, amount));
1054
+ try {
1055
+ await (tokenAddress ? this.sdk.logDeposit(validChainId, txHash, amount, tokenAddress) : this.sdk.logDeposit(validChainId, txHash, amount));
1056
+ } catch (logError) {
1057
+ console.warn(
1058
+ "[owney-sdk] Deposit landed on-chain but logDeposit failed (non-fatal):",
1059
+ logError
1060
+ );
1061
+ }
1055
1062
  return { txHash, smartWallet: wallet.address, amount };
1056
1063
  }
1057
1064
  const raw = await this.sdk.depositFunds(
@@ -1533,18 +1540,29 @@ function makeSponsoredDepositCallback(deps) {
1533
1540
  const wallet = deps.getWalletClient(cid);
1534
1541
  const { tokenName, tokenVersion } = await readTokenMeta(pub, token);
1535
1542
  const validAfter = 0n;
1536
- const validBefore = BigInt(Math.floor(Date.now() / 1e3) + AUTH_WINDOW_SECONDS);
1543
+ const validBefore = BigInt(
1544
+ Math.floor(Date.now() / 1e3) + AUTH_WINDOW_SECONDS
1545
+ );
1537
1546
  const nonce = randomAuthNonce();
1538
1547
  const typedData = buildTransferWithAuthorizationTypedData({
1539
1548
  token,
1540
1549
  chainId: cid,
1541
1550
  tokenName,
1542
1551
  tokenVersion,
1543
- message: { from: deps.ownerAddress, to: smartWallet, value: BigInt(amount), validAfter, validBefore, nonce }
1552
+ message: {
1553
+ from: deps.ownerAddress,
1554
+ to: smartWallet,
1555
+ value: BigInt(amount),
1556
+ validAfter,
1557
+ validBefore,
1558
+ nonce
1559
+ }
1544
1560
  });
1545
- const authSignature = await wallet.signTypedData(
1546
- { account: deps.ownerAddress, ...typedData }
1547
- );
1561
+ const authSignature = await wallet.signTypedData({
1562
+ account: deps.ownerAddress,
1563
+ ...typedData
1564
+ });
1565
+ deps.onApproved?.();
1548
1566
  const result = await post({
1549
1567
  baseUrl: deps.baseUrl,
1550
1568
  apiKey: deps.apiKey,
@@ -1628,7 +1646,10 @@ function makeSponsoredWethCallback(deps) {
1628
1646
  const cid = chainId;
1629
1647
  const token = deps.tokenAddressByChain[cid];
1630
1648
  if (!token) {
1631
- throw new OwneyError("CHAIN_UNSUPPORTED", `No sponsored WETH configured for chain ${chainId}`);
1649
+ throw new OwneyError(
1650
+ "CHAIN_UNSUPPORTED",
1651
+ `No sponsored WETH configured for chain ${chainId}`
1652
+ );
1632
1653
  }
1633
1654
  const amountWei = BigInt(amount);
1634
1655
  const pub = deps.getPublicClient(cid);
@@ -1640,9 +1661,15 @@ function makeSponsoredWethCallback(deps) {
1640
1661
  { token, chainId: cid, allowance: allowance.toString(), amount }
1641
1662
  );
1642
1663
  }
1643
- const relayer = await get({ baseUrl: deps.baseUrl, apiKey: deps.apiKey, chainId: cid });
1664
+ const relayer = await get({
1665
+ baseUrl: deps.baseUrl,
1666
+ apiKey: deps.apiKey,
1667
+ chainId: cid
1668
+ });
1644
1669
  const nonce = randomPermit2Nonce();
1645
- const deadline = BigInt(Math.floor(Date.now() / 1e3) + PERMIT_WINDOW_SECONDS);
1670
+ const deadline = BigInt(
1671
+ Math.floor(Date.now() / 1e3) + PERMIT_WINDOW_SECONDS
1672
+ );
1646
1673
  const typedData = buildPermitTransferFromTypedData({
1647
1674
  chainId: cid,
1648
1675
  message: {
@@ -1653,9 +1680,11 @@ function makeSponsoredWethCallback(deps) {
1653
1680
  }
1654
1681
  });
1655
1682
  const wallet = deps.getWalletClient(cid);
1656
- const signature = await wallet.signTypedData(
1657
- { account: deps.ownerAddress, ...typedData }
1658
- );
1683
+ const signature = await wallet.signTypedData({
1684
+ account: deps.ownerAddress,
1685
+ ...typedData
1686
+ });
1687
+ deps.onApproved?.();
1659
1688
  const result = await post({
1660
1689
  baseUrl: deps.baseUrl,
1661
1690
  apiKey: deps.apiKey,
@@ -1818,14 +1847,16 @@ var OwneySDK = class {
1818
1847
  * provider with viem `custom(provider)` to read token meta and sign the
1819
1848
  * `TransferWithAuthorization`, then POSTs to the sponsor API.
1820
1849
  */
1821
- getDefaultSponsoredCallback() {
1822
- if (this.cachedSponsoredCallback) return this.cachedSponsoredCallback;
1850
+ getDefaultSponsoredCallback(onApproved) {
1851
+ if (!onApproved && this.cachedSponsoredCallback)
1852
+ return this.cachedSponsoredCallback;
1823
1853
  const provider = this.requireConnectedProvider();
1824
1854
  const owner = this.state.walletAddress;
1825
- this.cachedSponsoredCallback = makeSponsoredDepositCallback({
1855
+ const callback = makeSponsoredDepositCallback({
1826
1856
  apiKey: this.apiKey,
1827
1857
  baseUrl: this.routingApiBaseUrl,
1828
1858
  ownerAddress: owner,
1859
+ onApproved,
1829
1860
  tokenAddressByChain: SPONSORED_USDC_BY_CHAIN,
1830
1861
  // Casts work around viem's chain-narrowed Client vs the generic
1831
1862
  // PublicClient/WalletClient param types — structurally identical at
@@ -1840,7 +1871,8 @@ var OwneySDK = class {
1840
1871
  transport: (0, import_viem5.custom)(provider)
1841
1872
  })
1842
1873
  });
1843
- return this.cachedSponsoredCallback;
1874
+ if (!onApproved) this.cachedSponsoredCallback = callback;
1875
+ return callback;
1844
1876
  }
1845
1877
  /**
1846
1878
  * Lazily builds (and caches) the default Permit2 sponsored WETH deposit
@@ -1848,15 +1880,16 @@ var OwneySDK = class {
1848
1880
  * deposit. Mirrors `getDefaultSponsoredCallback()` but signs a Permit2
1849
1881
  * `PermitTransferFrom` instead of an EIP-3009 authorization.
1850
1882
  */
1851
- getDefaultWethSponsoredCallback() {
1852
- if (this.cachedWethSponsoredCallback)
1883
+ getDefaultWethSponsoredCallback(onApproved) {
1884
+ if (!onApproved && this.cachedWethSponsoredCallback)
1853
1885
  return this.cachedWethSponsoredCallback;
1854
1886
  const provider = this.requireConnectedProvider();
1855
1887
  const owner = this.state.walletAddress;
1856
- this.cachedWethSponsoredCallback = makeSponsoredWethCallback({
1888
+ const callback = makeSponsoredWethCallback({
1857
1889
  apiKey: this.apiKey,
1858
1890
  baseUrl: this.routingApiBaseUrl,
1859
1891
  ownerAddress: owner,
1892
+ onApproved,
1860
1893
  tokenAddressByChain: SPONSORED_WETH_BY_CHAIN,
1861
1894
  // Casts work around viem's chain-narrowed Client vs the generic
1862
1895
  // PublicClient/WalletClient param types — structurally identical at
@@ -1871,7 +1904,8 @@ var OwneySDK = class {
1871
1904
  transport: (0, import_viem5.custom)(provider)
1872
1905
  })
1873
1906
  });
1874
- return this.cachedWethSponsoredCallback;
1907
+ if (!onApproved) this.cachedWethSponsoredCallback = callback;
1908
+ return callback;
1875
1909
  }
1876
1910
  getAgent(agentId) {
1877
1911
  const agent = this.agents.get(agentId);
@@ -2017,13 +2051,13 @@ var OwneySDK = class {
2017
2051
  * @returns {OwneyDepositResult} for a single agent, or {OwneyMultiDepositResult} with per-agent results
2018
2052
  */
2019
2053
  async deposit(options) {
2020
- const { amount, asset, depositCallback, agentId } = options;
2054
+ const { amount, asset, depositCallback, agentId, onApproved } = options;
2021
2055
  if (BigInt(amount) === 0n) {
2022
2056
  return { agentResults: {} };
2023
2057
  }
2024
2058
  const state = this.requireState();
2025
2059
  const chainId = this.requireChainId();
2026
- const effectiveCallback = depositCallback ?? (asset === "WETH" ? this.getDefaultWethSponsoredCallback() : this.getDefaultSponsoredCallback());
2060
+ const effectiveCallback = depositCallback ?? (asset === "WETH" ? this.getDefaultWethSponsoredCallback(onApproved) : this.getDefaultSponsoredCallback(onApproved));
2027
2061
  if (agentId) {
2028
2062
  if (this.isAgentDisabled(agentId)) {
2029
2063
  throw new OwneyError(
package/dist/index.d.cts CHANGED
@@ -98,6 +98,7 @@ type DepositOptions = {
98
98
  asset: Asset;
99
99
  depositCallback?: DepositCallback;
100
100
  agentId?: AgentId;
101
+ onApproved?: () => void;
101
102
  };
102
103
 
103
104
  interface OwneyDepositResult {
package/dist/index.d.ts CHANGED
@@ -98,6 +98,7 @@ type DepositOptions = {
98
98
  asset: Asset;
99
99
  depositCallback?: DepositCallback;
100
100
  agentId?: AgentId;
101
+ onApproved?: () => void;
101
102
  };
102
103
 
103
104
  interface OwneyDepositResult {
package/dist/index.js CHANGED
@@ -1019,7 +1019,14 @@ var ZyfaiAgent = class {
1019
1019
  amount
1020
1020
  );
1021
1021
  const tokenAddress = asset === "WETH" ? WETH_ADDRESS_BY_CHAIN[validChainId] : void 0;
1022
- await (tokenAddress ? this.sdk.logDeposit(validChainId, txHash, amount, tokenAddress) : this.sdk.logDeposit(validChainId, txHash, amount));
1022
+ try {
1023
+ await (tokenAddress ? this.sdk.logDeposit(validChainId, txHash, amount, tokenAddress) : this.sdk.logDeposit(validChainId, txHash, amount));
1024
+ } catch (logError) {
1025
+ console.warn(
1026
+ "[owney-sdk] Deposit landed on-chain but logDeposit failed (non-fatal):",
1027
+ logError
1028
+ );
1029
+ }
1023
1030
  return { txHash, smartWallet: wallet.address, amount };
1024
1031
  }
1025
1032
  const raw = await this.sdk.depositFunds(
@@ -1505,18 +1512,29 @@ function makeSponsoredDepositCallback(deps) {
1505
1512
  const wallet = deps.getWalletClient(cid);
1506
1513
  const { tokenName, tokenVersion } = await readTokenMeta(pub, token);
1507
1514
  const validAfter = 0n;
1508
- const validBefore = BigInt(Math.floor(Date.now() / 1e3) + AUTH_WINDOW_SECONDS);
1515
+ const validBefore = BigInt(
1516
+ Math.floor(Date.now() / 1e3) + AUTH_WINDOW_SECONDS
1517
+ );
1509
1518
  const nonce = randomAuthNonce();
1510
1519
  const typedData = buildTransferWithAuthorizationTypedData({
1511
1520
  token,
1512
1521
  chainId: cid,
1513
1522
  tokenName,
1514
1523
  tokenVersion,
1515
- message: { from: deps.ownerAddress, to: smartWallet, value: BigInt(amount), validAfter, validBefore, nonce }
1524
+ message: {
1525
+ from: deps.ownerAddress,
1526
+ to: smartWallet,
1527
+ value: BigInt(amount),
1528
+ validAfter,
1529
+ validBefore,
1530
+ nonce
1531
+ }
1516
1532
  });
1517
- const authSignature = await wallet.signTypedData(
1518
- { account: deps.ownerAddress, ...typedData }
1519
- );
1533
+ const authSignature = await wallet.signTypedData({
1534
+ account: deps.ownerAddress,
1535
+ ...typedData
1536
+ });
1537
+ deps.onApproved?.();
1520
1538
  const result = await post({
1521
1539
  baseUrl: deps.baseUrl,
1522
1540
  apiKey: deps.apiKey,
@@ -1600,7 +1618,10 @@ function makeSponsoredWethCallback(deps) {
1600
1618
  const cid = chainId;
1601
1619
  const token = deps.tokenAddressByChain[cid];
1602
1620
  if (!token) {
1603
- throw new OwneyError("CHAIN_UNSUPPORTED", `No sponsored WETH configured for chain ${chainId}`);
1621
+ throw new OwneyError(
1622
+ "CHAIN_UNSUPPORTED",
1623
+ `No sponsored WETH configured for chain ${chainId}`
1624
+ );
1604
1625
  }
1605
1626
  const amountWei = BigInt(amount);
1606
1627
  const pub = deps.getPublicClient(cid);
@@ -1612,9 +1633,15 @@ function makeSponsoredWethCallback(deps) {
1612
1633
  { token, chainId: cid, allowance: allowance.toString(), amount }
1613
1634
  );
1614
1635
  }
1615
- const relayer = await get({ baseUrl: deps.baseUrl, apiKey: deps.apiKey, chainId: cid });
1636
+ const relayer = await get({
1637
+ baseUrl: deps.baseUrl,
1638
+ apiKey: deps.apiKey,
1639
+ chainId: cid
1640
+ });
1616
1641
  const nonce = randomPermit2Nonce();
1617
- const deadline = BigInt(Math.floor(Date.now() / 1e3) + PERMIT_WINDOW_SECONDS);
1642
+ const deadline = BigInt(
1643
+ Math.floor(Date.now() / 1e3) + PERMIT_WINDOW_SECONDS
1644
+ );
1618
1645
  const typedData = buildPermitTransferFromTypedData({
1619
1646
  chainId: cid,
1620
1647
  message: {
@@ -1625,9 +1652,11 @@ function makeSponsoredWethCallback(deps) {
1625
1652
  }
1626
1653
  });
1627
1654
  const wallet = deps.getWalletClient(cid);
1628
- const signature = await wallet.signTypedData(
1629
- { account: deps.ownerAddress, ...typedData }
1630
- );
1655
+ const signature = await wallet.signTypedData({
1656
+ account: deps.ownerAddress,
1657
+ ...typedData
1658
+ });
1659
+ deps.onApproved?.();
1631
1660
  const result = await post({
1632
1661
  baseUrl: deps.baseUrl,
1633
1662
  apiKey: deps.apiKey,
@@ -1790,14 +1819,16 @@ var OwneySDK = class {
1790
1819
  * provider with viem `custom(provider)` to read token meta and sign the
1791
1820
  * `TransferWithAuthorization`, then POSTs to the sponsor API.
1792
1821
  */
1793
- getDefaultSponsoredCallback() {
1794
- if (this.cachedSponsoredCallback) return this.cachedSponsoredCallback;
1822
+ getDefaultSponsoredCallback(onApproved) {
1823
+ if (!onApproved && this.cachedSponsoredCallback)
1824
+ return this.cachedSponsoredCallback;
1795
1825
  const provider = this.requireConnectedProvider();
1796
1826
  const owner = this.state.walletAddress;
1797
- this.cachedSponsoredCallback = makeSponsoredDepositCallback({
1827
+ const callback = makeSponsoredDepositCallback({
1798
1828
  apiKey: this.apiKey,
1799
1829
  baseUrl: this.routingApiBaseUrl,
1800
1830
  ownerAddress: owner,
1831
+ onApproved,
1801
1832
  tokenAddressByChain: SPONSORED_USDC_BY_CHAIN,
1802
1833
  // Casts work around viem's chain-narrowed Client vs the generic
1803
1834
  // PublicClient/WalletClient param types — structurally identical at
@@ -1812,7 +1843,8 @@ var OwneySDK = class {
1812
1843
  transport: custom(provider)
1813
1844
  })
1814
1845
  });
1815
- return this.cachedSponsoredCallback;
1846
+ if (!onApproved) this.cachedSponsoredCallback = callback;
1847
+ return callback;
1816
1848
  }
1817
1849
  /**
1818
1850
  * Lazily builds (and caches) the default Permit2 sponsored WETH deposit
@@ -1820,15 +1852,16 @@ var OwneySDK = class {
1820
1852
  * deposit. Mirrors `getDefaultSponsoredCallback()` but signs a Permit2
1821
1853
  * `PermitTransferFrom` instead of an EIP-3009 authorization.
1822
1854
  */
1823
- getDefaultWethSponsoredCallback() {
1824
- if (this.cachedWethSponsoredCallback)
1855
+ getDefaultWethSponsoredCallback(onApproved) {
1856
+ if (!onApproved && this.cachedWethSponsoredCallback)
1825
1857
  return this.cachedWethSponsoredCallback;
1826
1858
  const provider = this.requireConnectedProvider();
1827
1859
  const owner = this.state.walletAddress;
1828
- this.cachedWethSponsoredCallback = makeSponsoredWethCallback({
1860
+ const callback = makeSponsoredWethCallback({
1829
1861
  apiKey: this.apiKey,
1830
1862
  baseUrl: this.routingApiBaseUrl,
1831
1863
  ownerAddress: owner,
1864
+ onApproved,
1832
1865
  tokenAddressByChain: SPONSORED_WETH_BY_CHAIN,
1833
1866
  // Casts work around viem's chain-narrowed Client vs the generic
1834
1867
  // PublicClient/WalletClient param types — structurally identical at
@@ -1843,7 +1876,8 @@ var OwneySDK = class {
1843
1876
  transport: custom(provider)
1844
1877
  })
1845
1878
  });
1846
- return this.cachedWethSponsoredCallback;
1879
+ if (!onApproved) this.cachedWethSponsoredCallback = callback;
1880
+ return callback;
1847
1881
  }
1848
1882
  getAgent(agentId) {
1849
1883
  const agent = this.agents.get(agentId);
@@ -1989,13 +2023,13 @@ var OwneySDK = class {
1989
2023
  * @returns {OwneyDepositResult} for a single agent, or {OwneyMultiDepositResult} with per-agent results
1990
2024
  */
1991
2025
  async deposit(options) {
1992
- const { amount, asset, depositCallback, agentId } = options;
2026
+ const { amount, asset, depositCallback, agentId, onApproved } = options;
1993
2027
  if (BigInt(amount) === 0n) {
1994
2028
  return { agentResults: {} };
1995
2029
  }
1996
2030
  const state = this.requireState();
1997
2031
  const chainId = this.requireChainId();
1998
- const effectiveCallback = depositCallback ?? (asset === "WETH" ? this.getDefaultWethSponsoredCallback() : this.getDefaultSponsoredCallback());
2032
+ const effectiveCallback = depositCallback ?? (asset === "WETH" ? this.getDefaultWethSponsoredCallback(onApproved) : this.getDefaultSponsoredCallback(onApproved));
1999
2033
  if (agentId) {
2000
2034
  if (this.isAgentDisabled(agentId)) {
2001
2035
  throw new OwneyError(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.6.8-beta.1",
3
+ "version": "0.6.8-beta.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",