anymal-protocol 1.0.20 → 1.0.22

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.d.mts CHANGED
@@ -60,6 +60,18 @@ declare function useUploadAnymalImage(): (imageFile: File, type: string, idToken
60
60
  type: string;
61
61
  }>;
62
62
 
63
+ declare function useProcessPartialKibblePayment(): (pid: string, nftId: string, orderId: string, dbAuthToken: string, marketplaceContract: string, smartAccount: any, bundlerClient: any, amountInTokens: string, maxTokenPayment: string, nonce: string, deadline: string, backendSignature: string) => Promise<{
64
+ success: boolean;
65
+ message: string;
66
+ }>;
67
+
68
+ declare function useApproveKibbleToken(): (kibbleTokenAddress: string, marketplaceContract: string, amount: string, smartAccount: any, bundlerClient: any) => Promise<{
69
+ success: boolean;
70
+ message: string;
71
+ }>;
72
+
73
+ declare const generateBytes32Nonce: () => `0x${string}`;
74
+
63
75
  declare function useCreateUserAppData(): (appId: string, pid: string, dbAuthToken: string, endpoint: string) => Promise<{
64
76
  success: boolean;
65
77
  data: any;
@@ -67,4 +79,4 @@ declare function useCreateUserAppData(): (appId: string, pid: string, dbAuthToke
67
79
 
68
80
  declare function useFetchBalance(): (publicClient: any, walletAddress: string, kibbleTokenAddress: string) => Promise<number | undefined>;
69
81
 
70
- export { type AnymalNftMetadataInputData, type CreateAnymalInputData, useAddAnymalToDatabase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchUserData, useMintAnymalNFT, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
82
+ export { type AnymalNftMetadataInputData, type CreateAnymalInputData, generateBytes32Nonce, useAddAnymalToDatabase, useApproveKibbleToken, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchUserData, useMintAnymalNFT, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
package/dist/index.d.ts CHANGED
@@ -60,6 +60,18 @@ declare function useUploadAnymalImage(): (imageFile: File, type: string, idToken
60
60
  type: string;
61
61
  }>;
62
62
 
63
+ declare function useProcessPartialKibblePayment(): (pid: string, nftId: string, orderId: string, dbAuthToken: string, marketplaceContract: string, smartAccount: any, bundlerClient: any, amountInTokens: string, maxTokenPayment: string, nonce: string, deadline: string, backendSignature: string) => Promise<{
64
+ success: boolean;
65
+ message: string;
66
+ }>;
67
+
68
+ declare function useApproveKibbleToken(): (kibbleTokenAddress: string, marketplaceContract: string, amount: string, smartAccount: any, bundlerClient: any) => Promise<{
69
+ success: boolean;
70
+ message: string;
71
+ }>;
72
+
73
+ declare const generateBytes32Nonce: () => `0x${string}`;
74
+
63
75
  declare function useCreateUserAppData(): (appId: string, pid: string, dbAuthToken: string, endpoint: string) => Promise<{
64
76
  success: boolean;
65
77
  data: any;
@@ -67,4 +79,4 @@ declare function useCreateUserAppData(): (appId: string, pid: string, dbAuthToke
67
79
 
68
80
  declare function useFetchBalance(): (publicClient: any, walletAddress: string, kibbleTokenAddress: string) => Promise<number | undefined>;
69
81
 
70
- export { type AnymalNftMetadataInputData, type CreateAnymalInputData, useAddAnymalToDatabase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchUserData, useMintAnymalNFT, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
82
+ export { type AnymalNftMetadataInputData, type CreateAnymalInputData, generateBytes32Nonce, useAddAnymalToDatabase, useApproveKibbleToken, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchUserData, useMintAnymalNFT, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
package/dist/index.js CHANGED
@@ -20,13 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ generateBytes32Nonce: () => generateBytes32Nonce,
23
24
  useAddAnymalToDatabase: () => useAddAnymalToDatabase,
25
+ useApproveKibbleToken: () => useApproveKibbleToken,
24
26
  useCreateUserAppData: () => useCreateUserAppData,
25
27
  useCreateWeb3Account: () => useCreateWeb3Account,
26
28
  useDeleteAnymalFromDatabase: () => useDeleteAnymalFromDatabase,
27
29
  useFetchBalance: () => useFetchBalance,
28
30
  useFetchUserData: () => useFetchUserData,
29
31
  useMintAnymalNFT: () => useMintAnymalNFT,
32
+ useProcessPartialKibblePayment: () => useProcessPartialKibblePayment,
30
33
  useSaveAnymalMetadata: () => useSaveAnymalMetadata,
31
34
  useUpdateAnymalWithNFT: () => useUpdateAnymalWithNFT,
32
35
  useUpdateUserAsVerified: () => useUpdateUserAsVerified,
@@ -599,6 +602,7 @@ var VERIFY_ACCOUNT_ABI = [
599
602
  type: "function"
600
603
  }
601
604
  ];
605
+ var MARKETPLACE_ABI = [{ "inputs": [{ "internalType": "address", "name": "target", "type": "address" }], "name": "AddressEmptyCode", "type": "error" }, { "inputs": [], "name": "ECDSAInvalidSignature", "type": "error" }, { "inputs": [{ "internalType": "uint256", "name": "length", "type": "uint256" }], "name": "ECDSAInvalidSignatureLength", "type": "error" }, { "inputs": [{ "internalType": "bytes32", "name": "s", "type": "bytes32" }], "name": "ECDSAInvalidSignatureS", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "implementation", "type": "address" }], "name": "ERC1967InvalidImplementation", "type": "error" }, { "inputs": [], "name": "ERC1967NonPayable", "type": "error" }, { "inputs": [], "name": "FailedCall", "type": "error" }, { "inputs": [], "name": "InvalidInitialization", "type": "error" }, { "inputs": [], "name": "NotInitializing", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "owner", "type": "address" }], "name": "OwnableInvalidOwner", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], "name": "OwnableUnauthorizedAccount", "type": "error" }, { "inputs": [], "name": "UUPSUnauthorizedCallContext", "type": "error" }, { "inputs": [{ "internalType": "bytes32", "name": "slot", "type": "bytes32" }], "name": "UUPSUnsupportedProxiableUUID", "type": "error" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "uint64", "name": "version", "type": "uint64" }], "name": "Initialized", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" }], "name": "OwnershipTransferred", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "string", "name": "orderId", "type": "string" }, { "indexed": true, "internalType": "address", "name": "payer", "type": "address" }, { "indexed": true, "internalType": "string", "name": "anymalNftId", "type": "string" }, { "indexed": false, "internalType": "uint256", "name": "amountInTokens", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "timestamp", "type": "uint256" }], "name": "PartialPaymentMade", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "string", "name": "orderId", "type": "string" }, { "indexed": true, "internalType": "address", "name": "payer", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amountInTokens", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "timestamp", "type": "uint256" }], "name": "PaymentMade", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "string", "name": "orderId", "type": "string" }, { "indexed": true, "internalType": "address", "name": "payer", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "refundedAmount", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "timestamp", "type": "uint256" }], "name": "RefundProcessed", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "bool", "name": "enabled", "type": "bool" }], "name": "SignatureCheckToggled", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "implementation", "type": "address" }], "name": "Upgraded", "type": "event" }, { "inputs": [], "name": "UPGRADE_INTERFACE_VERSION", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "authorizer", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_initialOwner", "type": "address" }, { "internalType": "address", "name": "_authorizer", "type": "address" }, { "internalType": "address", "name": "_kibbleToken", "type": "address" }], "name": "initialize", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "kibbleToken", "outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "owner", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }, { "internalType": "address", "name": "", "type": "address" }], "name": "paidAmounts", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "string", "name": "orderId", "type": "string" }, { "internalType": "string", "name": "anymalNftId", "type": "string" }, { "internalType": "uint256", "name": "amountInTokens", "type": "uint256" }, { "internalType": "uint256", "name": "maxTokenPayment", "type": "uint256" }, { "internalType": "bytes32", "name": "nonce", "type": "bytes32" }, { "internalType": "uint256", "name": "deadline", "type": "uint256" }, { "internalType": "bytes", "name": "backendSignature", "type": "bytes" }], "name": "partialPay", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "proxiableUUID", "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "string", "name": "orderId", "type": "string" }, { "internalType": "address", "name": "payer", "type": "address" }], "name": "refund", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_authorizer", "type": "address" }], "name": "setAuthorizer", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "bool", "name": "enabled", "type": "bool" }], "name": "setSignatureCheckEnabled", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "signatureCheckEnabled", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], "name": "transferOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "newImplementation", "type": "address" }, { "internalType": "bytes", "name": "data", "type": "bytes" }], "name": "upgradeToAndCall", "outputs": [], "stateMutability": "payable", "type": "function" }, { "inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], "name": "usedNonces", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "to", "type": "address" }, { "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "withdrawKibble", "outputs": [], "stateMutability": "nonpayable", "type": "function" }];
602
606
 
603
607
  // src/utils/account/useVerifyAccount.ts
604
608
  function useVerifyAccount() {
@@ -624,8 +628,8 @@ function useVerifyAccount() {
624
628
  data: callData
625
629
  }
626
630
  ],
627
- maxPriorityFeePerGas: (0, import_viem.parseGwei)("0.599"),
628
- maxFeePerGas: (0, import_viem.parseGwei)("0.599")
631
+ maxPriorityFeePerGas: (0, import_viem.parseGwei)("5.599"),
632
+ maxFeePerGas: (0, import_viem.parseGwei)("5.599")
629
633
  });
630
634
  await bundlerClient.waitForUserOperationReceipt({
631
635
  hash: userOpHash
@@ -927,8 +931,8 @@ function useMintAnymalNFT() {
927
931
  data: callData
928
932
  }
929
933
  ],
930
- maxPriorityFeePerGas: (0, import_viem2.parseGwei)("0.599"),
931
- maxFeePerGas: (0, import_viem2.parseGwei)("0.599")
934
+ maxPriorityFeePerGas: (0, import_viem2.parseGwei)("5.599"),
935
+ maxFeePerGas: (0, import_viem2.parseGwei)("5.599")
932
936
  });
933
937
  await bundlerClient.waitForUserOperationReceipt({
934
938
  hash: userOpHash
@@ -1236,15 +1240,126 @@ function useUploadAnymalImage() {
1236
1240
  );
1237
1241
  }
1238
1242
 
1239
- // src/utils/application/useCreateUserAppData.ts
1243
+ // src/utils/marketplace/useProcessPartialKibblePayment.ts
1244
+ var import_viem3 = require("viem");
1240
1245
  var import_react15 = require("react");
1246
+ function useProcessPartialKibblePayment() {
1247
+ return (0, import_react15.useCallback)(
1248
+ async (pid, nftId, orderId, dbAuthToken, marketplaceContract, smartAccount, bundlerClient, amountInTokens, maxTokenPayment, nonce, deadline, backendSignature) => {
1249
+ if (!orderId || !dbAuthToken || !nftId || !bundlerClient || !smartAccount || !pid || !marketplaceContract || !amountInTokens || !maxTokenPayment || !nonce || !deadline) {
1250
+ return {
1251
+ success: false,
1252
+ message: "Missing required parameters for partial payment."
1253
+ };
1254
+ }
1255
+ try {
1256
+ const args = [
1257
+ orderId,
1258
+ // string
1259
+ nftId,
1260
+ // string
1261
+ amountInTokens,
1262
+ // uint256
1263
+ maxTokenPayment,
1264
+ // uint256
1265
+ nonce,
1266
+ // bytes32
1267
+ deadline,
1268
+ // uint256
1269
+ backendSignature
1270
+ // bytes
1271
+ ];
1272
+ console.info({ args });
1273
+ const callData = (0, import_viem3.encodeFunctionData)({
1274
+ abi: MARKETPLACE_ABI,
1275
+ functionName: "partialPay",
1276
+ args
1277
+ });
1278
+ const userOpHash = await bundlerClient.sendUserOperation({
1279
+ account: smartAccount,
1280
+ calls: [
1281
+ {
1282
+ to: marketplaceContract,
1283
+ data: callData
1284
+ }
1285
+ ],
1286
+ maxPriorityFeePerGas: (0, import_viem3.parseGwei)("0.001"),
1287
+ maxFeePerGas: (0, import_viem3.parseGwei)("0.01")
1288
+ });
1289
+ await bundlerClient.waitForUserOperationReceipt({
1290
+ hash: userOpHash
1291
+ });
1292
+ return { success: true, message: "Partial Kibble Payment Processed!" };
1293
+ } catch (error) {
1294
+ const errorMessage = error instanceof Error ? error.message : "An unknown error occurred";
1295
+ return {
1296
+ success: false,
1297
+ message: `Error processing payment: ${errorMessage}`
1298
+ };
1299
+ }
1300
+ },
1301
+ []
1302
+ );
1303
+ }
1304
+
1305
+ // src/utils/marketplace/useApproveKibbleToken.ts
1306
+ var import_viem4 = require("viem");
1307
+ var import_react16 = require("react");
1308
+ function useApproveKibbleToken() {
1309
+ return (0, import_react16.useCallback)(
1310
+ async (kibbleTokenAddress, marketplaceContract, amount, smartAccount, bundlerClient) => {
1311
+ try {
1312
+ const callData = (0, import_viem4.encodeFunctionData)({
1313
+ abi: import_viem4.erc20Abi,
1314
+ functionName: "approve",
1315
+ args: [
1316
+ marketplaceContract,
1317
+ // spender address
1318
+ BigInt(amount)
1319
+ // amount to approve
1320
+ ]
1321
+ });
1322
+ const userOpHash = await bundlerClient.sendUserOperation({
1323
+ account: smartAccount,
1324
+ calls: [
1325
+ {
1326
+ to: kibbleTokenAddress,
1327
+ data: callData
1328
+ }
1329
+ ],
1330
+ maxPriorityFeePerGas: (0, import_viem4.parseGwei)("0.001"),
1331
+ maxFeePerGas: (0, import_viem4.parseGwei)("0.01")
1332
+ });
1333
+ await bundlerClient.waitForUserOperationReceipt({
1334
+ hash: userOpHash
1335
+ });
1336
+ return { success: true, message: "Approval transaction completed successfully." };
1337
+ } catch (error) {
1338
+ const errorMessage = error instanceof Error ? error.message : "An unknown error occurred";
1339
+ return { success: false, message: `Error processing approval: ${errorMessage}` };
1340
+ }
1341
+ },
1342
+ []
1343
+ );
1344
+ }
1345
+
1346
+ // src/helpers/NonceHelper.tsx
1241
1347
  var import_uuid = require("uuid");
1348
+ var import_viem5 = require("viem");
1349
+ var generateBytes32Nonce = () => {
1350
+ const uuid2 = (0, import_uuid.v4)().replace(/-/g, "");
1351
+ return (0, import_viem5.padHex)(`0x${uuid2}`, { size: 32 });
1352
+ };
1353
+
1354
+ // src/utils/application/useCreateUserAppData.ts
1355
+ var import_react17 = require("react");
1356
+ var import_uuid2 = require("uuid");
1242
1357
  function useCreateUserAppData() {
1243
- return (0, import_react15.useCallback)(
1358
+ return (0, import_react17.useCallback)(
1244
1359
  async (appId, pid, dbAuthToken, endpoint) => {
1245
1360
  if (!dbAuthToken || !pid || !dbAuthToken || !endpoint) return;
1246
1361
  const appValues = {
1247
- id: (0, import_uuid.v4)(),
1362
+ id: (0, import_uuid2.v4)(),
1248
1363
  userPid: pid,
1249
1364
  appId,
1250
1365
  settings: {
@@ -1293,17 +1408,17 @@ function useCreateUserAppData() {
1293
1408
  }
1294
1409
 
1295
1410
  // src/utils/balance/useFetchBalance.ts
1296
- var import_react16 = require("react");
1297
- var import_viem3 = require("viem");
1411
+ var import_react18 = require("react");
1412
+ var import_viem6 = require("viem");
1298
1413
  function useFetchBalance() {
1299
- return (0, import_react16.useCallback)(
1414
+ return (0, import_react18.useCallback)(
1300
1415
  async (publicClient, walletAddress, kibbleTokenAddress) => {
1301
1416
  try {
1302
1417
  const balance = await publicClient.readContract({
1303
- address: (0, import_viem3.getAddress)(kibbleTokenAddress),
1304
- abi: import_viem3.erc20Abi,
1418
+ address: (0, import_viem6.getAddress)(kibbleTokenAddress),
1419
+ abi: import_viem6.erc20Abi,
1305
1420
  functionName: "balanceOf",
1306
- args: [(0, import_viem3.getAddress)(walletAddress)]
1421
+ args: [(0, import_viem6.getAddress)(walletAddress)]
1307
1422
  });
1308
1423
  return Number(balance);
1309
1424
  } catch (error) {
@@ -1315,13 +1430,16 @@ function useFetchBalance() {
1315
1430
  }
1316
1431
  // Annotate the CommonJS export names for ESM import in node:
1317
1432
  0 && (module.exports = {
1433
+ generateBytes32Nonce,
1318
1434
  useAddAnymalToDatabase,
1435
+ useApproveKibbleToken,
1319
1436
  useCreateUserAppData,
1320
1437
  useCreateWeb3Account,
1321
1438
  useDeleteAnymalFromDatabase,
1322
1439
  useFetchBalance,
1323
1440
  useFetchUserData,
1324
1441
  useMintAnymalNFT,
1442
+ useProcessPartialKibblePayment,
1325
1443
  useSaveAnymalMetadata,
1326
1444
  useUpdateAnymalWithNFT,
1327
1445
  useUpdateUserAsVerified,
package/dist/index.mjs CHANGED
@@ -558,6 +558,7 @@ var VERIFY_ACCOUNT_ABI = [
558
558
  type: "function"
559
559
  }
560
560
  ];
561
+ var MARKETPLACE_ABI = [{ "inputs": [{ "internalType": "address", "name": "target", "type": "address" }], "name": "AddressEmptyCode", "type": "error" }, { "inputs": [], "name": "ECDSAInvalidSignature", "type": "error" }, { "inputs": [{ "internalType": "uint256", "name": "length", "type": "uint256" }], "name": "ECDSAInvalidSignatureLength", "type": "error" }, { "inputs": [{ "internalType": "bytes32", "name": "s", "type": "bytes32" }], "name": "ECDSAInvalidSignatureS", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "implementation", "type": "address" }], "name": "ERC1967InvalidImplementation", "type": "error" }, { "inputs": [], "name": "ERC1967NonPayable", "type": "error" }, { "inputs": [], "name": "FailedCall", "type": "error" }, { "inputs": [], "name": "InvalidInitialization", "type": "error" }, { "inputs": [], "name": "NotInitializing", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "owner", "type": "address" }], "name": "OwnableInvalidOwner", "type": "error" }, { "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], "name": "OwnableUnauthorizedAccount", "type": "error" }, { "inputs": [], "name": "UUPSUnauthorizedCallContext", "type": "error" }, { "inputs": [{ "internalType": "bytes32", "name": "slot", "type": "bytes32" }], "name": "UUPSUnsupportedProxiableUUID", "type": "error" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "uint64", "name": "version", "type": "uint64" }], "name": "Initialized", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" }], "name": "OwnershipTransferred", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "string", "name": "orderId", "type": "string" }, { "indexed": true, "internalType": "address", "name": "payer", "type": "address" }, { "indexed": true, "internalType": "string", "name": "anymalNftId", "type": "string" }, { "indexed": false, "internalType": "uint256", "name": "amountInTokens", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "timestamp", "type": "uint256" }], "name": "PartialPaymentMade", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "string", "name": "orderId", "type": "string" }, { "indexed": true, "internalType": "address", "name": "payer", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amountInTokens", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "timestamp", "type": "uint256" }], "name": "PaymentMade", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "string", "name": "orderId", "type": "string" }, { "indexed": true, "internalType": "address", "name": "payer", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "refundedAmount", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "timestamp", "type": "uint256" }], "name": "RefundProcessed", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "bool", "name": "enabled", "type": "bool" }], "name": "SignatureCheckToggled", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "implementation", "type": "address" }], "name": "Upgraded", "type": "event" }, { "inputs": [], "name": "UPGRADE_INTERFACE_VERSION", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "authorizer", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_initialOwner", "type": "address" }, { "internalType": "address", "name": "_authorizer", "type": "address" }, { "internalType": "address", "name": "_kibbleToken", "type": "address" }], "name": "initialize", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "kibbleToken", "outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "owner", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }, { "internalType": "address", "name": "", "type": "address" }], "name": "paidAmounts", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "string", "name": "orderId", "type": "string" }, { "internalType": "string", "name": "anymalNftId", "type": "string" }, { "internalType": "uint256", "name": "amountInTokens", "type": "uint256" }, { "internalType": "uint256", "name": "maxTokenPayment", "type": "uint256" }, { "internalType": "bytes32", "name": "nonce", "type": "bytes32" }, { "internalType": "uint256", "name": "deadline", "type": "uint256" }, { "internalType": "bytes", "name": "backendSignature", "type": "bytes" }], "name": "partialPay", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "proxiableUUID", "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "string", "name": "orderId", "type": "string" }, { "internalType": "address", "name": "payer", "type": "address" }], "name": "refund", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_authorizer", "type": "address" }], "name": "setAuthorizer", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "bool", "name": "enabled", "type": "bool" }], "name": "setSignatureCheckEnabled", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "signatureCheckEnabled", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], "name": "transferOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "newImplementation", "type": "address" }, { "internalType": "bytes", "name": "data", "type": "bytes" }], "name": "upgradeToAndCall", "outputs": [], "stateMutability": "payable", "type": "function" }, { "inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], "name": "usedNonces", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "to", "type": "address" }, { "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "withdrawKibble", "outputs": [], "stateMutability": "nonpayable", "type": "function" }];
561
562
 
562
563
  // src/utils/account/useVerifyAccount.ts
563
564
  function useVerifyAccount() {
@@ -583,8 +584,8 @@ function useVerifyAccount() {
583
584
  data: callData
584
585
  }
585
586
  ],
586
- maxPriorityFeePerGas: parseGwei("0.599"),
587
- maxFeePerGas: parseGwei("0.599")
587
+ maxPriorityFeePerGas: parseGwei("5.599"),
588
+ maxFeePerGas: parseGwei("5.599")
588
589
  });
589
590
  await bundlerClient.waitForUserOperationReceipt({
590
591
  hash: userOpHash
@@ -886,8 +887,8 @@ function useMintAnymalNFT() {
886
887
  data: callData
887
888
  }
888
889
  ],
889
- maxPriorityFeePerGas: parseGwei2("0.599"),
890
- maxFeePerGas: parseGwei2("0.599")
890
+ maxPriorityFeePerGas: parseGwei2("5.599"),
891
+ maxFeePerGas: parseGwei2("5.599")
891
892
  });
892
893
  await bundlerClient.waitForUserOperationReceipt({
893
894
  hash: userOpHash
@@ -1195,11 +1196,122 @@ function useUploadAnymalImage() {
1195
1196
  );
1196
1197
  }
1197
1198
 
1198
- // src/utils/application/useCreateUserAppData.ts
1199
+ // src/utils/marketplace/useProcessPartialKibblePayment.ts
1200
+ import { encodeFunctionData as encodeFunctionData3, parseGwei as parseGwei3 } from "viem";
1199
1201
  import { useCallback as useCallback15 } from "react";
1202
+ function useProcessPartialKibblePayment() {
1203
+ return useCallback15(
1204
+ async (pid, nftId, orderId, dbAuthToken, marketplaceContract, smartAccount, bundlerClient, amountInTokens, maxTokenPayment, nonce, deadline, backendSignature) => {
1205
+ if (!orderId || !dbAuthToken || !nftId || !bundlerClient || !smartAccount || !pid || !marketplaceContract || !amountInTokens || !maxTokenPayment || !nonce || !deadline) {
1206
+ return {
1207
+ success: false,
1208
+ message: "Missing required parameters for partial payment."
1209
+ };
1210
+ }
1211
+ try {
1212
+ const args = [
1213
+ orderId,
1214
+ // string
1215
+ nftId,
1216
+ // string
1217
+ amountInTokens,
1218
+ // uint256
1219
+ maxTokenPayment,
1220
+ // uint256
1221
+ nonce,
1222
+ // bytes32
1223
+ deadline,
1224
+ // uint256
1225
+ backendSignature
1226
+ // bytes
1227
+ ];
1228
+ console.info({ args });
1229
+ const callData = encodeFunctionData3({
1230
+ abi: MARKETPLACE_ABI,
1231
+ functionName: "partialPay",
1232
+ args
1233
+ });
1234
+ const userOpHash = await bundlerClient.sendUserOperation({
1235
+ account: smartAccount,
1236
+ calls: [
1237
+ {
1238
+ to: marketplaceContract,
1239
+ data: callData
1240
+ }
1241
+ ],
1242
+ maxPriorityFeePerGas: parseGwei3("0.001"),
1243
+ maxFeePerGas: parseGwei3("0.01")
1244
+ });
1245
+ await bundlerClient.waitForUserOperationReceipt({
1246
+ hash: userOpHash
1247
+ });
1248
+ return { success: true, message: "Partial Kibble Payment Processed!" };
1249
+ } catch (error) {
1250
+ const errorMessage = error instanceof Error ? error.message : "An unknown error occurred";
1251
+ return {
1252
+ success: false,
1253
+ message: `Error processing payment: ${errorMessage}`
1254
+ };
1255
+ }
1256
+ },
1257
+ []
1258
+ );
1259
+ }
1260
+
1261
+ // src/utils/marketplace/useApproveKibbleToken.ts
1262
+ import { encodeFunctionData as encodeFunctionData4, erc20Abi, parseGwei as parseGwei4 } from "viem";
1263
+ import { useCallback as useCallback16 } from "react";
1264
+ function useApproveKibbleToken() {
1265
+ return useCallback16(
1266
+ async (kibbleTokenAddress, marketplaceContract, amount, smartAccount, bundlerClient) => {
1267
+ try {
1268
+ const callData = encodeFunctionData4({
1269
+ abi: erc20Abi,
1270
+ functionName: "approve",
1271
+ args: [
1272
+ marketplaceContract,
1273
+ // spender address
1274
+ BigInt(amount)
1275
+ // amount to approve
1276
+ ]
1277
+ });
1278
+ const userOpHash = await bundlerClient.sendUserOperation({
1279
+ account: smartAccount,
1280
+ calls: [
1281
+ {
1282
+ to: kibbleTokenAddress,
1283
+ data: callData
1284
+ }
1285
+ ],
1286
+ maxPriorityFeePerGas: parseGwei4("0.001"),
1287
+ maxFeePerGas: parseGwei4("0.01")
1288
+ });
1289
+ await bundlerClient.waitForUserOperationReceipt({
1290
+ hash: userOpHash
1291
+ });
1292
+ return { success: true, message: "Approval transaction completed successfully." };
1293
+ } catch (error) {
1294
+ const errorMessage = error instanceof Error ? error.message : "An unknown error occurred";
1295
+ return { success: false, message: `Error processing approval: ${errorMessage}` };
1296
+ }
1297
+ },
1298
+ []
1299
+ );
1300
+ }
1301
+
1302
+ // src/helpers/NonceHelper.tsx
1303
+ import { v4 as uuidv4 } from "uuid";
1304
+ import { padHex } from "viem";
1305
+ var generateBytes32Nonce = () => {
1306
+ const uuid2 = uuidv4().replace(/-/g, "");
1307
+ return padHex(`0x${uuid2}`, { size: 32 });
1308
+ };
1309
+
1310
+ // src/utils/application/useCreateUserAppData.ts
1311
+ import { useCallback as useCallback17 } from "react";
1200
1312
  import { v4 as uuid } from "uuid";
1201
1313
  function useCreateUserAppData() {
1202
- return useCallback15(
1314
+ return useCallback17(
1203
1315
  async (appId, pid, dbAuthToken, endpoint) => {
1204
1316
  if (!dbAuthToken || !pid || !dbAuthToken || !endpoint) return;
1205
1317
  const appValues = {
@@ -1252,15 +1364,15 @@ function useCreateUserAppData() {
1252
1364
  }
1253
1365
 
1254
1366
  // src/utils/balance/useFetchBalance.ts
1255
- import { useCallback as useCallback16 } from "react";
1256
- import { erc20Abi, getAddress } from "viem";
1367
+ import { useCallback as useCallback18 } from "react";
1368
+ import { erc20Abi as erc20Abi2, getAddress } from "viem";
1257
1369
  function useFetchBalance() {
1258
- return useCallback16(
1370
+ return useCallback18(
1259
1371
  async (publicClient, walletAddress, kibbleTokenAddress) => {
1260
1372
  try {
1261
1373
  const balance = await publicClient.readContract({
1262
1374
  address: getAddress(kibbleTokenAddress),
1263
- abi: erc20Abi,
1375
+ abi: erc20Abi2,
1264
1376
  functionName: "balanceOf",
1265
1377
  args: [getAddress(walletAddress)]
1266
1378
  });
@@ -1273,13 +1385,16 @@ function useFetchBalance() {
1273
1385
  );
1274
1386
  }
1275
1387
  export {
1388
+ generateBytes32Nonce,
1276
1389
  useAddAnymalToDatabase,
1390
+ useApproveKibbleToken,
1277
1391
  useCreateUserAppData,
1278
1392
  useCreateWeb3Account,
1279
1393
  useDeleteAnymalFromDatabase,
1280
1394
  useFetchBalance,
1281
1395
  useFetchUserData,
1282
1396
  useMintAnymalNFT,
1397
+ useProcessPartialKibblePayment,
1283
1398
  useSaveAnymalMetadata,
1284
1399
  useUpdateAnymalWithNFT,
1285
1400
  useUpdateUserAsVerified,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anymal-protocol",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
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
  "module": "dist/index.js",
@@ -9,7 +9,7 @@
9
9
  "dist"
10
10
  ],
11
11
  "scripts": {
12
- "test": "echo \"Error: no test specified\" && exit 1",
12
+ "test": "jest",
13
13
  "build": "tsup src/index.ts --format cjs,esm --dts",
14
14
  "prepublishOnly": "npm run build"
15
15
  },
@@ -29,9 +29,16 @@
29
29
  "viem": "^2.22.8"
30
30
  },
31
31
  "devDependencies": {
32
+ "@testing-library/jest-dom": "^6.6.3",
33
+ "@testing-library/react": "^16.2.0",
34
+ "@types/jest": "^29.5.14",
32
35
  "@types/react": "^19.0.7",
33
36
  "@types/react-dom": "^19.0.3",
37
+ "jest": "^29.7.0",
38
+ "jest-environment-jsdom": "^29.7.0",
39
+ "ts-jest": "^29.2.5",
34
40
  "tsup": "^8.3.5",
35
- "typescript": "^5.7.3"
41
+ "typescript": "^5.7.3",
42
+ "util": "^0.12.5"
36
43
  }
37
44
  }