anymal-protocol 1.0.45 → 1.0.46

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
@@ -1,3 +1,5 @@
1
+ import { BundlerClient } from 'viem/account-abstraction';
2
+
1
3
  declare function useVerifyAccount(): (pid: string, campaignId: string, dbAuthToken: string, bundlerClient: any, smartAccount: any, accountRewardsContractAddress: `0x${string}`) => Promise<{
2
4
  success: boolean;
3
5
  message: string;
@@ -90,6 +92,47 @@ declare function useApproveKibbleToken(): (kibbleTokenAddress: string, marketpla
90
92
  message: string;
91
93
  }>;
92
94
 
95
+ /**
96
+ * React hook to create a new organization on-chain via the Organization beacon contract.
97
+ *
98
+ * This method can only be called by an admin of the Anymal Organization Beacon contract
99
+ *
100
+ * @returns {Function} - Async function to create the organization.
101
+ *
102
+ *
103
+ * @returns {Promise<{ success: boolean; message: string; proxyAddress?: string; }>} - Success status and message.
104
+ */
105
+ declare function useCreateOrganizationBase(): (orgPid: string, orgName: string, ownerAddress: string, orgContractAddress: string, adminSmartAccount: any, bundlerClient: any) => Promise<{
106
+ success: boolean;
107
+ message: string;
108
+ proxyAddress?: string;
109
+ }>;
110
+
111
+ /**
112
+ * React hook to approve the PartialPaymentModule to spend tokens on behalf of the organization.
113
+ *
114
+ * The hook instructs the organization's contract (via executeCall) to execute an ERC20 approve call.
115
+ *
116
+ * @returns {Function} - Async function to process the approval.
117
+ */
118
+ declare function useApproveOrgPartialPayment(): (orgContractAddress: string, kibbleTokenAddress: string, partialPaymentModuleAddress: string, managerSmartAccount: any, bundlerClient: BundlerClient, approveAmount: bigint) => Promise<{
119
+ success: boolean;
120
+ message: string;
121
+ }>;
122
+
123
+ /**
124
+ * React hook to process a partial KIBBLE payment via the Organization contract.
125
+ *
126
+ * The hook instructs the organization's contract (via executeCall)
127
+ * to execute the partialPay call on the PartialPaymentModule.
128
+ *
129
+ * @returns {Function} - Async function to process the partial payment.
130
+ */
131
+ declare function useProcessOrgPartialKibblePayment(): (orgContractAddress: string, partialPaymentModuleAddress: string, managerSmartAccount: any, bundlerClient: BundlerClient, orderId: string, anymalNftId: string, pid: string, amountInTokens: bigint, maxTokenPayment: bigint, nonce: string, deadline: number, backendSignature: string) => Promise<{
132
+ success: boolean;
133
+ message: string;
134
+ }>;
135
+
93
136
  declare const generateBytes32Nonce: () => `0x${string}`;
94
137
 
95
138
  declare function useCreateUserAppData(): (appId: string, pid: string, dbAuthToken: string, endpoint: string) => Promise<{
@@ -99,4 +142,4 @@ declare function useCreateUserAppData(): (appId: string, pid: string, dbAuthToke
99
142
 
100
143
  declare function useFetchBalance(): (publicClient: any, walletAddress: string, kibbleTokenAddress: string) => Promise<number | undefined>;
101
144
 
102
- export { type AnymalNftMetadataInputData, type CreateAnymalInputData, generateBytes32Nonce, useAddAnymalToDatabase, useApproveKibbleToken, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
145
+ export { type AnymalNftMetadataInputData, type CreateAnymalInputData, generateBytes32Nonce, useAddAnymalToDatabase, useApproveKibbleToken, useApproveOrgPartialPayment, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { BundlerClient } from 'viem/account-abstraction';
2
+
1
3
  declare function useVerifyAccount(): (pid: string, campaignId: string, dbAuthToken: string, bundlerClient: any, smartAccount: any, accountRewardsContractAddress: `0x${string}`) => Promise<{
2
4
  success: boolean;
3
5
  message: string;
@@ -90,6 +92,47 @@ declare function useApproveKibbleToken(): (kibbleTokenAddress: string, marketpla
90
92
  message: string;
91
93
  }>;
92
94
 
95
+ /**
96
+ * React hook to create a new organization on-chain via the Organization beacon contract.
97
+ *
98
+ * This method can only be called by an admin of the Anymal Organization Beacon contract
99
+ *
100
+ * @returns {Function} - Async function to create the organization.
101
+ *
102
+ *
103
+ * @returns {Promise<{ success: boolean; message: string; proxyAddress?: string; }>} - Success status and message.
104
+ */
105
+ declare function useCreateOrganizationBase(): (orgPid: string, orgName: string, ownerAddress: string, orgContractAddress: string, adminSmartAccount: any, bundlerClient: any) => Promise<{
106
+ success: boolean;
107
+ message: string;
108
+ proxyAddress?: string;
109
+ }>;
110
+
111
+ /**
112
+ * React hook to approve the PartialPaymentModule to spend tokens on behalf of the organization.
113
+ *
114
+ * The hook instructs the organization's contract (via executeCall) to execute an ERC20 approve call.
115
+ *
116
+ * @returns {Function} - Async function to process the approval.
117
+ */
118
+ declare function useApproveOrgPartialPayment(): (orgContractAddress: string, kibbleTokenAddress: string, partialPaymentModuleAddress: string, managerSmartAccount: any, bundlerClient: BundlerClient, approveAmount: bigint) => Promise<{
119
+ success: boolean;
120
+ message: string;
121
+ }>;
122
+
123
+ /**
124
+ * React hook to process a partial KIBBLE payment via the Organization contract.
125
+ *
126
+ * The hook instructs the organization's contract (via executeCall)
127
+ * to execute the partialPay call on the PartialPaymentModule.
128
+ *
129
+ * @returns {Function} - Async function to process the partial payment.
130
+ */
131
+ declare function useProcessOrgPartialKibblePayment(): (orgContractAddress: string, partialPaymentModuleAddress: string, managerSmartAccount: any, bundlerClient: BundlerClient, orderId: string, anymalNftId: string, pid: string, amountInTokens: bigint, maxTokenPayment: bigint, nonce: string, deadline: number, backendSignature: string) => Promise<{
132
+ success: boolean;
133
+ message: string;
134
+ }>;
135
+
93
136
  declare const generateBytes32Nonce: () => `0x${string}`;
94
137
 
95
138
  declare function useCreateUserAppData(): (appId: string, pid: string, dbAuthToken: string, endpoint: string) => Promise<{
@@ -99,4 +142,4 @@ declare function useCreateUserAppData(): (appId: string, pid: string, dbAuthToke
99
142
 
100
143
  declare function useFetchBalance(): (publicClient: any, walletAddress: string, kibbleTokenAddress: string) => Promise<number | undefined>;
101
144
 
102
- export { type AnymalNftMetadataInputData, type CreateAnymalInputData, generateBytes32Nonce, useAddAnymalToDatabase, useApproveKibbleToken, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
145
+ export { type AnymalNftMetadataInputData, type CreateAnymalInputData, generateBytes32Nonce, useAddAnymalToDatabase, useApproveKibbleToken, useApproveOrgPartialPayment, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
package/dist/index.js CHANGED
@@ -23,6 +23,8 @@ __export(index_exports, {
23
23
  generateBytes32Nonce: () => generateBytes32Nonce,
24
24
  useAddAnymalToDatabase: () => useAddAnymalToDatabase,
25
25
  useApproveKibbleToken: () => useApproveKibbleToken,
26
+ useApproveOrgPartialPayment: () => useApproveOrgPartialPayment,
27
+ useCreateOrganizationBase: () => useCreateOrganizationBase,
26
28
  useCreateUserAppData: () => useCreateUserAppData,
27
29
  useCreateWeb3Account: () => useCreateWeb3Account,
28
30
  useDeleteAnymalFromDatabase: () => useDeleteAnymalFromDatabase,
@@ -30,6 +32,7 @@ __export(index_exports, {
30
32
  useFetchNotifications: () => useFetchNotifications,
31
33
  useFetchUserData: () => useFetchUserData,
32
34
  useMintAnymalNFT: () => useMintAnymalNFT,
35
+ useProcessOrgPartialKibblePayment: () => useProcessOrgPartialKibblePayment,
33
36
  useProcessPartialKibblePayment: () => useProcessPartialKibblePayment,
34
37
  useSaveAnymalMetadata: () => useSaveAnymalMetadata,
35
38
  useUpdateAnymalWithNFT: () => useUpdateAnymalWithNFT,
@@ -66,6 +69,245 @@ var VERIFY_ACCOUNT_ABI = [
66
69
  }
67
70
  ];
68
71
  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": "pid", "type": "string" }, { "indexed": false, "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": true, "internalType": "string", "name": "pid", "type": "string" }, { "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": "string", "name": "pid", "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" }, { "internalType": "string", "name": "pid", "type": "string" }], "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" }];
72
+ var ORGANIZATION_ABI = [
73
+ {
74
+ "inputs": [
75
+ {
76
+ "internalType": "address",
77
+ "name": "_initialImplementation",
78
+ "type": "address"
79
+ },
80
+ {
81
+ "internalType": "address",
82
+ "name": "_initialOwner",
83
+ "type": "address"
84
+ },
85
+ {
86
+ "internalType": "address",
87
+ "name": "_anymalNFTProxy",
88
+ "type": "address"
89
+ }
90
+ ],
91
+ "stateMutability": "nonpayable",
92
+ "type": "constructor"
93
+ },
94
+ {
95
+ "inputs": [
96
+ {
97
+ "internalType": "address",
98
+ "name": "implementation",
99
+ "type": "address"
100
+ }
101
+ ],
102
+ "name": "BeaconInvalidImplementation",
103
+ "type": "error"
104
+ },
105
+ {
106
+ "inputs": [
107
+ {
108
+ "internalType": "address",
109
+ "name": "owner",
110
+ "type": "address"
111
+ }
112
+ ],
113
+ "name": "OwnableInvalidOwner",
114
+ "type": "error"
115
+ },
116
+ {
117
+ "inputs": [
118
+ {
119
+ "internalType": "address",
120
+ "name": "account",
121
+ "type": "address"
122
+ }
123
+ ],
124
+ "name": "OwnableUnauthorizedAccount",
125
+ "type": "error"
126
+ },
127
+ {
128
+ "anonymous": false,
129
+ "inputs": [
130
+ {
131
+ "indexed": true,
132
+ "internalType": "string",
133
+ "name": "pid",
134
+ "type": "string"
135
+ },
136
+ {
137
+ "indexed": true,
138
+ "internalType": "string",
139
+ "name": "name",
140
+ "type": "string"
141
+ },
142
+ {
143
+ "indexed": false,
144
+ "internalType": "address",
145
+ "name": "proxyAddress",
146
+ "type": "address"
147
+ },
148
+ {
149
+ "indexed": false,
150
+ "internalType": "address",
151
+ "name": "networkAdmin",
152
+ "type": "address"
153
+ },
154
+ {
155
+ "indexed": false,
156
+ "internalType": "address",
157
+ "name": "userAdmin",
158
+ "type": "address"
159
+ }
160
+ ],
161
+ "name": "NewOrganizationCreated",
162
+ "type": "event"
163
+ },
164
+ {
165
+ "anonymous": false,
166
+ "inputs": [
167
+ {
168
+ "indexed": true,
169
+ "internalType": "address",
170
+ "name": "previousOwner",
171
+ "type": "address"
172
+ },
173
+ {
174
+ "indexed": true,
175
+ "internalType": "address",
176
+ "name": "newOwner",
177
+ "type": "address"
178
+ }
179
+ ],
180
+ "name": "OwnershipTransferred",
181
+ "type": "event"
182
+ },
183
+ {
184
+ "anonymous": false,
185
+ "inputs": [
186
+ {
187
+ "indexed": true,
188
+ "internalType": "address",
189
+ "name": "implementation",
190
+ "type": "address"
191
+ }
192
+ ],
193
+ "name": "Upgraded",
194
+ "type": "event"
195
+ },
196
+ {
197
+ "inputs": [],
198
+ "name": "anymalNFTProxy",
199
+ "outputs": [
200
+ {
201
+ "internalType": "address",
202
+ "name": "",
203
+ "type": "address"
204
+ }
205
+ ],
206
+ "stateMutability": "view",
207
+ "type": "function"
208
+ },
209
+ {
210
+ "inputs": [
211
+ {
212
+ "internalType": "address",
213
+ "name": "_userAdmin",
214
+ "type": "address"
215
+ },
216
+ {
217
+ "internalType": "string",
218
+ "name": "_orgName",
219
+ "type": "string"
220
+ },
221
+ {
222
+ "internalType": "string",
223
+ "name": "_orgPid",
224
+ "type": "string"
225
+ }
226
+ ],
227
+ "name": "createOrganizationProxy",
228
+ "outputs": [
229
+ {
230
+ "internalType": "address",
231
+ "name": "proxyAddress",
232
+ "type": "address"
233
+ }
234
+ ],
235
+ "stateMutability": "nonpayable",
236
+ "type": "function"
237
+ },
238
+ {
239
+ "inputs": [],
240
+ "name": "implementation",
241
+ "outputs": [
242
+ {
243
+ "internalType": "address",
244
+ "name": "",
245
+ "type": "address"
246
+ }
247
+ ],
248
+ "stateMutability": "view",
249
+ "type": "function"
250
+ },
251
+ {
252
+ "inputs": [],
253
+ "name": "owner",
254
+ "outputs": [
255
+ {
256
+ "internalType": "address",
257
+ "name": "",
258
+ "type": "address"
259
+ }
260
+ ],
261
+ "stateMutability": "view",
262
+ "type": "function"
263
+ },
264
+ {
265
+ "inputs": [],
266
+ "name": "renounceOwnership",
267
+ "outputs": [],
268
+ "stateMutability": "nonpayable",
269
+ "type": "function"
270
+ },
271
+ {
272
+ "inputs": [
273
+ {
274
+ "internalType": "address",
275
+ "name": "newOwner",
276
+ "type": "address"
277
+ }
278
+ ],
279
+ "name": "transferOwnership",
280
+ "outputs": [],
281
+ "stateMutability": "nonpayable",
282
+ "type": "function"
283
+ },
284
+ {
285
+ "inputs": [
286
+ {
287
+ "internalType": "address",
288
+ "name": "newImplementation",
289
+ "type": "address"
290
+ }
291
+ ],
292
+ "name": "upgradeBeaconTo",
293
+ "outputs": [],
294
+ "stateMutability": "nonpayable",
295
+ "type": "function"
296
+ },
297
+ {
298
+ "inputs": [
299
+ {
300
+ "internalType": "address",
301
+ "name": "newImplementation",
302
+ "type": "address"
303
+ }
304
+ ],
305
+ "name": "upgradeTo",
306
+ "outputs": [],
307
+ "stateMutability": "nonpayable",
308
+ "type": "function"
309
+ }
310
+ ];
69
311
 
70
312
  // src/utils/account/useVerifyAccount.ts
71
313
  function useVerifyAccount() {
@@ -898,19 +1140,207 @@ function useApproveKibbleToken() {
898
1140
  );
899
1141
  }
900
1142
 
1143
+ // src/utils/organization/useCreateOrganizationBase.ts
1144
+ var import_react18 = require("react");
1145
+ var import_viem5 = require("viem");
1146
+ function useCreateOrganizationBase() {
1147
+ return (0, import_react18.useCallback)(
1148
+ /**
1149
+ * Creates a new organization on-chain.
1150
+ *
1151
+ * @param orgPid - The PID of the organization as registered in DefraDB.
1152
+ * @param orgName - The name of the organization as registered in DefraDB.
1153
+ * @param ownerAddress - The wallet address of the user who will be the default manager.
1154
+ * @param orgContractAddress - The contract address of the organization beacon.
1155
+ * @param adminSmartAccount - The smart account of the Anymal network administrator approving this org.
1156
+ * @param bundlerClient - The viem BundlerClient instance used for sending the user operation.
1157
+ * @returns A promise with success status and message.
1158
+ */
1159
+ async (orgPid, orgName, ownerAddress, orgContractAddress, adminSmartAccount, bundlerClient) => {
1160
+ if (!orgPid || !orgName || !orgContractAddress || !bundlerClient || !adminSmartAccount || !ownerAddress) {
1161
+ return {
1162
+ success: false,
1163
+ message: "Missing required parameters for organization creation."
1164
+ };
1165
+ }
1166
+ try {
1167
+ const callData = (0, import_viem5.encodeFunctionData)({
1168
+ abi: ORGANIZATION_ABI,
1169
+ functionName: "createOrganizationProxy",
1170
+ args: [ownerAddress, orgName, orgPid]
1171
+ });
1172
+ const userOpHash = await bundlerClient.sendUserOperation({
1173
+ account: adminSmartAccount,
1174
+ calls: [
1175
+ {
1176
+ to: orgContractAddress,
1177
+ data: callData
1178
+ }
1179
+ ],
1180
+ maxPriorityFeePerGas: (0, import_viem5.parseGwei)("0.001"),
1181
+ // Low priority fee
1182
+ maxFeePerGas: (0, import_viem5.parseGwei)("0.025")
1183
+ // Max fee cap
1184
+ });
1185
+ const txReceipt = await bundlerClient.waitForUserOperationReceipt({
1186
+ hash: userOpHash
1187
+ });
1188
+ if (!txReceipt.success) {
1189
+ return {
1190
+ message: txReceipt.reason || "Unable to register organization.",
1191
+ success: false
1192
+ };
1193
+ }
1194
+ let proxyAddress;
1195
+ for (const log of txReceipt.logs) {
1196
+ try {
1197
+ const decoded = (0, import_viem5.decodeEventLog)({
1198
+ abi: ORGANIZATION_ABI,
1199
+ data: log.data,
1200
+ topics: log.topics
1201
+ });
1202
+ if (decoded.eventName === "NewOrganizationCreated") {
1203
+ proxyAddress = decoded.args.proxyAddress;
1204
+ break;
1205
+ }
1206
+ } catch {
1207
+ }
1208
+ }
1209
+ if (!proxyAddress) {
1210
+ return {
1211
+ success: true,
1212
+ message: "Organization registered successfully, but proxy address not found in logs."
1213
+ };
1214
+ }
1215
+ return {
1216
+ success: true,
1217
+ message: "Organization registered successfully.",
1218
+ proxyAddress
1219
+ };
1220
+ } catch (error) {
1221
+ const errorMessage = error instanceof Error ? error.message : "An unknown error occurred.";
1222
+ return {
1223
+ success: false,
1224
+ message: `Error processing organization: ${errorMessage}`
1225
+ };
1226
+ }
1227
+ },
1228
+ []
1229
+ );
1230
+ }
1231
+
1232
+ // src/utils/organization/useApproveOrgKibbleToken.ts
1233
+ var import_react19 = require("react");
1234
+ var import_viem6 = require("viem");
1235
+ function useApproveOrgPartialPayment() {
1236
+ return (0, import_react19.useCallback)(
1237
+ async (orgContractAddress, kibbleTokenAddress, partialPaymentModuleAddress, managerSmartAccount, bundlerClient, approveAmount) => {
1238
+ if (!orgContractAddress || !kibbleTokenAddress || !partialPaymentModuleAddress || !managerSmartAccount || !bundlerClient || !approveAmount) {
1239
+ return {
1240
+ success: false,
1241
+ message: "Missing required parameters for approval."
1242
+ };
1243
+ }
1244
+ try {
1245
+ const approveCalldata = (0, import_viem6.encodeFunctionData)({
1246
+ abi: import_viem6.erc20Abi,
1247
+ functionName: "approve",
1248
+ args: [partialPaymentModuleAddress, approveAmount]
1249
+ });
1250
+ const executeApproveCalldata = (0, import_viem6.encodeFunctionData)({
1251
+ abi: ORGANIZATION_ABI,
1252
+ functionName: "executeCall",
1253
+ args: [kibbleTokenAddress, approveCalldata]
1254
+ });
1255
+ const userOpApproveHash = await bundlerClient.sendUserOperation({
1256
+ account: managerSmartAccount,
1257
+ calls: [
1258
+ {
1259
+ to: orgContractAddress,
1260
+ data: executeApproveCalldata
1261
+ }
1262
+ ],
1263
+ maxPriorityFeePerGas: (0, import_viem6.parseGwei)("0.001")
1264
+ // maxFeePerGas: parseGwei("0.01"),
1265
+ });
1266
+ await bundlerClient.waitForUserOperationReceipt({ hash: userOpApproveHash });
1267
+ return { success: true, message: "Approval processed successfully." };
1268
+ } catch (error) {
1269
+ const errorMessage = error instanceof Error ? error.message : "An unknown error occurred.";
1270
+ return { success: false, message: `Error processing approval: ${errorMessage}` };
1271
+ }
1272
+ },
1273
+ []
1274
+ );
1275
+ }
1276
+
1277
+ // src/utils/organization/useProcessOrgPartialKibblePayment.ts
1278
+ var import_react20 = require("react");
1279
+ var import_viem7 = require("viem");
1280
+ function useProcessOrgPartialKibblePayment() {
1281
+ return (0, import_react20.useCallback)(
1282
+ async (orgContractAddress, partialPaymentModuleAddress, managerSmartAccount, bundlerClient, orderId, anymalNftId, pid, amountInTokens, maxTokenPayment, nonce, deadline, backendSignature) => {
1283
+ if (!orgContractAddress || !partialPaymentModuleAddress || !managerSmartAccount || !bundlerClient || !orderId || !pid || !nonce || !backendSignature) {
1284
+ return {
1285
+ success: false,
1286
+ message: "Missing required parameters for partial payment."
1287
+ };
1288
+ }
1289
+ try {
1290
+ const partialPayCalldata = (0, import_viem7.encodeFunctionData)({
1291
+ abi: MARKETPLACE_ABI,
1292
+ functionName: "partialPay",
1293
+ args: [
1294
+ orderId,
1295
+ anymalNftId,
1296
+ pid,
1297
+ amountInTokens,
1298
+ maxTokenPayment,
1299
+ nonce,
1300
+ deadline,
1301
+ backendSignature
1302
+ ]
1303
+ });
1304
+ const executePartialPayCalldata = (0, import_viem7.encodeFunctionData)({
1305
+ abi: ORGANIZATION_ABI,
1306
+ functionName: "executeCall",
1307
+ args: [partialPaymentModuleAddress, partialPayCalldata]
1308
+ });
1309
+ const userOpPartialPayHash = await bundlerClient.sendUserOperation({
1310
+ account: managerSmartAccount,
1311
+ calls: [
1312
+ {
1313
+ to: orgContractAddress,
1314
+ data: executePartialPayCalldata
1315
+ }
1316
+ ],
1317
+ maxPriorityFeePerGas: (0, import_viem7.parseGwei)("0.001")
1318
+ // maxFeePerGas: parseGwei("0.01"),
1319
+ });
1320
+ await bundlerClient.waitForUserOperationReceipt({ hash: userOpPartialPayHash });
1321
+ return { success: true, message: "Partial payment processed successfully." };
1322
+ } catch (error) {
1323
+ const errorMessage = error instanceof Error ? error.message : "An unknown error occurred.";
1324
+ return { success: false, message: `Error processing partial payment: ${errorMessage}` };
1325
+ }
1326
+ },
1327
+ []
1328
+ );
1329
+ }
1330
+
901
1331
  // src/helpers/NonceHelper.tsx
902
1332
  var import_uuid = require("uuid");
903
- var import_viem5 = require("viem");
1333
+ var import_viem8 = require("viem");
904
1334
  var generateBytes32Nonce = () => {
905
1335
  const uuid2 = (0, import_uuid.v4)().replace(/-/g, "");
906
- return (0, import_viem5.padHex)(`0x${uuid2}`, { size: 32 });
1336
+ return (0, import_viem8.padHex)(`0x${uuid2}`, { size: 32 });
907
1337
  };
908
1338
 
909
1339
  // src/utils/application/useCreateUserAppData.ts
910
- var import_react18 = require("react");
1340
+ var import_react21 = require("react");
911
1341
  var import_uuid2 = require("uuid");
912
1342
  function useCreateUserAppData() {
913
- return (0, import_react18.useCallback)(
1343
+ return (0, import_react21.useCallback)(
914
1344
  async (appId, pid, dbAuthToken, endpoint) => {
915
1345
  if (!dbAuthToken || !pid || !dbAuthToken || !endpoint) return;
916
1346
  const appValues = {
@@ -963,17 +1393,17 @@ function useCreateUserAppData() {
963
1393
  }
964
1394
 
965
1395
  // src/utils/balance/useFetchBalance.ts
966
- var import_react19 = require("react");
967
- var import_viem6 = require("viem");
1396
+ var import_react22 = require("react");
1397
+ var import_viem9 = require("viem");
968
1398
  function useFetchBalance() {
969
- return (0, import_react19.useCallback)(
1399
+ return (0, import_react22.useCallback)(
970
1400
  async (publicClient, walletAddress, kibbleTokenAddress) => {
971
1401
  try {
972
1402
  const balance = await publicClient.readContract({
973
- address: (0, import_viem6.getAddress)(kibbleTokenAddress),
974
- abi: import_viem6.erc20Abi,
1403
+ address: (0, import_viem9.getAddress)(kibbleTokenAddress),
1404
+ abi: import_viem9.erc20Abi,
975
1405
  functionName: "balanceOf",
976
- args: [(0, import_viem6.getAddress)(walletAddress)]
1406
+ args: [(0, import_viem9.getAddress)(walletAddress)]
977
1407
  });
978
1408
  return Number(balance);
979
1409
  } catch (error) {
@@ -988,6 +1418,8 @@ function useFetchBalance() {
988
1418
  generateBytes32Nonce,
989
1419
  useAddAnymalToDatabase,
990
1420
  useApproveKibbleToken,
1421
+ useApproveOrgPartialPayment,
1422
+ useCreateOrganizationBase,
991
1423
  useCreateUserAppData,
992
1424
  useCreateWeb3Account,
993
1425
  useDeleteAnymalFromDatabase,
@@ -995,6 +1427,7 @@ function useFetchBalance() {
995
1427
  useFetchNotifications,
996
1428
  useFetchUserData,
997
1429
  useMintAnymalNFT,
1430
+ useProcessOrgPartialKibblePayment,
998
1431
  useProcessPartialKibblePayment,
999
1432
  useSaveAnymalMetadata,
1000
1433
  useUpdateAnymalWithNFT,
package/dist/index.mjs CHANGED
@@ -21,6 +21,245 @@ var VERIFY_ACCOUNT_ABI = [
21
21
  }
22
22
  ];
23
23
  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": "pid", "type": "string" }, { "indexed": false, "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": true, "internalType": "string", "name": "pid", "type": "string" }, { "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": "string", "name": "pid", "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" }, { "internalType": "string", "name": "pid", "type": "string" }], "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" }];
24
+ var ORGANIZATION_ABI = [
25
+ {
26
+ "inputs": [
27
+ {
28
+ "internalType": "address",
29
+ "name": "_initialImplementation",
30
+ "type": "address"
31
+ },
32
+ {
33
+ "internalType": "address",
34
+ "name": "_initialOwner",
35
+ "type": "address"
36
+ },
37
+ {
38
+ "internalType": "address",
39
+ "name": "_anymalNFTProxy",
40
+ "type": "address"
41
+ }
42
+ ],
43
+ "stateMutability": "nonpayable",
44
+ "type": "constructor"
45
+ },
46
+ {
47
+ "inputs": [
48
+ {
49
+ "internalType": "address",
50
+ "name": "implementation",
51
+ "type": "address"
52
+ }
53
+ ],
54
+ "name": "BeaconInvalidImplementation",
55
+ "type": "error"
56
+ },
57
+ {
58
+ "inputs": [
59
+ {
60
+ "internalType": "address",
61
+ "name": "owner",
62
+ "type": "address"
63
+ }
64
+ ],
65
+ "name": "OwnableInvalidOwner",
66
+ "type": "error"
67
+ },
68
+ {
69
+ "inputs": [
70
+ {
71
+ "internalType": "address",
72
+ "name": "account",
73
+ "type": "address"
74
+ }
75
+ ],
76
+ "name": "OwnableUnauthorizedAccount",
77
+ "type": "error"
78
+ },
79
+ {
80
+ "anonymous": false,
81
+ "inputs": [
82
+ {
83
+ "indexed": true,
84
+ "internalType": "string",
85
+ "name": "pid",
86
+ "type": "string"
87
+ },
88
+ {
89
+ "indexed": true,
90
+ "internalType": "string",
91
+ "name": "name",
92
+ "type": "string"
93
+ },
94
+ {
95
+ "indexed": false,
96
+ "internalType": "address",
97
+ "name": "proxyAddress",
98
+ "type": "address"
99
+ },
100
+ {
101
+ "indexed": false,
102
+ "internalType": "address",
103
+ "name": "networkAdmin",
104
+ "type": "address"
105
+ },
106
+ {
107
+ "indexed": false,
108
+ "internalType": "address",
109
+ "name": "userAdmin",
110
+ "type": "address"
111
+ }
112
+ ],
113
+ "name": "NewOrganizationCreated",
114
+ "type": "event"
115
+ },
116
+ {
117
+ "anonymous": false,
118
+ "inputs": [
119
+ {
120
+ "indexed": true,
121
+ "internalType": "address",
122
+ "name": "previousOwner",
123
+ "type": "address"
124
+ },
125
+ {
126
+ "indexed": true,
127
+ "internalType": "address",
128
+ "name": "newOwner",
129
+ "type": "address"
130
+ }
131
+ ],
132
+ "name": "OwnershipTransferred",
133
+ "type": "event"
134
+ },
135
+ {
136
+ "anonymous": false,
137
+ "inputs": [
138
+ {
139
+ "indexed": true,
140
+ "internalType": "address",
141
+ "name": "implementation",
142
+ "type": "address"
143
+ }
144
+ ],
145
+ "name": "Upgraded",
146
+ "type": "event"
147
+ },
148
+ {
149
+ "inputs": [],
150
+ "name": "anymalNFTProxy",
151
+ "outputs": [
152
+ {
153
+ "internalType": "address",
154
+ "name": "",
155
+ "type": "address"
156
+ }
157
+ ],
158
+ "stateMutability": "view",
159
+ "type": "function"
160
+ },
161
+ {
162
+ "inputs": [
163
+ {
164
+ "internalType": "address",
165
+ "name": "_userAdmin",
166
+ "type": "address"
167
+ },
168
+ {
169
+ "internalType": "string",
170
+ "name": "_orgName",
171
+ "type": "string"
172
+ },
173
+ {
174
+ "internalType": "string",
175
+ "name": "_orgPid",
176
+ "type": "string"
177
+ }
178
+ ],
179
+ "name": "createOrganizationProxy",
180
+ "outputs": [
181
+ {
182
+ "internalType": "address",
183
+ "name": "proxyAddress",
184
+ "type": "address"
185
+ }
186
+ ],
187
+ "stateMutability": "nonpayable",
188
+ "type": "function"
189
+ },
190
+ {
191
+ "inputs": [],
192
+ "name": "implementation",
193
+ "outputs": [
194
+ {
195
+ "internalType": "address",
196
+ "name": "",
197
+ "type": "address"
198
+ }
199
+ ],
200
+ "stateMutability": "view",
201
+ "type": "function"
202
+ },
203
+ {
204
+ "inputs": [],
205
+ "name": "owner",
206
+ "outputs": [
207
+ {
208
+ "internalType": "address",
209
+ "name": "",
210
+ "type": "address"
211
+ }
212
+ ],
213
+ "stateMutability": "view",
214
+ "type": "function"
215
+ },
216
+ {
217
+ "inputs": [],
218
+ "name": "renounceOwnership",
219
+ "outputs": [],
220
+ "stateMutability": "nonpayable",
221
+ "type": "function"
222
+ },
223
+ {
224
+ "inputs": [
225
+ {
226
+ "internalType": "address",
227
+ "name": "newOwner",
228
+ "type": "address"
229
+ }
230
+ ],
231
+ "name": "transferOwnership",
232
+ "outputs": [],
233
+ "stateMutability": "nonpayable",
234
+ "type": "function"
235
+ },
236
+ {
237
+ "inputs": [
238
+ {
239
+ "internalType": "address",
240
+ "name": "newImplementation",
241
+ "type": "address"
242
+ }
243
+ ],
244
+ "name": "upgradeBeaconTo",
245
+ "outputs": [],
246
+ "stateMutability": "nonpayable",
247
+ "type": "function"
248
+ },
249
+ {
250
+ "inputs": [
251
+ {
252
+ "internalType": "address",
253
+ "name": "newImplementation",
254
+ "type": "address"
255
+ }
256
+ ],
257
+ "name": "upgradeTo",
258
+ "outputs": [],
259
+ "stateMutability": "nonpayable",
260
+ "type": "function"
261
+ }
262
+ ];
24
263
 
25
264
  // src/utils/account/useVerifyAccount.ts
26
265
  function useVerifyAccount() {
@@ -853,6 +1092,194 @@ function useApproveKibbleToken() {
853
1092
  );
854
1093
  }
855
1094
 
1095
+ // src/utils/organization/useCreateOrganizationBase.ts
1096
+ import { useCallback as useCallback18 } from "react";
1097
+ import { decodeEventLog, encodeFunctionData as encodeFunctionData5, parseGwei as parseGwei5 } from "viem";
1098
+ function useCreateOrganizationBase() {
1099
+ return useCallback18(
1100
+ /**
1101
+ * Creates a new organization on-chain.
1102
+ *
1103
+ * @param orgPid - The PID of the organization as registered in DefraDB.
1104
+ * @param orgName - The name of the organization as registered in DefraDB.
1105
+ * @param ownerAddress - The wallet address of the user who will be the default manager.
1106
+ * @param orgContractAddress - The contract address of the organization beacon.
1107
+ * @param adminSmartAccount - The smart account of the Anymal network administrator approving this org.
1108
+ * @param bundlerClient - The viem BundlerClient instance used for sending the user operation.
1109
+ * @returns A promise with success status and message.
1110
+ */
1111
+ async (orgPid, orgName, ownerAddress, orgContractAddress, adminSmartAccount, bundlerClient) => {
1112
+ if (!orgPid || !orgName || !orgContractAddress || !bundlerClient || !adminSmartAccount || !ownerAddress) {
1113
+ return {
1114
+ success: false,
1115
+ message: "Missing required parameters for organization creation."
1116
+ };
1117
+ }
1118
+ try {
1119
+ const callData = encodeFunctionData5({
1120
+ abi: ORGANIZATION_ABI,
1121
+ functionName: "createOrganizationProxy",
1122
+ args: [ownerAddress, orgName, orgPid]
1123
+ });
1124
+ const userOpHash = await bundlerClient.sendUserOperation({
1125
+ account: adminSmartAccount,
1126
+ calls: [
1127
+ {
1128
+ to: orgContractAddress,
1129
+ data: callData
1130
+ }
1131
+ ],
1132
+ maxPriorityFeePerGas: parseGwei5("0.001"),
1133
+ // Low priority fee
1134
+ maxFeePerGas: parseGwei5("0.025")
1135
+ // Max fee cap
1136
+ });
1137
+ const txReceipt = await bundlerClient.waitForUserOperationReceipt({
1138
+ hash: userOpHash
1139
+ });
1140
+ if (!txReceipt.success) {
1141
+ return {
1142
+ message: txReceipt.reason || "Unable to register organization.",
1143
+ success: false
1144
+ };
1145
+ }
1146
+ let proxyAddress;
1147
+ for (const log of txReceipt.logs) {
1148
+ try {
1149
+ const decoded = decodeEventLog({
1150
+ abi: ORGANIZATION_ABI,
1151
+ data: log.data,
1152
+ topics: log.topics
1153
+ });
1154
+ if (decoded.eventName === "NewOrganizationCreated") {
1155
+ proxyAddress = decoded.args.proxyAddress;
1156
+ break;
1157
+ }
1158
+ } catch {
1159
+ }
1160
+ }
1161
+ if (!proxyAddress) {
1162
+ return {
1163
+ success: true,
1164
+ message: "Organization registered successfully, but proxy address not found in logs."
1165
+ };
1166
+ }
1167
+ return {
1168
+ success: true,
1169
+ message: "Organization registered successfully.",
1170
+ proxyAddress
1171
+ };
1172
+ } catch (error) {
1173
+ const errorMessage = error instanceof Error ? error.message : "An unknown error occurred.";
1174
+ return {
1175
+ success: false,
1176
+ message: `Error processing organization: ${errorMessage}`
1177
+ };
1178
+ }
1179
+ },
1180
+ []
1181
+ );
1182
+ }
1183
+
1184
+ // src/utils/organization/useApproveOrgKibbleToken.ts
1185
+ import { useCallback as useCallback19 } from "react";
1186
+ import { encodeFunctionData as encodeFunctionData6, erc20Abi as erc20Abi2, parseGwei as parseGwei6 } from "viem";
1187
+ function useApproveOrgPartialPayment() {
1188
+ return useCallback19(
1189
+ async (orgContractAddress, kibbleTokenAddress, partialPaymentModuleAddress, managerSmartAccount, bundlerClient, approveAmount) => {
1190
+ if (!orgContractAddress || !kibbleTokenAddress || !partialPaymentModuleAddress || !managerSmartAccount || !bundlerClient || !approveAmount) {
1191
+ return {
1192
+ success: false,
1193
+ message: "Missing required parameters for approval."
1194
+ };
1195
+ }
1196
+ try {
1197
+ const approveCalldata = encodeFunctionData6({
1198
+ abi: erc20Abi2,
1199
+ functionName: "approve",
1200
+ args: [partialPaymentModuleAddress, approveAmount]
1201
+ });
1202
+ const executeApproveCalldata = encodeFunctionData6({
1203
+ abi: ORGANIZATION_ABI,
1204
+ functionName: "executeCall",
1205
+ args: [kibbleTokenAddress, approveCalldata]
1206
+ });
1207
+ const userOpApproveHash = await bundlerClient.sendUserOperation({
1208
+ account: managerSmartAccount,
1209
+ calls: [
1210
+ {
1211
+ to: orgContractAddress,
1212
+ data: executeApproveCalldata
1213
+ }
1214
+ ],
1215
+ maxPriorityFeePerGas: parseGwei6("0.001")
1216
+ // maxFeePerGas: parseGwei("0.01"),
1217
+ });
1218
+ await bundlerClient.waitForUserOperationReceipt({ hash: userOpApproveHash });
1219
+ return { success: true, message: "Approval processed successfully." };
1220
+ } catch (error) {
1221
+ const errorMessage = error instanceof Error ? error.message : "An unknown error occurred.";
1222
+ return { success: false, message: `Error processing approval: ${errorMessage}` };
1223
+ }
1224
+ },
1225
+ []
1226
+ );
1227
+ }
1228
+
1229
+ // src/utils/organization/useProcessOrgPartialKibblePayment.ts
1230
+ import { useCallback as useCallback20 } from "react";
1231
+ import { encodeFunctionData as encodeFunctionData7, parseGwei as parseGwei7 } from "viem";
1232
+ function useProcessOrgPartialKibblePayment() {
1233
+ return useCallback20(
1234
+ async (orgContractAddress, partialPaymentModuleAddress, managerSmartAccount, bundlerClient, orderId, anymalNftId, pid, amountInTokens, maxTokenPayment, nonce, deadline, backendSignature) => {
1235
+ if (!orgContractAddress || !partialPaymentModuleAddress || !managerSmartAccount || !bundlerClient || !orderId || !pid || !nonce || !backendSignature) {
1236
+ return {
1237
+ success: false,
1238
+ message: "Missing required parameters for partial payment."
1239
+ };
1240
+ }
1241
+ try {
1242
+ const partialPayCalldata = encodeFunctionData7({
1243
+ abi: MARKETPLACE_ABI,
1244
+ functionName: "partialPay",
1245
+ args: [
1246
+ orderId,
1247
+ anymalNftId,
1248
+ pid,
1249
+ amountInTokens,
1250
+ maxTokenPayment,
1251
+ nonce,
1252
+ deadline,
1253
+ backendSignature
1254
+ ]
1255
+ });
1256
+ const executePartialPayCalldata = encodeFunctionData7({
1257
+ abi: ORGANIZATION_ABI,
1258
+ functionName: "executeCall",
1259
+ args: [partialPaymentModuleAddress, partialPayCalldata]
1260
+ });
1261
+ const userOpPartialPayHash = await bundlerClient.sendUserOperation({
1262
+ account: managerSmartAccount,
1263
+ calls: [
1264
+ {
1265
+ to: orgContractAddress,
1266
+ data: executePartialPayCalldata
1267
+ }
1268
+ ],
1269
+ maxPriorityFeePerGas: parseGwei7("0.001")
1270
+ // maxFeePerGas: parseGwei("0.01"),
1271
+ });
1272
+ await bundlerClient.waitForUserOperationReceipt({ hash: userOpPartialPayHash });
1273
+ return { success: true, message: "Partial payment processed successfully." };
1274
+ } catch (error) {
1275
+ const errorMessage = error instanceof Error ? error.message : "An unknown error occurred.";
1276
+ return { success: false, message: `Error processing partial payment: ${errorMessage}` };
1277
+ }
1278
+ },
1279
+ []
1280
+ );
1281
+ }
1282
+
856
1283
  // src/helpers/NonceHelper.tsx
857
1284
  import { v4 as uuidv4 } from "uuid";
858
1285
  import { padHex } from "viem";
@@ -862,10 +1289,10 @@ var generateBytes32Nonce = () => {
862
1289
  };
863
1290
 
864
1291
  // src/utils/application/useCreateUserAppData.ts
865
- import { useCallback as useCallback18 } from "react";
1292
+ import { useCallback as useCallback21 } from "react";
866
1293
  import { v4 as uuid } from "uuid";
867
1294
  function useCreateUserAppData() {
868
- return useCallback18(
1295
+ return useCallback21(
869
1296
  async (appId, pid, dbAuthToken, endpoint) => {
870
1297
  if (!dbAuthToken || !pid || !dbAuthToken || !endpoint) return;
871
1298
  const appValues = {
@@ -918,15 +1345,15 @@ function useCreateUserAppData() {
918
1345
  }
919
1346
 
920
1347
  // src/utils/balance/useFetchBalance.ts
921
- import { useCallback as useCallback19 } from "react";
922
- import { erc20Abi as erc20Abi2, getAddress } from "viem";
1348
+ import { useCallback as useCallback22 } from "react";
1349
+ import { erc20Abi as erc20Abi3, getAddress } from "viem";
923
1350
  function useFetchBalance() {
924
- return useCallback19(
1351
+ return useCallback22(
925
1352
  async (publicClient, walletAddress, kibbleTokenAddress) => {
926
1353
  try {
927
1354
  const balance = await publicClient.readContract({
928
1355
  address: getAddress(kibbleTokenAddress),
929
- abi: erc20Abi2,
1356
+ abi: erc20Abi3,
930
1357
  functionName: "balanceOf",
931
1358
  args: [getAddress(walletAddress)]
932
1359
  });
@@ -942,6 +1369,8 @@ export {
942
1369
  generateBytes32Nonce,
943
1370
  useAddAnymalToDatabase,
944
1371
  useApproveKibbleToken,
1372
+ useApproveOrgPartialPayment,
1373
+ useCreateOrganizationBase,
945
1374
  useCreateUserAppData,
946
1375
  useCreateWeb3Account,
947
1376
  useDeleteAnymalFromDatabase,
@@ -949,6 +1378,7 @@ export {
949
1378
  useFetchNotifications,
950
1379
  useFetchUserData,
951
1380
  useMintAnymalNFT,
1381
+ useProcessOrgPartialKibblePayment,
952
1382
  useProcessPartialKibblePayment,
953
1383
  useSaveAnymalMetadata,
954
1384
  useUpdateAnymalWithNFT,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anymal-protocol",
3
- "version": "1.0.45",
3
+ "version": "1.0.46",
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",