anymal-protocol 1.0.118 → 1.0.120

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.mjs CHANGED
@@ -1,13 +1,18 @@
1
1
  import {
2
2
  AUTH_API_ENDPOINTS,
3
+ FIREBASE_WEB_API_KEYS,
4
+ FIREBASE_WEB_AUTH_API_ENDPOINTS,
3
5
  NETWORK_HOSTS,
4
6
  Network,
7
+ createApp,
5
8
  createAuthEnvelope,
9
+ flattenFirestoreData,
6
10
  generateAppSignature,
7
11
  generateJWT,
12
+ getFirebaseTokenForApp,
8
13
  loadExistingSecp256k1PrivateKey,
9
14
  serializePublicKeyCompressed
10
- } from "./chunk-F72KTNHS.mjs";
15
+ } from "./chunk-OBXCSRGF.mjs";
11
16
 
12
17
  // src/utils/account/useVerifyAccount.ts
13
18
  import { useCallback } from "react";
@@ -1211,35 +1216,36 @@ async function applyBundlerGasEstimator(account, bundlerClient, options) {
1211
1216
  verificationGasMultiplier = 1.2,
1212
1217
  preVerificationGasMultiplier = 2,
1213
1218
  maxCallGasPercentOfBlock = 0.1,
1214
- // 10% for now?
1215
1219
  debug = true
1216
1220
  } = options || {};
1217
1221
  const publicClient = bundlerClient.client;
1218
1222
  const blockGasLimit = (await publicClient.getBlock()).gasLimit;
1219
1223
  const dynamicCallGasCap = blockGasLimit * BigInt(Math.floor(maxCallGasPercentOfBlock * 100)) / 100n;
1220
1224
  account.userOperation = {
1225
+ ...account.userOperation,
1221
1226
  estimateGas: async (userOp) => {
1222
- const estimate = await bundlerClient.estimateUserOperationGas(userOp);
1223
- const paddedCallGasLimit = estimate.callGasLimit * BigInt(Math.ceil(callGasMultiplier * 100)) / 100n;
1224
- const cappedCallGasLimit = paddedCallGasLimit > dynamicCallGasCap ? dynamicCallGasCap : paddedCallGasLimit;
1225
- const paddedVerificationGasLimit = estimate.verificationGasLimit * BigInt(Math.ceil(verificationGasMultiplier * 100)) / 100n;
1226
- const paddedPreVerificationGas = estimate.preVerificationGas * BigInt(Math.ceil(preVerificationGasMultiplier * 100)) / 100n;
1227
- if (debug) {
1228
- console.log("\u{1F4E6} Bundler Gas Estimates:");
1229
- console.log(" blockGasLimit:", blockGasLimit.toString());
1230
- console.log(" maxCallGasLimit (% cap):", dynamicCallGasCap.toString());
1231
- console.log(" original callGasLimit:", estimate.callGasLimit.toString());
1232
- console.log(" padded callGasLimit:", paddedCallGasLimit.toString());
1233
- console.log(" capped callGasLimit:", cappedCallGasLimit.toString());
1234
- console.log(" verificationGasLimit:", paddedVerificationGasLimit.toString());
1235
- console.log(" preVerificationGas:", paddedPreVerificationGas.toString());
1227
+ try {
1228
+ const estimate = await bundlerClient.estimateUserOperationGas(userOp);
1229
+ const paddedCallGasLimit = estimate.callGasLimit * BigInt(Math.ceil(callGasMultiplier * 100)) / 100n;
1230
+ const cappedCallGasLimit = paddedCallGasLimit > dynamicCallGasCap ? dynamicCallGasCap : paddedCallGasLimit;
1231
+ const paddedVerificationGasLimit = estimate.verificationGasLimit * BigInt(Math.ceil(verificationGasMultiplier * 100)) / 100n;
1232
+ const paddedPreVerificationGas = estimate.preVerificationGas * BigInt(Math.ceil(preVerificationGasMultiplier * 100)) / 100n;
1233
+ if (debug) {
1234
+ console.log("\u2705 Gas Estimation Success:");
1235
+ console.log(" callGasLimit (capped):", cappedCallGasLimit.toString());
1236
+ console.log(" verificationGasLimit:", paddedVerificationGasLimit.toString());
1237
+ console.log(" preVerificationGas:", paddedPreVerificationGas.toString());
1238
+ }
1239
+ return {
1240
+ ...estimate,
1241
+ callGasLimit: cappedCallGasLimit,
1242
+ verificationGasLimit: paddedVerificationGasLimit,
1243
+ preVerificationGas: paddedPreVerificationGas
1244
+ };
1245
+ } catch (error) {
1246
+ console.error("\u274C Gas estimation failed!", error);
1247
+ throw error;
1236
1248
  }
1237
- return {
1238
- ...estimate,
1239
- callGasLimit: cappedCallGasLimit,
1240
- verificationGasLimit: paddedVerificationGasLimit,
1241
- preVerificationGas: paddedPreVerificationGas
1242
- };
1243
1249
  }
1244
1250
  };
1245
1251
  }
@@ -1659,8 +1665,94 @@ function useFetchAnymals() {
1659
1665
  }
1660
1666
 
1661
1667
  // src/utils/marketplace/useProcessPartialKibblePayment.ts
1662
- import { encodeFunctionData as encodeFunctionData2 } from "viem";
1663
1668
  import { useCallback as useCallback17 } from "react";
1669
+
1670
+ // src/helpers/ProcessDirectPartialPayment.tsx
1671
+ import { encodeFunctionData as encodeFunctionData2 } from "viem";
1672
+
1673
+ // src/helpers/SendUserOpWithRetries.tsx
1674
+ async function sendUserOpWithRetries(bundlerClient, params, retries = 3, delay = 1e3) {
1675
+ let attempt = 0;
1676
+ let lastError;
1677
+ while (attempt < retries) {
1678
+ try {
1679
+ return await bundlerClient.sendUserOperation(params);
1680
+ } catch (err) {
1681
+ lastError = err;
1682
+ console.warn(`\u{1F6D1} sendUserOperation failed (attempt ${attempt + 1}):`, err);
1683
+ attempt++;
1684
+ if (attempt < retries) await new Promise((r) => setTimeout(r, delay));
1685
+ }
1686
+ }
1687
+ throw new Error(`sendUserOperation failed after ${retries} attempts: ${lastError}`);
1688
+ }
1689
+
1690
+ // src/helpers/WaitForReceiptWithRetries.tsx
1691
+ async function waitForReceiptWithRetries(bundlerClient, hash, retries = 3, delay = 2e3) {
1692
+ let attempt = 0;
1693
+ let lastError;
1694
+ while (attempt < retries) {
1695
+ try {
1696
+ const receipt = await bundlerClient.waitForUserOperationReceipt(
1697
+ {
1698
+ hash,
1699
+ timeout: 3e4,
1700
+ retryCount: 10
1701
+ }
1702
+ );
1703
+ if (!receipt.success) {
1704
+ throw new Error(`UserOperation reverted: ${receipt.reason || "unknown"}`);
1705
+ }
1706
+ return receipt;
1707
+ } catch (err) {
1708
+ lastError = err;
1709
+ console.warn(`\u{1F6D1} waitForUserOperationReceipt failed (attempt ${attempt + 1}):`, err);
1710
+ attempt++;
1711
+ if (attempt < retries) await new Promise((r) => setTimeout(r, delay));
1712
+ }
1713
+ }
1714
+ throw new Error(`waitForUserOperationReceipt failed after ${retries} attempts: ${lastError}`);
1715
+ }
1716
+
1717
+ // src/helpers/ProcessDirectPartialPayment.tsx
1718
+ async function processDirectPartialPayment(marketplaceContract, smartAccount, bundlerClient, orderId, anymalNftId, pid, amountInTokens, maxTokenPayment, nonce, deadline, backendSignature) {
1719
+ try {
1720
+ const partialPayCalldata = encodeFunctionData2({
1721
+ abi: MARKETPLACE_ABI,
1722
+ functionName: "partialPay",
1723
+ args: [
1724
+ orderId,
1725
+ anymalNftId,
1726
+ pid,
1727
+ amountInTokens,
1728
+ maxTokenPayment,
1729
+ nonce,
1730
+ deadline,
1731
+ backendSignature
1732
+ ]
1733
+ });
1734
+ await applyBundlerGasEstimator(smartAccount, bundlerClient);
1735
+ const userOpHash = await sendUserOpWithRetries(bundlerClient, {
1736
+ account: smartAccount,
1737
+ calls: [{ to: marketplaceContract, data: partialPayCalldata }],
1738
+ paymaster: true
1739
+ });
1740
+ await waitForReceiptWithRetries(bundlerClient, userOpHash);
1741
+ return {
1742
+ success: true,
1743
+ message: "Direct partial payment UserOperation executed successfully.",
1744
+ opHash: userOpHash
1745
+ };
1746
+ } catch (error) {
1747
+ const errorMessage = error instanceof Error ? error.cause?.message || error.message : "An unknown error occurred.";
1748
+ return {
1749
+ success: false,
1750
+ message: `Error during direct payment processing: ${errorMessage}`
1751
+ };
1752
+ }
1753
+ }
1754
+
1755
+ // src/utils/marketplace/useProcessPartialKibblePayment.ts
1664
1756
  function useProcessPartialKibblePayment() {
1665
1757
  return useCallback17(
1666
1758
  async (pid, nftId, orderId, dbAuthToken, marketplaceContract, smartAccount, bundlerClient, amountInTokens, maxTokenPayment, nonce, deadline, backendSignature) => {
@@ -1688,31 +1780,25 @@ function useProcessPartialKibblePayment() {
1688
1780
  backendSignature
1689
1781
  // bytes
1690
1782
  ];
1691
- console.info({ args });
1692
- const callData = encodeFunctionData2({
1693
- abi: MARKETPLACE_ABI,
1694
- functionName: "partialPay",
1695
- args
1696
- });
1697
- await applyBundlerGasEstimator(smartAccount, bundlerClient);
1698
- const userOpHash = await bundlerClient.sendUserOperation({
1699
- account: smartAccount,
1700
- calls: [
1701
- {
1702
- to: marketplaceContract,
1703
- data: callData
1704
- }
1705
- ],
1706
- paymaster: true
1707
- });
1708
- const receipt = await bundlerClient.waitForUserOperationReceipt({
1709
- hash: userOpHash,
1710
- timeout: 3e4,
1711
- retryCount: 10
1712
- });
1713
- return { success: true, message: receipt.userOpHash };
1783
+ const result = await processDirectPartialPayment(
1784
+ marketplaceContract,
1785
+ smartAccount,
1786
+ bundlerClient,
1787
+ orderId,
1788
+ nftId,
1789
+ pid,
1790
+ amountInTokens,
1791
+ maxTokenPayment,
1792
+ nonce,
1793
+ deadline,
1794
+ backendSignature
1795
+ );
1796
+ return {
1797
+ success: result.success,
1798
+ message: result.message
1799
+ };
1714
1800
  } catch (error) {
1715
- const errorMessage = error instanceof Error ? error.message : "An unknown error occurred";
1801
+ const errorMessage = error instanceof Error ? error.cause?.message || error.message : "An unknown error occurred.";
1716
1802
  return {
1717
1803
  success: false,
1718
1804
  message: `Error processing payment: ${errorMessage}`
@@ -1724,41 +1810,53 @@ function useProcessPartialKibblePayment() {
1724
1810
  }
1725
1811
 
1726
1812
  // src/utils/marketplace/useApproveKibbleToken.ts
1727
- import { encodeFunctionData as encodeFunctionData3, erc20Abi } from "viem";
1728
1813
  import { useCallback as useCallback18 } from "react";
1814
+
1815
+ // src/helpers/ProcessDirectKibbleApproval.tsx
1816
+ import { encodeFunctionData as encodeFunctionData3, erc20Abi } from "viem";
1817
+ async function processDirectKibbleApproval(kibbleTokenAddress, spenderAddress, smartAccount, bundlerClient, approveAmount) {
1818
+ try {
1819
+ const approveCalldata = encodeFunctionData3({
1820
+ abi: erc20Abi,
1821
+ functionName: "approve",
1822
+ args: [spenderAddress, approveAmount]
1823
+ });
1824
+ await applyBundlerGasEstimator(smartAccount, bundlerClient);
1825
+ const userOpHash = await sendUserOpWithRetries(bundlerClient, {
1826
+ account: smartAccount,
1827
+ calls: [{ to: kibbleTokenAddress, data: approveCalldata }],
1828
+ paymaster: true
1829
+ });
1830
+ await waitForReceiptWithRetries(bundlerClient, userOpHash);
1831
+ return {
1832
+ success: true,
1833
+ message: "Direct approval UserOperation executed successfully.",
1834
+ opHash: userOpHash
1835
+ };
1836
+ } catch (error) {
1837
+ const errorMessage = error instanceof Error ? error.cause?.message || error.message : "An unknown error occurred.";
1838
+ return {
1839
+ success: false,
1840
+ message: `Error during direct approval processing: ${errorMessage}`
1841
+ };
1842
+ }
1843
+ }
1844
+
1845
+ // src/utils/marketplace/useApproveKibbleToken.ts
1729
1846
  function useApproveKibbleToken() {
1730
1847
  return useCallback18(
1731
1848
  async (kibbleTokenAddress, marketplaceContract, amount, smartAccount, bundlerClient) => {
1732
1849
  try {
1733
- const callData = encodeFunctionData3({
1734
- abi: erc20Abi,
1735
- functionName: "approve",
1736
- args: [
1737
- marketplaceContract,
1738
- // spender address
1739
- BigInt(amount)
1740
- // amount to approve
1741
- ]
1742
- });
1743
- await applyBundlerGasEstimator(smartAccount, bundlerClient);
1744
- const userOpHash = await bundlerClient.sendUserOperation({
1745
- account: smartAccount,
1746
- calls: [
1747
- {
1748
- to: kibbleTokenAddress,
1749
- data: callData
1750
- }
1751
- ],
1752
- paymaster: true
1753
- });
1754
- await bundlerClient.waitForUserOperationReceipt({
1755
- hash: userOpHash,
1756
- timeout: 3e4,
1757
- retryCount: 10
1758
- });
1850
+ const result = await processDirectKibbleApproval(
1851
+ kibbleTokenAddress,
1852
+ marketplaceContract,
1853
+ smartAccount,
1854
+ bundlerClient,
1855
+ amount
1856
+ );
1759
1857
  return {
1760
- success: true,
1761
- message: "Approval transaction completed successfully."
1858
+ success: result.success,
1859
+ message: result.message
1762
1860
  };
1763
1861
  } catch (error) {
1764
1862
  const errorMessage = error instanceof Error ? error.message : "An unknown error occurred";
@@ -1863,7 +1961,92 @@ function useCreateOrganizationBase() {
1863
1961
 
1864
1962
  // src/utils/organization/useApproveOrgKibbleToken.ts
1865
1963
  import { useCallback as useCallback20 } from "react";
1866
- import { encodeFunctionData as encodeFunctionData5, erc20Abi as erc20Abi2 } from "viem";
1964
+
1965
+ // src/helpers/ProcessOrgKibbleApproval.tsx
1966
+ import { encodeFunctionData as encodeFunctionData5, erc20Abi as erc20Abi3 } from "viem";
1967
+
1968
+ // src/helpers/WaitForAllowance.tsx
1969
+ import { erc20Abi as erc20Abi2 } from "viem";
1970
+ async function waitForAllowance(publicClient, tokenAddress, ownerAddress, spenderAddress, expectedAmount) {
1971
+ const MAX_RETRIES = 10;
1972
+ const RETRY_INTERVAL = 2e3;
1973
+ console.log(` MDEBUG: Polling for allowance of ${expectedAmount} for spender ${spenderAddress}...`);
1974
+ for (let i = 0; i < MAX_RETRIES; i++) {
1975
+ try {
1976
+ const currentAllowance = await publicClient.readContract({
1977
+ address: tokenAddress,
1978
+ abi: erc20Abi2,
1979
+ functionName: "allowance",
1980
+ args: [ownerAddress, spenderAddress]
1981
+ });
1982
+ console.log(` MDEBUG: (Attempt ${i + 1}) Current allowance is ${currentAllowance.toString()}`);
1983
+ if (currentAllowance >= expectedAmount) {
1984
+ console.log(` MDEBUG: \u2705 Allowance confirmed on-chain. ${currentAllowance}`);
1985
+ return true;
1986
+ }
1987
+ } catch (error) {
1988
+ const errorMessage = error instanceof Error ? error.cause?.message || error.message : "An unknown error occurred waiting for allowance.";
1989
+ console.log(` MDEBUG: Error polling for allowance: ${errorMessage}`);
1990
+ }
1991
+ await new Promise((res) => setTimeout(res, RETRY_INTERVAL));
1992
+ }
1993
+ console.log(" MDEBUG: \u274C Timed out waiting for allowance confirmation.");
1994
+ return false;
1995
+ }
1996
+
1997
+ // src/helpers/ProcessOrgKibbleApproval.tsx
1998
+ async function processOrgKibbleApproval(orgContractAddress, kibbleTokenAddress, partialPaymentModuleAddress, managerSmartAccount, bundlerClient, approveAmount) {
1999
+ try {
2000
+ if (approveAmount <= 0n) {
2001
+ return { success: false, message: "Approval amount must be greater than zero." };
2002
+ }
2003
+ const approveCalldata = encodeFunctionData5({
2004
+ abi: erc20Abi3,
2005
+ functionName: "approve",
2006
+ args: [partialPaymentModuleAddress, approveAmount]
2007
+ });
2008
+ const executeApproveCalldata = encodeFunctionData5({
2009
+ abi: ORGANIZATION_IMPL_ABI,
2010
+ functionName: "executeCall",
2011
+ args: [kibbleTokenAddress, approveCalldata]
2012
+ });
2013
+ await applyBundlerGasEstimator(managerSmartAccount, bundlerClient);
2014
+ const userOpApproveHash = await sendUserOpWithRetries(bundlerClient, {
2015
+ account: managerSmartAccount,
2016
+ calls: [{ to: orgContractAddress, data: executeApproveCalldata }],
2017
+ paymaster: true
2018
+ });
2019
+ await waitForReceiptWithRetries(bundlerClient, userOpApproveHash);
2020
+ const publicClient = bundlerClient.client;
2021
+ const allowanceConfirmed = await waitForAllowance(
2022
+ publicClient,
2023
+ kibbleTokenAddress,
2024
+ orgContractAddress,
2025
+ partialPaymentModuleAddress,
2026
+ approveAmount
2027
+ );
2028
+ if (!allowanceConfirmed) {
2029
+ console.error("\u274C Halting iteration because on-chain allowance could not be confirmed.");
2030
+ return {
2031
+ success: false,
2032
+ message: `Error waiting for allowance`
2033
+ };
2034
+ }
2035
+ return {
2036
+ success: true,
2037
+ message: "Approval UserOperation executed successfully.",
2038
+ opHash: userOpApproveHash
2039
+ };
2040
+ } catch (error) {
2041
+ const errorMessage = error instanceof Error ? error.cause?.message || error.message : "An unknown error occurred.";
2042
+ return {
2043
+ success: false,
2044
+ message: `Error during approval processing: ${errorMessage}`
2045
+ };
2046
+ }
2047
+ }
2048
+
2049
+ // src/utils/organization/useApproveOrgKibbleToken.ts
1867
2050
  function useApproveOrgPartialPayment() {
1868
2051
  return useCallback20(
1869
2052
  async (orgContractAddress, kibbleTokenAddress, partialPaymentModuleAddress, managerSmartAccount, bundlerClient, approveAmount) => {
@@ -1874,37 +2057,22 @@ function useApproveOrgPartialPayment() {
1874
2057
  };
1875
2058
  }
1876
2059
  try {
1877
- const approveCalldata = encodeFunctionData5({
1878
- abi: erc20Abi2,
1879
- functionName: "approve",
1880
- args: [partialPaymentModuleAddress, approveAmount]
1881
- });
1882
- const executeApproveCalldata = encodeFunctionData5({
1883
- abi: ORGANIZATION_IMPL_ABI,
1884
- functionName: "executeCall",
1885
- args: [kibbleTokenAddress, approveCalldata]
1886
- });
1887
- await applyBundlerGasEstimator(managerSmartAccount, bundlerClient);
1888
- const userOpApproveHash = await bundlerClient.sendUserOperation({
1889
- account: managerSmartAccount,
1890
- calls: [
1891
- {
1892
- to: orgContractAddress,
1893
- data: executeApproveCalldata
1894
- }
1895
- ],
1896
- paymaster: true
1897
- });
1898
- await bundlerClient.waitForUserOperationReceipt({
1899
- hash: userOpApproveHash
1900
- });
1901
- return { success: true, message: "Approval processed successfully." };
1902
- } catch (error) {
1903
- const errorMessage = error instanceof Error ? error.message : "An unknown error occurred.";
2060
+ const result = await processOrgKibbleApproval(
2061
+ orgContractAddress,
2062
+ kibbleTokenAddress,
2063
+ partialPaymentModuleAddress,
2064
+ managerSmartAccount,
2065
+ bundlerClient,
2066
+ approveAmount
2067
+ );
1904
2068
  return {
1905
- success: false,
1906
- message: `Error processing approval: ${errorMessage}`
2069
+ success: result.success,
2070
+ message: result.message
1907
2071
  };
2072
+ } catch (error) {
2073
+ console.error(" MDEBUG: Uncaught error in `useApproveOrgPartialPayment` hook:", error);
2074
+ const message = error instanceof Error ? error.cause?.message || error.message : "An unknown error occurred.";
2075
+ return { success: false, message: `Approval failed: ${message}` };
1908
2076
  }
1909
2077
  },
1910
2078
  []
@@ -1913,7 +2081,52 @@ function useApproveOrgPartialPayment() {
1913
2081
 
1914
2082
  // src/utils/organization/useProcessOrgPartialKibblePayment.ts
1915
2083
  import { useCallback as useCallback21 } from "react";
2084
+
2085
+ // src/helpers/ProcessOrgPartialPayment.tsx
1916
2086
  import { encodeFunctionData as encodeFunctionData6 } from "viem";
2087
+ async function processOrgPartialPayment(orgContractAddress, partialPaymentModuleAddress, managerSmartAccount, bundlerClient, orderId, anymalNftId, pid, amountInTokens, maxTokenPayment, nonce, deadline, backendSignature) {
2088
+ try {
2089
+ const partialPayCalldata = encodeFunctionData6({
2090
+ abi: MARKETPLACE_ABI,
2091
+ functionName: "partialPay",
2092
+ args: [
2093
+ orderId,
2094
+ anymalNftId,
2095
+ pid,
2096
+ amountInTokens,
2097
+ maxTokenPayment,
2098
+ nonce,
2099
+ deadline,
2100
+ backendSignature
2101
+ ]
2102
+ });
2103
+ const executePartialPayCalldata = encodeFunctionData6({
2104
+ abi: ORGANIZATION_IMPL_ABI,
2105
+ functionName: "executeCall",
2106
+ args: [partialPaymentModuleAddress, partialPayCalldata]
2107
+ });
2108
+ await applyBundlerGasEstimator(managerSmartAccount, bundlerClient);
2109
+ const userOpHash = await sendUserOpWithRetries(bundlerClient, {
2110
+ account: managerSmartAccount,
2111
+ calls: [{ to: orgContractAddress, data: executePartialPayCalldata }],
2112
+ paymaster: true
2113
+ });
2114
+ await waitForReceiptWithRetries(bundlerClient, userOpHash);
2115
+ return {
2116
+ success: true,
2117
+ message: "Partial payment UserOperation executed successfully.",
2118
+ opHash: userOpHash
2119
+ };
2120
+ } catch (error) {
2121
+ const errorMessage = error instanceof Error ? error.cause?.message || error.message : "An unknown error occurred.";
2122
+ return {
2123
+ success: false,
2124
+ message: `Error during payment processing: ${errorMessage}`
2125
+ };
2126
+ }
2127
+ }
2128
+
2129
+ // src/utils/organization/useProcessOrgPartialKibblePayment.ts
1917
2130
  function useProcessOrgPartialKibblePayment() {
1918
2131
  return useCallback21(
1919
2132
  async (orgContractAddress, partialPaymentModuleAddress, managerSmartAccount, bundlerClient, orderId, anymalNftId, pid, amountInTokens, maxTokenPayment, nonce, deadline, backendSignature) => {
@@ -1924,46 +2137,28 @@ function useProcessOrgPartialKibblePayment() {
1924
2137
  };
1925
2138
  }
1926
2139
  try {
1927
- const partialPayCalldata = encodeFunctionData6({
1928
- abi: MARKETPLACE_ABI,
1929
- functionName: "partialPay",
1930
- args: [
1931
- orderId,
1932
- anymalNftId,
1933
- pid,
1934
- amountInTokens,
1935
- maxTokenPayment,
1936
- nonce,
1937
- deadline,
1938
- backendSignature
1939
- ]
1940
- });
1941
- const executePartialPayCalldata = encodeFunctionData6({
1942
- abi: ORGANIZATION_IMPL_ABI,
1943
- functionName: "executeCall",
1944
- args: [partialPaymentModuleAddress, partialPayCalldata]
1945
- });
1946
- await applyBundlerGasEstimator(managerSmartAccount, bundlerClient);
1947
- const userOpPartialPayHash = await bundlerClient.sendUserOperation({
1948
- account: managerSmartAccount,
1949
- calls: [
1950
- {
1951
- to: orgContractAddress,
1952
- data: executePartialPayCalldata
1953
- }
1954
- ],
1955
- paymaster: true
1956
- });
1957
- const receipt = await bundlerClient.waitForUserOperationReceipt({
1958
- hash: userOpPartialPayHash
1959
- });
1960
- return { success: true, message: receipt.userOpHash };
1961
- } catch (error) {
1962
- const errorMessage = error instanceof Error ? error.message : "An unknown error occurred.";
2140
+ const result = await processOrgPartialPayment(
2141
+ orgContractAddress,
2142
+ partialPaymentModuleAddress,
2143
+ managerSmartAccount,
2144
+ bundlerClient,
2145
+ orderId,
2146
+ anymalNftId,
2147
+ pid,
2148
+ amountInTokens,
2149
+ maxTokenPayment,
2150
+ nonce,
2151
+ deadline,
2152
+ backendSignature
2153
+ );
1963
2154
  return {
1964
- success: false,
1965
- message: `Error processing partial payment: ${errorMessage}`
2155
+ success: result.success,
2156
+ message: result.message
1966
2157
  };
2158
+ } catch (error) {
2159
+ console.error(" MDEBUG: Uncaught error in `useProcessOrgPartialKibblePayment`:", error);
2160
+ const errorMessage = error instanceof Error ? error.cause?.message || error.message : "An unknown error occurred.";
2161
+ return { success: false, message: `Partial payment failed: ${errorMessage}` };
1967
2162
  }
1968
2163
  },
1969
2164
  []
@@ -2289,14 +2484,14 @@ function useCreateOrganizationAppData() {
2289
2484
 
2290
2485
  // src/utils/balance/useFetchBalance.ts
2291
2486
  import { useCallback as useCallback27 } from "react";
2292
- import { erc20Abi as erc20Abi3, getAddress } from "viem";
2487
+ import { erc20Abi as erc20Abi4, getAddress } from "viem";
2293
2488
  function useFetchBalance() {
2294
2489
  return useCallback27(
2295
2490
  async (publicClient, walletAddress, kibbleTokenAddress) => {
2296
2491
  try {
2297
2492
  const balance = await publicClient.readContract({
2298
2493
  address: getAddress(kibbleTokenAddress),
2299
- abi: erc20Abi3,
2494
+ abi: erc20Abi4,
2300
2495
  functionName: "balanceOf",
2301
2496
  args: [getAddress(walletAddress)]
2302
2497
  });
@@ -2515,6 +2710,8 @@ export {
2515
2710
  ActionSourceType,
2516
2711
  ActionStatus,
2517
2712
  ActionType,
2713
+ FIREBASE_WEB_API_KEYS,
2714
+ FIREBASE_WEB_AUTH_API_ENDPOINTS,
2518
2715
  MarketplacePaymentType,
2519
2716
  NETWORK_HOSTS,
2520
2717
  Network,
@@ -2522,12 +2719,20 @@ export {
2522
2719
  convertToActionRecord,
2523
2720
  convertToMultipleActionDefinitions,
2524
2721
  convertToMultipleActionRecords,
2722
+ createApp,
2525
2723
  createAuthEnvelope,
2526
2724
  fetchAnymals,
2725
+ flattenFirestoreData,
2527
2726
  generateAppSignature,
2528
2727
  generateBytes32Nonce,
2529
2728
  generateJWT,
2729
+ getFirebaseTokenForApp,
2530
2730
  loadExistingSecp256k1PrivateKey,
2731
+ processDirectKibbleApproval,
2732
+ processDirectPartialPayment,
2733
+ processOrgKibbleApproval,
2734
+ processOrgPartialPayment,
2735
+ sendUserOpWithRetries,
2531
2736
  serializePublicKeyCompressed,
2532
2737
  submitAction,
2533
2738
  useAddAnymalToDatabase,
@@ -2559,5 +2764,7 @@ export {
2559
2764
  useUpdateUserPid,
2560
2765
  useUploadAnymalImage,
2561
2766
  useVerifyAccount,
2562
- useVerifyWeb3AuthSession
2767
+ useVerifyWeb3AuthSession,
2768
+ waitForAllowance,
2769
+ waitForReceiptWithRetries
2563
2770
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anymal-protocol",
3
- "version": "1.0.118",
3
+ "version": "1.0.120",
4
4
  "description": "A React/TypeScript-based utility library for reusable functions and hooks inside of the Anymal Ecosystem.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {