anymal-protocol 1.0.117 → 1.0.119
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/{chunk-F72KTNHS.mjs → chunk-OBXCSRGF.mjs} +109 -1
- package/dist/cli/index.mjs +2 -36
- package/dist/index.d.mts +59 -11
- package/dist/index.d.ts +59 -11
- package/dist/index.js +487 -160
- package/dist/index.mjs +368 -151
- package/package.json +1 -1
- package/dist/chunk-43I5M7QS.mjs +0 -93
- package/dist/chunk-5UXBNDDZ.mjs +0 -93
- package/dist/chunk-DIGESQEI.mjs +0 -91
- package/dist/chunk-KEC6WLEL.mjs +0 -93
- package/dist/chunk-QHK3YPLJ.mjs +0 -93
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-
|
|
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
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
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
|
}
|
|
@@ -1265,7 +1271,7 @@ function useMintAnymalNFT() {
|
|
|
1265
1271
|
anymalTxId
|
|
1266
1272
|
]
|
|
1267
1273
|
});
|
|
1268
|
-
applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
1274
|
+
await applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
1269
1275
|
const userOpHash = await bundlerClient.sendUserOperation({
|
|
1270
1276
|
account: smartAccount,
|
|
1271
1277
|
calls: [
|
|
@@ -1659,8 +1665,104 @@ 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, erc20Abi } 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 publicClient = bundlerClient.client;
|
|
1721
|
+
const allowance = await publicClient.readContract({
|
|
1722
|
+
abi: erc20Abi,
|
|
1723
|
+
address: marketplaceContract,
|
|
1724
|
+
functionName: "allowance",
|
|
1725
|
+
args: [smartAccount.address, marketplaceContract]
|
|
1726
|
+
});
|
|
1727
|
+
if (allowance < amountInTokens) {
|
|
1728
|
+
return { success: false, message: "Insufficient allowance for direct partial payment." };
|
|
1729
|
+
}
|
|
1730
|
+
const partialPayCalldata = encodeFunctionData2({
|
|
1731
|
+
abi: MARKETPLACE_ABI,
|
|
1732
|
+
functionName: "partialPay",
|
|
1733
|
+
args: [
|
|
1734
|
+
orderId,
|
|
1735
|
+
anymalNftId,
|
|
1736
|
+
pid,
|
|
1737
|
+
amountInTokens,
|
|
1738
|
+
maxTokenPayment,
|
|
1739
|
+
nonce,
|
|
1740
|
+
deadline,
|
|
1741
|
+
backendSignature
|
|
1742
|
+
]
|
|
1743
|
+
});
|
|
1744
|
+
await applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
1745
|
+
const userOpHash = await sendUserOpWithRetries(bundlerClient, {
|
|
1746
|
+
account: smartAccount,
|
|
1747
|
+
calls: [{ to: marketplaceContract, data: partialPayCalldata }],
|
|
1748
|
+
paymaster: true
|
|
1749
|
+
});
|
|
1750
|
+
await waitForReceiptWithRetries(bundlerClient, userOpHash);
|
|
1751
|
+
return {
|
|
1752
|
+
success: true,
|
|
1753
|
+
message: "Direct partial payment UserOperation executed successfully.",
|
|
1754
|
+
opHash: userOpHash
|
|
1755
|
+
};
|
|
1756
|
+
} catch (error) {
|
|
1757
|
+
const errorMessage = error instanceof Error ? error.cause?.message || error.message : "An unknown error occurred.";
|
|
1758
|
+
return {
|
|
1759
|
+
success: false,
|
|
1760
|
+
message: `Error during direct payment processing: ${errorMessage}`
|
|
1761
|
+
};
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1765
|
+
// src/utils/marketplace/useProcessPartialKibblePayment.ts
|
|
1664
1766
|
function useProcessPartialKibblePayment() {
|
|
1665
1767
|
return useCallback17(
|
|
1666
1768
|
async (pid, nftId, orderId, dbAuthToken, marketplaceContract, smartAccount, bundlerClient, amountInTokens, maxTokenPayment, nonce, deadline, backendSignature) => {
|
|
@@ -1688,31 +1790,25 @@ function useProcessPartialKibblePayment() {
|
|
|
1688
1790
|
backendSignature
|
|
1689
1791
|
// bytes
|
|
1690
1792
|
];
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
}
|
|
1708
|
-
const receipt = await bundlerClient.waitForUserOperationReceipt({
|
|
1709
|
-
hash: userOpHash,
|
|
1710
|
-
timeout: 3e4,
|
|
1711
|
-
retryCount: 10
|
|
1712
|
-
});
|
|
1713
|
-
return { success: true, message: receipt.userOpHash };
|
|
1793
|
+
const result = await processDirectPartialPayment(
|
|
1794
|
+
marketplaceContract,
|
|
1795
|
+
smartAccount,
|
|
1796
|
+
bundlerClient,
|
|
1797
|
+
orderId,
|
|
1798
|
+
nftId,
|
|
1799
|
+
pid,
|
|
1800
|
+
amountInTokens,
|
|
1801
|
+
maxTokenPayment,
|
|
1802
|
+
nonce,
|
|
1803
|
+
deadline,
|
|
1804
|
+
backendSignature
|
|
1805
|
+
);
|
|
1806
|
+
return {
|
|
1807
|
+
success: result.success,
|
|
1808
|
+
message: result.message
|
|
1809
|
+
};
|
|
1714
1810
|
} catch (error) {
|
|
1715
|
-
const errorMessage = error instanceof Error ? error.message : "An unknown error occurred";
|
|
1811
|
+
const errorMessage = error instanceof Error ? error.cause?.message || error.message : "An unknown error occurred.";
|
|
1716
1812
|
return {
|
|
1717
1813
|
success: false,
|
|
1718
1814
|
message: `Error processing payment: ${errorMessage}`
|
|
@@ -1724,41 +1820,53 @@ function useProcessPartialKibblePayment() {
|
|
|
1724
1820
|
}
|
|
1725
1821
|
|
|
1726
1822
|
// src/utils/marketplace/useApproveKibbleToken.ts
|
|
1727
|
-
import { encodeFunctionData as encodeFunctionData3, erc20Abi } from "viem";
|
|
1728
1823
|
import { useCallback as useCallback18 } from "react";
|
|
1824
|
+
|
|
1825
|
+
// src/helpers/ProcessDirectKibbleApproval.tsx
|
|
1826
|
+
import { encodeFunctionData as encodeFunctionData3, erc20Abi as erc20Abi2 } from "viem";
|
|
1827
|
+
async function processDirectKibbleApproval(kibbleTokenAddress, spenderAddress, smartAccount, bundlerClient, approveAmount) {
|
|
1828
|
+
try {
|
|
1829
|
+
const approveCalldata = encodeFunctionData3({
|
|
1830
|
+
abi: erc20Abi2,
|
|
1831
|
+
functionName: "approve",
|
|
1832
|
+
args: [spenderAddress, approveAmount]
|
|
1833
|
+
});
|
|
1834
|
+
await applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
1835
|
+
const userOpHash = await sendUserOpWithRetries(bundlerClient, {
|
|
1836
|
+
account: smartAccount,
|
|
1837
|
+
calls: [{ to: kibbleTokenAddress, data: approveCalldata }],
|
|
1838
|
+
paymaster: true
|
|
1839
|
+
});
|
|
1840
|
+
await waitForReceiptWithRetries(bundlerClient, userOpHash);
|
|
1841
|
+
return {
|
|
1842
|
+
success: true,
|
|
1843
|
+
message: "Direct approval UserOperation executed successfully.",
|
|
1844
|
+
opHash: userOpHash
|
|
1845
|
+
};
|
|
1846
|
+
} catch (error) {
|
|
1847
|
+
const errorMessage = error instanceof Error ? error.cause?.message || error.message : "An unknown error occurred.";
|
|
1848
|
+
return {
|
|
1849
|
+
success: false,
|
|
1850
|
+
message: `Error during direct approval processing: ${errorMessage}`
|
|
1851
|
+
};
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
// src/utils/marketplace/useApproveKibbleToken.ts
|
|
1729
1856
|
function useApproveKibbleToken() {
|
|
1730
1857
|
return useCallback18(
|
|
1731
1858
|
async (kibbleTokenAddress, marketplaceContract, amount, smartAccount, bundlerClient) => {
|
|
1732
1859
|
try {
|
|
1733
|
-
const
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
// amount to approve
|
|
1741
|
-
]
|
|
1742
|
-
});
|
|
1743
|
-
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
|
-
});
|
|
1860
|
+
const result = await processDirectKibbleApproval(
|
|
1861
|
+
kibbleTokenAddress,
|
|
1862
|
+
marketplaceContract,
|
|
1863
|
+
smartAccount,
|
|
1864
|
+
bundlerClient,
|
|
1865
|
+
amount
|
|
1866
|
+
);
|
|
1759
1867
|
return {
|
|
1760
|
-
success:
|
|
1761
|
-
message:
|
|
1868
|
+
success: result.success,
|
|
1869
|
+
message: result.message
|
|
1762
1870
|
};
|
|
1763
1871
|
} catch (error) {
|
|
1764
1872
|
const errorMessage = error instanceof Error ? error.message : "An unknown error occurred";
|
|
@@ -1801,7 +1909,7 @@ function useCreateOrganizationBase() {
|
|
|
1801
1909
|
functionName: "createOrganizationProxy",
|
|
1802
1910
|
args: [ownerAddress, orgName, orgPid]
|
|
1803
1911
|
});
|
|
1804
|
-
applyBundlerGasEstimator(adminSmartAccount, bundlerClient);
|
|
1912
|
+
await applyBundlerGasEstimator(adminSmartAccount, bundlerClient);
|
|
1805
1913
|
const userOpHash = await bundlerClient.sendUserOperation({
|
|
1806
1914
|
account: adminSmartAccount,
|
|
1807
1915
|
calls: [
|
|
@@ -1863,7 +1971,92 @@ function useCreateOrganizationBase() {
|
|
|
1863
1971
|
|
|
1864
1972
|
// src/utils/organization/useApproveOrgKibbleToken.ts
|
|
1865
1973
|
import { useCallback as useCallback20 } from "react";
|
|
1866
|
-
|
|
1974
|
+
|
|
1975
|
+
// src/helpers/ProcessOrgKibbleApproval.tsx
|
|
1976
|
+
import { encodeFunctionData as encodeFunctionData5, erc20Abi as erc20Abi4 } from "viem";
|
|
1977
|
+
|
|
1978
|
+
// src/helpers/WaitForAllowance.tsx
|
|
1979
|
+
import { erc20Abi as erc20Abi3 } from "viem";
|
|
1980
|
+
async function waitForAllowance(publicClient, tokenAddress, ownerAddress, spenderAddress, expectedAmount) {
|
|
1981
|
+
const MAX_RETRIES = 10;
|
|
1982
|
+
const RETRY_INTERVAL = 2e3;
|
|
1983
|
+
console.log(` MDEBUG: Polling for allowance of ${expectedAmount} for spender ${spenderAddress}...`);
|
|
1984
|
+
for (let i = 0; i < MAX_RETRIES; i++) {
|
|
1985
|
+
try {
|
|
1986
|
+
const currentAllowance = await publicClient.readContract({
|
|
1987
|
+
address: tokenAddress,
|
|
1988
|
+
abi: erc20Abi3,
|
|
1989
|
+
functionName: "allowance",
|
|
1990
|
+
args: [ownerAddress, spenderAddress]
|
|
1991
|
+
});
|
|
1992
|
+
console.log(` MDEBUG: (Attempt ${i + 1}) Current allowance is ${currentAllowance.toString()}`);
|
|
1993
|
+
if (currentAllowance >= expectedAmount) {
|
|
1994
|
+
console.log(` MDEBUG: \u2705 Allowance confirmed on-chain. ${currentAllowance}`);
|
|
1995
|
+
return true;
|
|
1996
|
+
}
|
|
1997
|
+
} catch (error) {
|
|
1998
|
+
const errorMessage = error instanceof Error ? error.cause?.message || error.message : "An unknown error occurred waiting for allowance.";
|
|
1999
|
+
console.log(` MDEBUG: Error polling for allowance: ${errorMessage}`);
|
|
2000
|
+
}
|
|
2001
|
+
await new Promise((res) => setTimeout(res, RETRY_INTERVAL));
|
|
2002
|
+
}
|
|
2003
|
+
console.log(" MDEBUG: \u274C Timed out waiting for allowance confirmation.");
|
|
2004
|
+
return false;
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
// src/helpers/ProcessOrgKibbleApproval.tsx
|
|
2008
|
+
async function processOrgKibbleApproval(orgContractAddress, kibbleTokenAddress, partialPaymentModuleAddress, managerSmartAccount, bundlerClient, approveAmount) {
|
|
2009
|
+
try {
|
|
2010
|
+
if (approveAmount <= 0n) {
|
|
2011
|
+
return { success: false, message: "Approval amount must be greater than zero." };
|
|
2012
|
+
}
|
|
2013
|
+
const approveCalldata = encodeFunctionData5({
|
|
2014
|
+
abi: erc20Abi4,
|
|
2015
|
+
functionName: "approve",
|
|
2016
|
+
args: [partialPaymentModuleAddress, approveAmount]
|
|
2017
|
+
});
|
|
2018
|
+
const executeApproveCalldata = encodeFunctionData5({
|
|
2019
|
+
abi: ORGANIZATION_IMPL_ABI,
|
|
2020
|
+
functionName: "executeCall",
|
|
2021
|
+
args: [kibbleTokenAddress, approveCalldata]
|
|
2022
|
+
});
|
|
2023
|
+
await applyBundlerGasEstimator(managerSmartAccount, bundlerClient);
|
|
2024
|
+
const userOpApproveHash = await sendUserOpWithRetries(bundlerClient, {
|
|
2025
|
+
account: managerSmartAccount,
|
|
2026
|
+
calls: [{ to: orgContractAddress, data: executeApproveCalldata }],
|
|
2027
|
+
paymaster: true
|
|
2028
|
+
});
|
|
2029
|
+
await waitForReceiptWithRetries(bundlerClient, userOpApproveHash);
|
|
2030
|
+
const publicClient = bundlerClient.client;
|
|
2031
|
+
const allowanceConfirmed = await waitForAllowance(
|
|
2032
|
+
publicClient,
|
|
2033
|
+
kibbleTokenAddress,
|
|
2034
|
+
orgContractAddress,
|
|
2035
|
+
partialPaymentModuleAddress,
|
|
2036
|
+
approveAmount
|
|
2037
|
+
);
|
|
2038
|
+
if (!allowanceConfirmed) {
|
|
2039
|
+
console.error("\u274C Halting iteration because on-chain allowance could not be confirmed.");
|
|
2040
|
+
return {
|
|
2041
|
+
success: false,
|
|
2042
|
+
message: `Error waiting for allowance`
|
|
2043
|
+
};
|
|
2044
|
+
}
|
|
2045
|
+
return {
|
|
2046
|
+
success: true,
|
|
2047
|
+
message: "Approval UserOperation executed successfully.",
|
|
2048
|
+
opHash: userOpApproveHash
|
|
2049
|
+
};
|
|
2050
|
+
} catch (error) {
|
|
2051
|
+
const errorMessage = error instanceof Error ? error.cause?.message || error.message : "An unknown error occurred.";
|
|
2052
|
+
return {
|
|
2053
|
+
success: false,
|
|
2054
|
+
message: `Error during approval processing: ${errorMessage}`
|
|
2055
|
+
};
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
// src/utils/organization/useApproveOrgKibbleToken.ts
|
|
1867
2060
|
function useApproveOrgPartialPayment() {
|
|
1868
2061
|
return useCallback20(
|
|
1869
2062
|
async (orgContractAddress, kibbleTokenAddress, partialPaymentModuleAddress, managerSmartAccount, bundlerClient, approveAmount) => {
|
|
@@ -1874,37 +2067,22 @@ function useApproveOrgPartialPayment() {
|
|
|
1874
2067
|
};
|
|
1875
2068
|
}
|
|
1876
2069
|
try {
|
|
1877
|
-
const
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
args: [kibbleTokenAddress, approveCalldata]
|
|
1886
|
-
});
|
|
1887
|
-
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.";
|
|
2070
|
+
const result = await processOrgKibbleApproval(
|
|
2071
|
+
orgContractAddress,
|
|
2072
|
+
kibbleTokenAddress,
|
|
2073
|
+
partialPaymentModuleAddress,
|
|
2074
|
+
managerSmartAccount,
|
|
2075
|
+
bundlerClient,
|
|
2076
|
+
approveAmount
|
|
2077
|
+
);
|
|
1904
2078
|
return {
|
|
1905
|
-
success:
|
|
1906
|
-
message:
|
|
2079
|
+
success: result.success,
|
|
2080
|
+
message: result.message
|
|
1907
2081
|
};
|
|
2082
|
+
} catch (error) {
|
|
2083
|
+
console.error(" MDEBUG: Uncaught error in `useApproveOrgPartialPayment` hook:", error);
|
|
2084
|
+
const message = error instanceof Error ? error.cause?.message || error.message : "An unknown error occurred.";
|
|
2085
|
+
return { success: false, message: `Approval failed: ${message}` };
|
|
1908
2086
|
}
|
|
1909
2087
|
},
|
|
1910
2088
|
[]
|
|
@@ -1913,7 +2091,52 @@ function useApproveOrgPartialPayment() {
|
|
|
1913
2091
|
|
|
1914
2092
|
// src/utils/organization/useProcessOrgPartialKibblePayment.ts
|
|
1915
2093
|
import { useCallback as useCallback21 } from "react";
|
|
2094
|
+
|
|
2095
|
+
// src/helpers/ProcessOrgPartialPayment.tsx
|
|
1916
2096
|
import { encodeFunctionData as encodeFunctionData6 } from "viem";
|
|
2097
|
+
async function processOrgPartialPayment(orgContractAddress, partialPaymentModuleAddress, managerSmartAccount, bundlerClient, orderId, anymalNftId, pid, amountInTokens, maxTokenPayment, nonce, deadline, backendSignature) {
|
|
2098
|
+
try {
|
|
2099
|
+
const partialPayCalldata = encodeFunctionData6({
|
|
2100
|
+
abi: MARKETPLACE_ABI,
|
|
2101
|
+
functionName: "partialPay",
|
|
2102
|
+
args: [
|
|
2103
|
+
orderId,
|
|
2104
|
+
anymalNftId,
|
|
2105
|
+
pid,
|
|
2106
|
+
amountInTokens,
|
|
2107
|
+
maxTokenPayment,
|
|
2108
|
+
nonce,
|
|
2109
|
+
deadline,
|
|
2110
|
+
backendSignature
|
|
2111
|
+
]
|
|
2112
|
+
});
|
|
2113
|
+
const executePartialPayCalldata = encodeFunctionData6({
|
|
2114
|
+
abi: ORGANIZATION_IMPL_ABI,
|
|
2115
|
+
functionName: "executeCall",
|
|
2116
|
+
args: [partialPaymentModuleAddress, partialPayCalldata]
|
|
2117
|
+
});
|
|
2118
|
+
await applyBundlerGasEstimator(managerSmartAccount, bundlerClient);
|
|
2119
|
+
const userOpHash = await sendUserOpWithRetries(bundlerClient, {
|
|
2120
|
+
account: managerSmartAccount,
|
|
2121
|
+
calls: [{ to: orgContractAddress, data: executePartialPayCalldata }],
|
|
2122
|
+
paymaster: true
|
|
2123
|
+
});
|
|
2124
|
+
await waitForReceiptWithRetries(bundlerClient, userOpHash);
|
|
2125
|
+
return {
|
|
2126
|
+
success: true,
|
|
2127
|
+
message: "Partial payment UserOperation executed successfully.",
|
|
2128
|
+
opHash: userOpHash
|
|
2129
|
+
};
|
|
2130
|
+
} catch (error) {
|
|
2131
|
+
const errorMessage = error instanceof Error ? error.cause?.message || error.message : "An unknown error occurred.";
|
|
2132
|
+
return {
|
|
2133
|
+
success: false,
|
|
2134
|
+
message: `Error during payment processing: ${errorMessage}`
|
|
2135
|
+
};
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2139
|
+
// src/utils/organization/useProcessOrgPartialKibblePayment.ts
|
|
1917
2140
|
function useProcessOrgPartialKibblePayment() {
|
|
1918
2141
|
return useCallback21(
|
|
1919
2142
|
async (orgContractAddress, partialPaymentModuleAddress, managerSmartAccount, bundlerClient, orderId, anymalNftId, pid, amountInTokens, maxTokenPayment, nonce, deadline, backendSignature) => {
|
|
@@ -1924,46 +2147,28 @@ function useProcessOrgPartialKibblePayment() {
|
|
|
1924
2147
|
};
|
|
1925
2148
|
}
|
|
1926
2149
|
try {
|
|
1927
|
-
const
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
const executePartialPayCalldata = encodeFunctionData6({
|
|
1942
|
-
abi: ORGANIZATION_IMPL_ABI,
|
|
1943
|
-
functionName: "executeCall",
|
|
1944
|
-
args: [partialPaymentModuleAddress, partialPayCalldata]
|
|
1945
|
-
});
|
|
1946
|
-
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.";
|
|
2150
|
+
const result = await processOrgPartialPayment(
|
|
2151
|
+
orgContractAddress,
|
|
2152
|
+
partialPaymentModuleAddress,
|
|
2153
|
+
managerSmartAccount,
|
|
2154
|
+
bundlerClient,
|
|
2155
|
+
orderId,
|
|
2156
|
+
anymalNftId,
|
|
2157
|
+
pid,
|
|
2158
|
+
amountInTokens,
|
|
2159
|
+
maxTokenPayment,
|
|
2160
|
+
nonce,
|
|
2161
|
+
deadline,
|
|
2162
|
+
backendSignature
|
|
2163
|
+
);
|
|
1963
2164
|
return {
|
|
1964
|
-
success:
|
|
1965
|
-
message:
|
|
2165
|
+
success: result.success,
|
|
2166
|
+
message: result.message
|
|
1966
2167
|
};
|
|
2168
|
+
} catch (error) {
|
|
2169
|
+
console.error(" MDEBUG: Uncaught error in `useProcessOrgPartialKibblePayment`:", error);
|
|
2170
|
+
const errorMessage = error instanceof Error ? error.cause?.message || error.message : "An unknown error occurred.";
|
|
2171
|
+
return { success: false, message: `Partial payment failed: ${errorMessage}` };
|
|
1967
2172
|
}
|
|
1968
2173
|
},
|
|
1969
2174
|
[]
|
|
@@ -2289,14 +2494,14 @@ function useCreateOrganizationAppData() {
|
|
|
2289
2494
|
|
|
2290
2495
|
// src/utils/balance/useFetchBalance.ts
|
|
2291
2496
|
import { useCallback as useCallback27 } from "react";
|
|
2292
|
-
import { erc20Abi as
|
|
2497
|
+
import { erc20Abi as erc20Abi5, getAddress } from "viem";
|
|
2293
2498
|
function useFetchBalance() {
|
|
2294
2499
|
return useCallback27(
|
|
2295
2500
|
async (publicClient, walletAddress, kibbleTokenAddress) => {
|
|
2296
2501
|
try {
|
|
2297
2502
|
const balance = await publicClient.readContract({
|
|
2298
2503
|
address: getAddress(kibbleTokenAddress),
|
|
2299
|
-
abi:
|
|
2504
|
+
abi: erc20Abi5,
|
|
2300
2505
|
functionName: "balanceOf",
|
|
2301
2506
|
args: [getAddress(walletAddress)]
|
|
2302
2507
|
});
|
|
@@ -2326,7 +2531,7 @@ function useClaimActionReward() {
|
|
|
2326
2531
|
functionName: "claimByIndex",
|
|
2327
2532
|
args: [actionId, claimIndex]
|
|
2328
2533
|
});
|
|
2329
|
-
applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
2534
|
+
await applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
2330
2535
|
const userOpHash = await bundlerClient.sendUserOperation({
|
|
2331
2536
|
account: smartAccount,
|
|
2332
2537
|
calls: [
|
|
@@ -2370,7 +2575,7 @@ function useClaimOrgActionReward() {
|
|
|
2370
2575
|
functionName: "executeCall",
|
|
2371
2576
|
args: [rewardableActionContractAddress, claimCallData]
|
|
2372
2577
|
});
|
|
2373
|
-
applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
2578
|
+
await applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
2374
2579
|
const userOpHash = await bundlerClient.sendUserOperation({
|
|
2375
2580
|
account: smartAccount,
|
|
2376
2581
|
calls: [
|
|
@@ -2515,6 +2720,8 @@ export {
|
|
|
2515
2720
|
ActionSourceType,
|
|
2516
2721
|
ActionStatus,
|
|
2517
2722
|
ActionType,
|
|
2723
|
+
FIREBASE_WEB_API_KEYS,
|
|
2724
|
+
FIREBASE_WEB_AUTH_API_ENDPOINTS,
|
|
2518
2725
|
MarketplacePaymentType,
|
|
2519
2726
|
NETWORK_HOSTS,
|
|
2520
2727
|
Network,
|
|
@@ -2522,12 +2729,20 @@ export {
|
|
|
2522
2729
|
convertToActionRecord,
|
|
2523
2730
|
convertToMultipleActionDefinitions,
|
|
2524
2731
|
convertToMultipleActionRecords,
|
|
2732
|
+
createApp,
|
|
2525
2733
|
createAuthEnvelope,
|
|
2526
2734
|
fetchAnymals,
|
|
2735
|
+
flattenFirestoreData,
|
|
2527
2736
|
generateAppSignature,
|
|
2528
2737
|
generateBytes32Nonce,
|
|
2529
2738
|
generateJWT,
|
|
2739
|
+
getFirebaseTokenForApp,
|
|
2530
2740
|
loadExistingSecp256k1PrivateKey,
|
|
2741
|
+
processDirectKibbleApproval,
|
|
2742
|
+
processDirectPartialPayment,
|
|
2743
|
+
processOrgKibbleApproval,
|
|
2744
|
+
processOrgPartialPayment,
|
|
2745
|
+
sendUserOpWithRetries,
|
|
2531
2746
|
serializePublicKeyCompressed,
|
|
2532
2747
|
submitAction,
|
|
2533
2748
|
useAddAnymalToDatabase,
|
|
@@ -2559,5 +2774,7 @@ export {
|
|
|
2559
2774
|
useUpdateUserPid,
|
|
2560
2775
|
useUploadAnymalImage,
|
|
2561
2776
|
useVerifyAccount,
|
|
2562
|
-
useVerifyWeb3AuthSession
|
|
2777
|
+
useVerifyWeb3AuthSession,
|
|
2778
|
+
waitForAllowance,
|
|
2779
|
+
waitForReceiptWithRetries
|
|
2563
2780
|
};
|
package/package.json
CHANGED