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