@sudobility/contracts 0.15.1 → 1.9.0

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.
Files changed (171) hide show
  1. package/README.md +2 -3
  2. package/artifacts/contracts/Mailer.sol/Mailer.dbg.json +1 -1
  3. package/artifacts/contracts/Mailer.sol/Mailer.json +2 -278
  4. package/artifacts/contracts/MockUSDC.sol/MockUSDC.dbg.json +1 -1
  5. package/artifacts/contracts/interfaces/IERC20.sol/IERC20.dbg.json +1 -1
  6. package/dist/evm/src/evm/index.d.ts +1 -1
  7. package/dist/evm/src/evm/index.d.ts.map +1 -1
  8. package/dist/evm/src/evm/index.js +4 -4
  9. package/dist/evm/src/evm/index.js.map +1 -1
  10. package/dist/evm/src/evm/mailer-client.d.ts +210 -0
  11. package/dist/evm/src/evm/mailer-client.d.ts.map +1 -0
  12. package/dist/evm/src/evm/mailer-client.js +417 -0
  13. package/dist/evm/src/evm/mailer-client.js.map +1 -0
  14. package/dist/evm/typechain-types/Mailer.d.ts +10 -177
  15. package/dist/evm/typechain-types/Mailer.d.ts.map +1 -1
  16. package/dist/evm/typechain-types/factories/Mailer__factory.d.ts +1 -216
  17. package/dist/evm/typechain-types/factories/Mailer__factory.d.ts.map +1 -1
  18. package/dist/evm/typechain-types/factories/Mailer__factory.js +1 -277
  19. package/dist/evm/typechain-types/factories/Mailer__factory.js.map +1 -1
  20. package/dist/solana/solana/index.d.ts +1 -1
  21. package/dist/solana/solana/index.d.ts.map +1 -1
  22. package/dist/solana/solana/index.js +1 -4
  23. package/dist/solana/solana/index.js.map +1 -1
  24. package/dist/solana/solana/mailer-client.d.ts +209 -0
  25. package/dist/solana/solana/mailer-client.d.ts.map +1 -0
  26. package/dist/solana/solana/mailer-client.js +728 -0
  27. package/dist/solana/solana/mailer-client.js.map +1 -0
  28. package/dist/solana/solana/types.d.ts +2 -3
  29. package/dist/solana/solana/types.d.ts.map +1 -1
  30. package/dist/solana/solana/types.js.map +1 -1
  31. package/dist/unified/src/evm/index.d.ts +1 -1
  32. package/dist/unified/src/evm/index.d.ts.map +1 -1
  33. package/dist/unified/src/evm/index.js +4 -4
  34. package/dist/unified/src/evm/index.js.map +1 -1
  35. package/dist/unified/src/evm/mailer-client.d.ts +210 -0
  36. package/dist/unified/src/evm/mailer-client.d.ts.map +1 -0
  37. package/dist/unified/src/evm/mailer-client.js +417 -0
  38. package/dist/unified/src/evm/mailer-client.js.map +1 -0
  39. package/dist/unified/src/react/context/MailerProvider.d.ts +20 -26
  40. package/dist/unified/src/react/context/MailerProvider.d.ts.map +1 -1
  41. package/dist/unified/src/react/context/MailerProvider.js +26 -26
  42. package/dist/unified/src/react/context/MailerProvider.js.map +1 -1
  43. package/dist/unified/src/react/hooks/useMailerMutations.d.ts +192 -225
  44. package/dist/unified/src/react/hooks/useMailerMutations.d.ts.map +1 -1
  45. package/dist/unified/src/react/hooks/useMailerMutations.js +266 -263
  46. package/dist/unified/src/react/hooks/useMailerMutations.js.map +1 -1
  47. package/dist/unified/src/react/hooks/useMailerQueries.d.ts +63 -117
  48. package/dist/unified/src/react/hooks/useMailerQueries.d.ts.map +1 -1
  49. package/dist/unified/src/react/hooks/useMailerQueries.js +104 -239
  50. package/dist/unified/src/react/hooks/useMailerQueries.js.map +1 -1
  51. package/dist/unified/src/react/index.d.ts +3 -5
  52. package/dist/unified/src/react/index.d.ts.map +1 -1
  53. package/dist/unified/src/react/index.js +26 -41
  54. package/dist/unified/src/react/index.js.map +1 -1
  55. package/dist/unified/src/solana/index.d.ts +1 -1
  56. package/dist/unified/src/solana/index.d.ts.map +1 -1
  57. package/dist/unified/src/solana/index.js +1 -4
  58. package/dist/unified/src/solana/index.js.map +1 -1
  59. package/dist/unified/src/solana/mailer-client.d.ts +209 -0
  60. package/dist/unified/src/solana/mailer-client.d.ts.map +1 -0
  61. package/dist/unified/src/solana/mailer-client.js +728 -0
  62. package/dist/unified/src/solana/mailer-client.js.map +1 -0
  63. package/dist/unified/src/solana/types.d.ts +2 -3
  64. package/dist/unified/src/solana/types.d.ts.map +1 -1
  65. package/dist/unified/src/solana/types.js.map +1 -1
  66. package/dist/unified/src/unified/index.d.ts +1 -1
  67. package/dist/unified/src/unified/index.d.ts.map +1 -1
  68. package/dist/unified/src/unified/onchain-mailer-client.d.ts +247 -192
  69. package/dist/unified/src/unified/onchain-mailer-client.d.ts.map +1 -1
  70. package/dist/unified/src/unified/onchain-mailer-client.js +1462 -551
  71. package/dist/unified/src/unified/onchain-mailer-client.js.map +1 -1
  72. package/dist/unified/src/unified/types.d.ts +6 -23
  73. package/dist/unified/src/unified/types.d.ts.map +1 -1
  74. package/dist/unified/src/utils/chain-config.d.ts +2 -4
  75. package/dist/unified/src/utils/chain-config.d.ts.map +1 -1
  76. package/dist/unified/src/utils/chain-config.js +36 -46
  77. package/dist/unified/src/utils/chain-config.js.map +1 -1
  78. package/dist/unified/typechain-types/Mailer.d.ts +10 -177
  79. package/dist/unified/typechain-types/Mailer.d.ts.map +1 -1
  80. package/dist/unified/typechain-types/factories/Mailer__factory.d.ts +1 -216
  81. package/dist/unified/typechain-types/factories/Mailer__factory.d.ts.map +1 -1
  82. package/dist/unified/typechain-types/factories/Mailer__factory.js +1 -277
  83. package/dist/unified/typechain-types/factories/Mailer__factory.js.map +1 -1
  84. package/dist/unified-esm/src/evm/index.d.ts +1 -1
  85. package/dist/unified-esm/src/evm/index.d.ts.map +1 -1
  86. package/dist/unified-esm/src/evm/index.js +2 -2
  87. package/dist/unified-esm/src/evm/index.js.map +1 -1
  88. package/dist/unified-esm/src/evm/mailer-client.d.ts +210 -0
  89. package/dist/unified-esm/src/evm/mailer-client.d.ts.map +1 -0
  90. package/dist/unified-esm/src/evm/mailer-client.js +413 -0
  91. package/dist/unified-esm/src/evm/mailer-client.js.map +1 -0
  92. package/dist/unified-esm/src/react/context/MailerProvider.d.ts +20 -26
  93. package/dist/unified-esm/src/react/context/MailerProvider.d.ts.map +1 -1
  94. package/dist/unified-esm/src/react/context/MailerProvider.js +26 -25
  95. package/dist/unified-esm/src/react/context/MailerProvider.js.map +1 -1
  96. package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts +192 -225
  97. package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts.map +1 -1
  98. package/dist/unified-esm/src/react/hooks/useMailerMutations.js +262 -254
  99. package/dist/unified-esm/src/react/hooks/useMailerMutations.js.map +1 -1
  100. package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts +63 -117
  101. package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts.map +1 -1
  102. package/dist/unified-esm/src/react/hooks/useMailerQueries.js +102 -232
  103. package/dist/unified-esm/src/react/hooks/useMailerQueries.js.map +1 -1
  104. package/dist/unified-esm/src/react/index.d.ts +3 -5
  105. package/dist/unified-esm/src/react/index.d.ts.map +1 -1
  106. package/dist/unified-esm/src/react/index.js +5 -9
  107. package/dist/unified-esm/src/react/index.js.map +1 -1
  108. package/dist/unified-esm/src/solana/index.d.ts +1 -1
  109. package/dist/unified-esm/src/solana/index.d.ts.map +1 -1
  110. package/dist/unified-esm/src/solana/index.js +1 -2
  111. package/dist/unified-esm/src/solana/index.js.map +1 -1
  112. package/dist/unified-esm/src/solana/mailer-client.d.ts +209 -0
  113. package/dist/unified-esm/src/solana/mailer-client.d.ts.map +1 -0
  114. package/dist/unified-esm/src/solana/mailer-client.js +724 -0
  115. package/dist/unified-esm/src/solana/mailer-client.js.map +1 -0
  116. package/dist/unified-esm/src/solana/types.d.ts +2 -3
  117. package/dist/unified-esm/src/solana/types.d.ts.map +1 -1
  118. package/dist/unified-esm/src/solana/types.js.map +1 -1
  119. package/dist/unified-esm/src/unified/index.d.ts +1 -1
  120. package/dist/unified-esm/src/unified/index.d.ts.map +1 -1
  121. package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts +247 -192
  122. package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts.map +1 -1
  123. package/dist/unified-esm/src/unified/onchain-mailer-client.js +1462 -551
  124. package/dist/unified-esm/src/unified/onchain-mailer-client.js.map +1 -1
  125. package/dist/unified-esm/src/unified/types.d.ts +6 -23
  126. package/dist/unified-esm/src/unified/types.d.ts.map +1 -1
  127. package/dist/unified-esm/src/utils/chain-config.d.ts +2 -4
  128. package/dist/unified-esm/src/utils/chain-config.d.ts.map +1 -1
  129. package/dist/unified-esm/src/utils/chain-config.js +35 -46
  130. package/dist/unified-esm/src/utils/chain-config.js.map +1 -1
  131. package/dist/unified-esm/typechain-types/Mailer.d.ts +10 -177
  132. package/dist/unified-esm/typechain-types/Mailer.d.ts.map +1 -1
  133. package/dist/unified-esm/typechain-types/factories/Mailer__factory.d.ts +1 -216
  134. package/dist/unified-esm/typechain-types/factories/Mailer__factory.d.ts.map +1 -1
  135. package/dist/unified-esm/typechain-types/factories/Mailer__factory.js +1 -277
  136. package/dist/unified-esm/typechain-types/factories/Mailer__factory.js.map +1 -1
  137. package/package.json +11 -22
  138. package/programs/mailer/src/lib.rs +171 -1026
  139. package/programs/mailer/tests/integration_tests.rs +65 -586
  140. package/typechain-types/Mailer.ts +8 -319
  141. package/typechain-types/factories/Mailer__factory.ts +1 -277
  142. package/artifacts/contracts/Mailer.sol/Mailer.d.ts +0 -1146
  143. package/artifacts/contracts/Mailer.sol/artifacts.d.ts +0 -21
  144. package/artifacts/contracts/MockUSDC.sol/MockUSDC.d.ts +0 -284
  145. package/artifacts/contracts/MockUSDC.sol/artifacts.d.ts +0 -21
  146. package/artifacts/contracts/interfaces/IERC20.sol/IERC20.d.ts +0 -157
  147. package/artifacts/contracts/interfaces/IERC20.sol/artifacts.d.ts +0 -21
  148. package/dist/evm/src/evm/evm-mailer-client.d.ts +0 -1062
  149. package/dist/evm/src/evm/evm-mailer-client.d.ts.map +0 -1
  150. package/dist/evm/src/evm/evm-mailer-client.js +0 -924
  151. package/dist/evm/src/evm/evm-mailer-client.js.map +0 -1
  152. package/dist/solana/solana/solana-mailer-client.d.ts +0 -209
  153. package/dist/solana/solana/solana-mailer-client.d.ts.map +0 -1
  154. package/dist/solana/solana/solana-mailer-client.js +0 -1004
  155. package/dist/solana/solana/solana-mailer-client.js.map +0 -1
  156. package/dist/unified/src/evm/evm-mailer-client.d.ts +0 -1062
  157. package/dist/unified/src/evm/evm-mailer-client.d.ts.map +0 -1
  158. package/dist/unified/src/evm/evm-mailer-client.js +0 -924
  159. package/dist/unified/src/evm/evm-mailer-client.js.map +0 -1
  160. package/dist/unified/src/solana/solana-mailer-client.d.ts +0 -209
  161. package/dist/unified/src/solana/solana-mailer-client.d.ts.map +0 -1
  162. package/dist/unified/src/solana/solana-mailer-client.js +0 -1004
  163. package/dist/unified/src/solana/solana-mailer-client.js.map +0 -1
  164. package/dist/unified-esm/src/evm/evm-mailer-client.d.ts +0 -1062
  165. package/dist/unified-esm/src/evm/evm-mailer-client.d.ts.map +0 -1
  166. package/dist/unified-esm/src/evm/evm-mailer-client.js +0 -920
  167. package/dist/unified-esm/src/evm/evm-mailer-client.js.map +0 -1
  168. package/dist/unified-esm/src/solana/solana-mailer-client.d.ts +0 -209
  169. package/dist/unified-esm/src/solana/solana-mailer-client.d.ts.map +0 -1
  170. package/dist/unified-esm/src/solana/solana-mailer-client.js +0 -1000
  171. package/dist/unified-esm/src/solana/solana-mailer-client.js.map +0 -1
@@ -1,392 +1,400 @@
1
1
  import { useMutation, useQueryClient } from '@tanstack/react-query';
2
+ import { useMailerClient } from '../context/MailerProvider.js';
2
3
  import { mailerQueryKeys } from './useMailerQueries.js';
3
4
  /**
4
- * Hook for message-related operations
5
+ * Hook to send a message
5
6
  *
6
7
  * @example
7
8
  * ```tsx
8
- * function MessageSender() {
9
- * const client = useMailerClient(); // Get client from context or create it
10
- * const { sendMessage, sendPrepared } = useMessaging(client, wallet, chainInfo);
9
+ * function SendMessageForm() {
10
+ * const sendMessage = useSendMessage();
11
11
  *
12
12
  * const handleSend = () => {
13
13
  * sendMessage.mutate({
14
14
  * subject: 'Hello',
15
15
  * body: 'World!',
16
- * priority: true
16
+ * priority: true,
17
+ * resolveSenderToName: false
17
18
  * });
18
19
  * };
19
20
  *
20
21
  * return (
21
22
  * <button onClick={handleSend} disabled={sendMessage.isPending}>
22
- * Send Message
23
+ * {sendMessage.isPending ? 'Sending...' : 'Send Message'}
23
24
  * </button>
24
25
  * );
25
26
  * }
26
27
  * ```
27
28
  */
28
- export function useMessaging(client, connectedWallet, chainInfo, options) {
29
+ export function useSendMessage(options) {
30
+ const client = useMailerClient();
29
31
  const queryClient = useQueryClient();
30
- const sendMessage = useMutation({
31
- mutationFn: async ({ subject, body, priority = false, resolveSenderToName = false }) => client.sendMessage(connectedWallet, chainInfo, subject, body, { priority, resolveSenderToName }),
32
- onSuccess: () => {
33
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.claimableAmount() });
34
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.ownerClaimable() });
35
- },
36
- ...options?.sendMessage,
37
- });
38
- const sendPrepared = useMutation({
39
- mutationFn: async ({ to, mailId, priority = false, resolveSenderToName = false }) => client.sendPrepared(connectedWallet, chainInfo, to, mailId, { priority, resolveSenderToName }),
32
+ return useMutation({
33
+ mutationFn: async ({ subject, body, priority = false, resolveSenderToName = false }) => client.sendMessage(subject, body, priority, resolveSenderToName),
40
34
  onSuccess: () => {
35
+ // Invalidate claimable amounts as sending affects balances
41
36
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.claimableAmount() });
42
37
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.ownerClaimable() });
43
38
  },
44
- ...options?.sendPrepared,
39
+ ...options,
45
40
  });
46
- return {
47
- sendMessage,
48
- sendPrepared,
49
- };
50
41
  }
51
42
  /**
52
- * Hook for claim-related operations
43
+ * Hook to send a prepared message
53
44
  *
54
45
  * @example
55
46
  * ```tsx
56
- * function ClaimPanel() {
57
- * const { claimRevenue, claimOwnerShare, claimExpiredShares } = useClaims(client, wallet, chainInfo);
47
+ * function SendPreparedButton() {
48
+ * const sendPrepared = useSendPrepared();
58
49
  *
59
50
  * return (
60
- * <div>
61
- * <button onClick={() => claimRevenue.mutate()}>
62
- * Claim Revenue
63
- * </button>
64
- * <button onClick={() => claimOwnerShare.mutate()}>
65
- * Claim Owner Share
66
- * </button>
67
- * </div>
51
+ * <button
52
+ * onClick={() => sendPrepared.mutate({
53
+ * to: '0x123...',
54
+ * mailId: 'template-001',
55
+ * priority: true
56
+ * })}
57
+ * disabled={sendPrepared.isPending}
58
+ * >
59
+ * Send Prepared
60
+ * </button>
68
61
  * );
69
62
  * }
70
63
  * ```
71
64
  */
72
- export function useClaims(client, connectedWallet, chainInfo, options) {
65
+ export function useSendPrepared(options) {
66
+ const client = useMailerClient();
73
67
  const queryClient = useQueryClient();
74
- const claimRevenue = useMutation({
75
- mutationFn: () => client.claimRevenue(connectedWallet, chainInfo),
68
+ return useMutation({
69
+ mutationFn: async ({ to, mailId, priority = false, resolveSenderToName = false }) => client.sendPrepared(to, mailId, priority, resolveSenderToName),
76
70
  onSuccess: () => {
77
71
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.claimableAmount() });
78
- },
79
- ...options?.claimRevenue,
80
- });
81
- const claimOwnerShare = useMutation({
82
- mutationFn: () => client.claimOwnerShare(connectedWallet, chainInfo),
83
- onSuccess: () => {
84
72
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.ownerClaimable() });
85
73
  },
86
- ...options?.claimOwnerShare,
74
+ ...options,
87
75
  });
88
- const claimExpiredShares = useMutation({
89
- mutationFn: async ({ recipient }) => client.claimExpiredShares(connectedWallet, chainInfo, recipient),
90
- onSuccess: (_, variables) => {
91
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.claimableAmount(variables.recipient) });
92
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.ownerClaimable() });
93
- },
94
- ...options?.claimExpiredShares,
95
- });
96
- return {
97
- claimRevenue,
98
- claimOwnerShare,
99
- claimExpiredShares,
100
- };
101
76
  }
102
77
  /**
103
- * Hook for delegation-related operations
78
+ * Hook to send message to email address
104
79
  *
105
80
  * @example
106
81
  * ```tsx
107
- * function DelegationManager() {
108
- * const { delegateTo, rejectDelegation } = useDelegation(client, wallet, chainInfo);
82
+ * function SendToEmailForm() {
83
+ * const sendToEmail = useSendToEmail();
109
84
  *
110
85
  * return (
111
- * <>
112
- * <button onClick={() => delegateTo.mutate({ delegate: '0xABC...' })}>
113
- * Delegate
114
- * </button>
115
- * <button onClick={() => rejectDelegation.mutate({ delegatorAddress: '0xDEF...' })}>
116
- * Reject Delegation
117
- * </button>
118
- * </>
86
+ * <button
87
+ * onClick={() => sendToEmail.mutate({
88
+ * toEmail: 'user@example.com',
89
+ * subject: 'Hello',
90
+ * body: 'Welcome!'
91
+ * })}
92
+ * >
93
+ * Send to Email
94
+ * </button>
119
95
  * );
120
96
  * }
121
97
  * ```
122
98
  */
123
- export function useDelegation(client, connectedWallet, chainInfo, options) {
99
+ export function useSendToEmail(options) {
100
+ const client = useMailerClient();
124
101
  const queryClient = useQueryClient();
125
- const delegateTo = useMutation({
126
- mutationFn: async ({ delegate }) => client.delegateTo(connectedWallet, chainInfo, delegate),
102
+ return useMutation({
103
+ mutationFn: async ({ toEmail, subject, body }) => client.sendToEmail(toEmail, subject, body),
127
104
  onSuccess: () => {
128
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.delegation() });
105
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.ownerClaimable() });
129
106
  },
130
- ...options?.delegateTo,
107
+ ...options,
131
108
  });
132
- const rejectDelegation = useMutation({
133
- mutationFn: async ({ delegatorAddress }) => client.rejectDelegation(connectedWallet, chainInfo, delegatorAddress),
109
+ }
110
+ /**
111
+ * Hook to send prepared message to email address
112
+ */
113
+ export function useSendPreparedToEmail(options) {
114
+ const client = useMailerClient();
115
+ const queryClient = useQueryClient();
116
+ return useMutation({
117
+ mutationFn: async ({ toEmail, mailId }) => client.sendPreparedToEmail(toEmail, mailId),
134
118
  onSuccess: () => {
135
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.delegation() });
119
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.ownerClaimable() });
136
120
  },
137
- ...options?.rejectDelegation,
121
+ ...options,
138
122
  });
139
- return {
140
- delegateTo,
141
- rejectDelegation,
142
- };
143
123
  }
144
124
  /**
145
- * Hook for permission-related operations (EVM only)
125
+ * Hook to claim revenue share
146
126
  *
147
127
  * @example
148
128
  * ```tsx
149
- * function PermissionManager() {
150
- * const { setPermission, removePermission } = usePermissions(client, wallet, chainInfo);
129
+ * function ClaimButton() {
130
+ * const { data: claimable } = useGetClaimableAmount();
131
+ * const claimRevenue = useClaimRevenue();
132
+ *
133
+ * if (!claimable || claimable === 0n) return null;
151
134
  *
152
135
  * return (
153
- * <>
154
- * <button onClick={() => setPermission.mutate({ contractAddress: '0xABC...' })}>
155
- * Grant Permission
156
- * </button>
157
- * <button onClick={() => removePermission.mutate({ contractAddress: '0xABC...' })}>
158
- * Revoke Permission
159
- * </button>
160
- * </>
136
+ * <button
137
+ * onClick={() => claimRevenue.mutate()}
138
+ * disabled={claimRevenue.isPending}
139
+ * >
140
+ * Claim {Number(claimable) / 1_000_000} USDC
141
+ * </button>
161
142
  * );
162
143
  * }
163
144
  * ```
164
145
  */
165
- export function usePermissions(client, connectedWallet, chainInfo, options) {
146
+ export function useClaimRevenue(options) {
147
+ const client = useMailerClient();
166
148
  const queryClient = useQueryClient();
167
- const setPermission = useMutation({
168
- mutationFn: async ({ contractAddress }) => client.setPermission(connectedWallet, chainInfo, contractAddress),
149
+ return useMutation({
150
+ mutationFn: () => client.claimRevenue(),
169
151
  onSuccess: () => {
170
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.permissions() });
171
- },
172
- ...options?.setPermission,
173
- });
174
- const removePermission = useMutation({
175
- mutationFn: async ({ contractAddress }) => client.removePermission(connectedWallet, chainInfo, contractAddress),
176
- onSuccess: () => {
177
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.permissions() });
152
+ // Invalidate claimable amount after successful claim
153
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.claimableAmount() });
178
154
  },
179
- ...options?.removePermission,
155
+ ...options,
180
156
  });
181
- return {
182
- setPermission,
183
- removePermission,
184
- };
185
157
  }
186
158
  /**
187
- * Hook for contract control operations (owner only)
159
+ * Hook to claim owner share (owner only)
188
160
  *
189
161
  * @example
190
162
  * ```tsx
191
- * function ContractControls() {
192
- * const { pause, unpause, emergencyUnpause } = useContractControl(client, wallet, chainInfo);
163
+ * function OwnerClaimButton() {
164
+ * const { data: ownerClaimable } = useGetOwnerClaimable();
165
+ * const claimOwner = useClaimOwnerShare();
193
166
  *
194
167
  * return (
195
- * <>
196
- * <button onClick={() => pause.mutate()}>Pause</button>
197
- * <button onClick={() => unpause.mutate()}>Unpause</button>
198
- * <button onClick={() => emergencyUnpause.mutate()}>Emergency Unpause</button>
199
- * </>
168
+ * <button onClick={() => claimOwner.mutate()}>
169
+ * Claim Owner Fees: {Number(ownerClaimable) / 1_000_000} USDC
170
+ * </button>
200
171
  * );
201
172
  * }
202
173
  * ```
203
174
  */
204
- export function useContractControl(client, connectedWallet, chainInfo, options) {
175
+ export function useClaimOwnerShare(options) {
176
+ const client = useMailerClient();
205
177
  const queryClient = useQueryClient();
206
- const pause = useMutation({
207
- mutationFn: () => client.pause(connectedWallet, chainInfo),
178
+ return useMutation({
179
+ mutationFn: () => client.claimOwnerShare(),
208
180
  onSuccess: () => {
209
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.isPaused() });
210
181
  queryClient.invalidateQueries({ queryKey: mailerQueryKeys.ownerClaimable() });
211
182
  },
212
- ...options?.pause,
213
- });
214
- const unpause = useMutation({
215
- mutationFn: () => client.unpause(connectedWallet, chainInfo),
216
- onSuccess: () => {
217
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.isPaused() });
218
- },
219
- ...options?.unpause,
183
+ ...options,
220
184
  });
221
- const emergencyUnpause = useMutation({
222
- mutationFn: () => client.emergencyUnpause(connectedWallet, chainInfo),
223
- onSuccess: () => {
224
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.isPaused() });
185
+ }
186
+ /**
187
+ * Hook to claim expired shares (owner only, EVM only)
188
+ */
189
+ export function useClaimExpiredShares(options) {
190
+ const client = useMailerClient();
191
+ const queryClient = useQueryClient();
192
+ return useMutation({
193
+ mutationFn: async ({ recipient }) => client.claimExpiredShares(recipient),
194
+ onSuccess: (_, variables) => {
195
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.claimableAmount(variables.recipient) });
196
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.ownerClaimable() });
225
197
  },
226
- ...options?.emergencyUnpause,
198
+ ...options,
227
199
  });
228
- return {
229
- pause,
230
- unpause,
231
- emergencyUnpause,
232
- };
233
200
  }
234
201
  /**
235
- * Hook for owner-specific operations
202
+ * Hook to delegate to another address
236
203
  *
237
204
  * @example
238
205
  * ```tsx
239
- * function OwnerPanel() {
240
- * const { setFees, distributeClaimableFunds } = useOwnerOperations(client, wallet, chainInfo);
206
+ * function DelegateButton() {
207
+ * const delegate = useDelegateTo();
241
208
  *
242
209
  * return (
243
- * <>
244
- * <button onClick={() => setFees.mutate({ sendFee: 200000n, delegationFee: 10000000n })}>
245
- * Update Fees
246
- * </button>
247
- * <button onClick={() => distributeClaimableFunds.mutate({ recipient: '0xABC...' })}>
248
- * Distribute Funds
249
- * </button>
250
- * </>
210
+ * <button
211
+ * onClick={() => delegate.mutate({ delegate: '0xABC...' })}
212
+ * disabled={delegate.isPending}
213
+ * >
214
+ * Delegate
215
+ * </button>
251
216
  * );
252
217
  * }
253
218
  * ```
254
219
  */
255
- export function useOwnerOperations(client, connectedWallet, chainInfo, options) {
220
+ export function useDelegateTo(options) {
221
+ const client = useMailerClient();
256
222
  const queryClient = useQueryClient();
257
- const setFees = useMutation({
258
- mutationFn: async ({ sendFee, delegationFee }) => client.setFees(connectedWallet, chainInfo, sendFee, delegationFee),
223
+ return useMutation({
224
+ mutationFn: async ({ delegate }) => client.delegateTo(delegate),
259
225
  onSuccess: () => {
260
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.sendFee() });
261
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.delegationFee() });
262
- },
263
- ...options?.setFees,
264
- });
265
- const distributeClaimableFunds = useMutation({
266
- mutationFn: async ({ recipient }) => client.distributeClaimableFunds(connectedWallet, chainInfo, recipient),
267
- onSuccess: (_, variables) => {
268
- queryClient.invalidateQueries({ queryKey: mailerQueryKeys.claimableAmount(variables.recipient) });
226
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.delegation() });
269
227
  },
270
- ...options?.distributeClaimableFunds,
228
+ ...options,
271
229
  });
272
- return {
273
- setFees,
274
- distributeClaimableFunds,
275
- };
276
230
  }
277
- // ========== Legacy individual hooks for backward compatibility ==========
278
- // These use context for convenience but the grouped hooks above are preferred
279
- import { useMailerContext } from '../context/MailerProvider.js';
280
231
  /**
281
- * @deprecated Use useMessaging() instead
282
- */
283
- export function useSendMessage(options) {
284
- const { client, wallet, chainInfo } = useMailerContext();
285
- const { sendMessage } = useMessaging(client, wallet, chainInfo, { sendMessage: options });
286
- return sendMessage;
287
- }
288
- /**
289
- * @deprecated Use useMessaging() instead
290
- */
291
- export function useSendPrepared(options) {
292
- const { client, wallet, chainInfo } = useMailerContext();
293
- const { sendPrepared } = useMessaging(client, wallet, chainInfo, { sendPrepared: options });
294
- return sendPrepared;
295
- }
296
- /**
297
- * @deprecated Use useClaims() instead
298
- */
299
- export function useClaimRevenue(options) {
300
- const { client, wallet, chainInfo } = useMailerContext();
301
- const { claimRevenue } = useClaims(client, wallet, chainInfo, { claimRevenue: options });
302
- return claimRevenue;
303
- }
304
- /**
305
- * @deprecated Use useClaims() instead
306
- */
307
- export function useClaimOwnerShare(options) {
308
- const { client, wallet, chainInfo } = useMailerContext();
309
- const { claimOwnerShare } = useClaims(client, wallet, chainInfo, { claimOwnerShare: options });
310
- return claimOwnerShare;
311
- }
312
- /**
313
- * @deprecated Use useClaims() instead
314
- */
315
- export function useClaimExpiredShares(options) {
316
- const { client, wallet, chainInfo } = useMailerContext();
317
- const { claimExpiredShares } = useClaims(client, wallet, chainInfo, { claimExpiredShares: options });
318
- return claimExpiredShares;
319
- }
320
- /**
321
- * @deprecated Use useDelegation() instead
322
- */
323
- export function useDelegateTo(options) {
324
- const { client, wallet, chainInfo } = useMailerContext();
325
- const { delegateTo } = useDelegation(client, wallet, chainInfo, { delegateTo: options });
326
- return delegateTo;
327
- }
328
- /**
329
- * @deprecated Use useDelegation() instead
232
+ * Hook to reject a delegation made to you
233
+ *
234
+ * @example
235
+ * ```tsx
236
+ * function RejectDelegationButton({ delegatorAddress }: { delegatorAddress: string }) {
237
+ * const rejectDelegation = useRejectDelegation();
238
+ *
239
+ * return (
240
+ * <button
241
+ * onClick={() => rejectDelegation.mutate({ delegatorAddress })}
242
+ * >
243
+ * Reject Delegation
244
+ * </button>
245
+ * );
246
+ * }
247
+ * ```
330
248
  */
331
249
  export function useRejectDelegation(options) {
332
- const { client, wallet, chainInfo } = useMailerContext();
333
- const { rejectDelegation } = useDelegation(client, wallet, chainInfo, { rejectDelegation: options });
334
- return rejectDelegation;
335
- }
336
- /**
337
- * @deprecated Use usePermissions() instead
338
- */
339
- export function useSetPermission(options) {
340
- const { client, wallet, chainInfo } = useMailerContext();
341
- const { setPermission } = usePermissions(client, wallet, chainInfo, { setPermission: options });
342
- return setPermission;
250
+ const client = useMailerClient();
251
+ const queryClient = useQueryClient();
252
+ return useMutation({
253
+ mutationFn: async ({ delegatorAddress }) => client.rejectDelegation(delegatorAddress),
254
+ onSuccess: () => {
255
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.delegation() });
256
+ },
257
+ ...options,
258
+ });
343
259
  }
344
260
  /**
345
- * @deprecated Use usePermissions() instead
261
+ * Hook to set send fee (owner only)
262
+ *
263
+ * @example
264
+ * ```tsx
265
+ * function SetFeeForm() {
266
+ * const setFee = useSetFee();
267
+ *
268
+ * return (
269
+ * <button onClick={() => setFee.mutate({ newFee: 200000n })}>
270
+ * Update Fee to 0.2 USDC
271
+ * </button>
272
+ * );
273
+ * }
274
+ * ```
346
275
  */
347
- export function useRemovePermission(options) {
348
- const { client, wallet, chainInfo } = useMailerContext();
349
- const { removePermission } = usePermissions(client, wallet, chainInfo, { removePermission: options });
350
- return removePermission;
276
+ export function useSetFee(options) {
277
+ const client = useMailerClient();
278
+ const queryClient = useQueryClient();
279
+ return useMutation({
280
+ mutationFn: async ({ newFee }) => client.setFee(newFee),
281
+ onSuccess: () => {
282
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.sendFee() });
283
+ },
284
+ ...options,
285
+ });
351
286
  }
352
287
  /**
353
- * @deprecated Use useOwnerOperations() instead
288
+ * Hook to set delegation fee (owner only)
354
289
  */
355
- export function useSetFees(options) {
356
- const { client, wallet, chainInfo } = useMailerContext();
357
- const { setFees } = useOwnerOperations(client, wallet, chainInfo, { setFees: options });
358
- return setFees;
290
+ export function useSetDelegationFee(options) {
291
+ const client = useMailerClient();
292
+ const queryClient = useQueryClient();
293
+ return useMutation({
294
+ mutationFn: async ({ newFee }) => client.setDelegationFee(newFee),
295
+ onSuccess: () => {
296
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.delegationFee() });
297
+ },
298
+ ...options,
299
+ });
359
300
  }
360
301
  /**
361
- * @deprecated Use useContractControl() instead
302
+ * Hook to pause the contract (owner only)
303
+ *
304
+ * @example
305
+ * ```tsx
306
+ * function PauseButton() {
307
+ * const pause = usePause();
308
+ *
309
+ * return (
310
+ * <button
311
+ * onClick={() => pause.mutate()}
312
+ * disabled={pause.isPending}
313
+ * >
314
+ * Pause Contract
315
+ * </button>
316
+ * );
317
+ * }
318
+ * ```
362
319
  */
363
320
  export function usePause(options) {
364
- const { client, wallet, chainInfo } = useMailerContext();
365
- const { pause } = useContractControl(client, wallet, chainInfo, { pause: options });
366
- return pause;
321
+ const client = useMailerClient();
322
+ const queryClient = useQueryClient();
323
+ return useMutation({
324
+ mutationFn: () => client.pause(),
325
+ onSuccess: () => {
326
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.isPaused() });
327
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.ownerClaimable() });
328
+ },
329
+ ...options,
330
+ });
367
331
  }
368
332
  /**
369
- * @deprecated Use useContractControl() instead
333
+ * Hook to unpause the contract (owner only)
334
+ *
335
+ * @example
336
+ * ```tsx
337
+ * function UnpauseButton() {
338
+ * const unpause = useUnpause();
339
+ *
340
+ * return (
341
+ * <button onClick={() => unpause.mutate()}>
342
+ * Unpause Contract
343
+ * </button>
344
+ * );
345
+ * }
346
+ * ```
370
347
  */
371
348
  export function useUnpause(options) {
372
- const { client, wallet, chainInfo } = useMailerContext();
373
- const { unpause } = useContractControl(client, wallet, chainInfo, { unpause: options });
374
- return unpause;
349
+ const client = useMailerClient();
350
+ const queryClient = useQueryClient();
351
+ return useMutation({
352
+ mutationFn: () => client.unpause(),
353
+ onSuccess: () => {
354
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.isPaused() });
355
+ },
356
+ ...options,
357
+ });
375
358
  }
376
359
  /**
377
- * @deprecated Use useContractControl() instead
360
+ * Hook to emergency unpause (owner only)
378
361
  */
379
362
  export function useEmergencyUnpause(options) {
380
- const { client, wallet, chainInfo } = useMailerContext();
381
- const { emergencyUnpause } = useContractControl(client, wallet, chainInfo, { emergencyUnpause: options });
382
- return emergencyUnpause;
363
+ const client = useMailerClient();
364
+ const queryClient = useQueryClient();
365
+ return useMutation({
366
+ mutationFn: () => client.emergencyUnpause(),
367
+ onSuccess: () => {
368
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.isPaused() });
369
+ },
370
+ ...options,
371
+ });
383
372
  }
384
373
  /**
385
- * @deprecated Use useOwnerOperations() instead
374
+ * Hook to distribute claimable funds (anyone can call when paused)
375
+ *
376
+ * @example
377
+ * ```tsx
378
+ * function DistributeFundsButton({ recipient }: { recipient: string }) {
379
+ * const distribute = useDistributeClaimableFunds();
380
+ *
381
+ * return (
382
+ * <button onClick={() => distribute.mutate({ recipient })}>
383
+ * Distribute Funds to {recipient}
384
+ * </button>
385
+ * );
386
+ * }
387
+ * ```
386
388
  */
387
389
  export function useDistributeClaimableFunds(options) {
388
- const { client, wallet, chainInfo } = useMailerContext();
389
- const { distributeClaimableFunds } = useOwnerOperations(client, wallet, chainInfo, { distributeClaimableFunds: options });
390
- return distributeClaimableFunds;
390
+ const client = useMailerClient();
391
+ const queryClient = useQueryClient();
392
+ return useMutation({
393
+ mutationFn: async ({ recipient }) => client.distributeClaimableFunds(recipient),
394
+ onSuccess: (_, variables) => {
395
+ queryClient.invalidateQueries({ queryKey: mailerQueryKeys.claimableAmount(variables.recipient) });
396
+ },
397
+ ...options,
398
+ });
391
399
  }
392
400
  //# sourceMappingURL=useMailerMutations.js.map