@paylobster/mcp-server 1.5.0 → 1.7.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 (167) hide show
  1. package/README.md +147 -228
  2. package/dist/cli.d.ts +3 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +86 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +3 -19
  9. package/dist/index.js.map +1 -1
  10. package/dist/resources/index.d.ts +9 -0
  11. package/dist/resources/index.d.ts.map +1 -0
  12. package/dist/resources/index.js +159 -0
  13. package/dist/resources/index.js.map +1 -0
  14. package/dist/server.d.ts +3 -6
  15. package/dist/server.d.ts.map +1 -1
  16. package/dist/server.js +1455 -114
  17. package/dist/server.js.map +1 -1
  18. package/dist/tools/balance.d.ts +5 -16
  19. package/dist/tools/balance.d.ts.map +1 -1
  20. package/dist/tools/balance.js +26 -44
  21. package/dist/tools/balance.js.map +1 -1
  22. package/dist/tools/bridge.d.ts +142 -0
  23. package/dist/tools/bridge.d.ts.map +1 -0
  24. package/dist/tools/bridge.js +121 -0
  25. package/dist/tools/bridge.js.map +1 -0
  26. package/dist/tools/cascade.d.ts +59 -0
  27. package/dist/tools/cascade.d.ts.map +1 -0
  28. package/dist/tools/cascade.js +119 -0
  29. package/dist/tools/cascade.js.map +1 -0
  30. package/dist/tools/compliance.d.ts +36 -0
  31. package/dist/tools/compliance.d.ts.map +1 -0
  32. package/dist/tools/compliance.js +57 -0
  33. package/dist/tools/compliance.js.map +1 -0
  34. package/dist/tools/convenience.d.ts +121 -0
  35. package/dist/tools/convenience.d.ts.map +1 -0
  36. package/dist/tools/convenience.js +331 -0
  37. package/dist/tools/convenience.js.map +1 -0
  38. package/dist/tools/credit.d.ts +46 -0
  39. package/dist/tools/credit.d.ts.map +1 -0
  40. package/dist/tools/credit.js +102 -0
  41. package/dist/tools/credit.js.map +1 -0
  42. package/dist/tools/disputes.d.ts +71 -0
  43. package/dist/tools/disputes.d.ts.map +1 -0
  44. package/dist/tools/disputes.js +121 -0
  45. package/dist/tools/disputes.js.map +1 -0
  46. package/dist/tools/escrow.d.ts +90 -31
  47. package/dist/tools/escrow.d.ts.map +1 -1
  48. package/dist/tools/escrow.js +215 -98
  49. package/dist/tools/escrow.js.map +1 -1
  50. package/dist/tools/intent.d.ts +78 -0
  51. package/dist/tools/intent.d.ts.map +1 -0
  52. package/dist/tools/intent.js +192 -0
  53. package/dist/tools/intent.js.map +1 -0
  54. package/dist/tools/investment.d.ts +196 -0
  55. package/dist/tools/investment.d.ts.map +1 -0
  56. package/dist/tools/investment.js +415 -0
  57. package/dist/tools/investment.js.map +1 -0
  58. package/dist/tools/links.d.ts +41 -0
  59. package/dist/tools/links.d.ts.map +1 -0
  60. package/dist/tools/links.js +78 -0
  61. package/dist/tools/links.js.map +1 -0
  62. package/dist/tools/portfolio.d.ts +44 -0
  63. package/dist/tools/portfolio.d.ts.map +1 -0
  64. package/dist/tools/portfolio.js +166 -0
  65. package/dist/tools/portfolio.js.map +1 -0
  66. package/dist/tools/price-alerts.d.ts +52 -0
  67. package/dist/tools/price-alerts.d.ts.map +1 -0
  68. package/dist/tools/price-alerts.js +78 -0
  69. package/dist/tools/price-alerts.js.map +1 -0
  70. package/dist/tools/refunds.d.ts +32 -0
  71. package/dist/tools/refunds.d.ts.map +1 -0
  72. package/dist/tools/refunds.js +75 -0
  73. package/dist/tools/refunds.js.map +1 -0
  74. package/dist/tools/reputation.d.ts +49 -15
  75. package/dist/tools/reputation.d.ts.map +1 -1
  76. package/dist/tools/reputation.js +107 -45
  77. package/dist/tools/reputation.js.map +1 -1
  78. package/dist/tools/revenue.d.ts +42 -0
  79. package/dist/tools/revenue.d.ts.map +1 -0
  80. package/dist/tools/revenue.js +67 -0
  81. package/dist/tools/revenue.js.map +1 -0
  82. package/dist/tools/search.d.ts +54 -30
  83. package/dist/tools/search.d.ts.map +1 -1
  84. package/dist/tools/search.js +85 -122
  85. package/dist/tools/search.js.map +1 -1
  86. package/dist/tools/streaming.d.ts +60 -0
  87. package/dist/tools/streaming.d.ts.map +1 -0
  88. package/dist/tools/streaming.js +163 -0
  89. package/dist/tools/streaming.js.map +1 -0
  90. package/dist/tools/swap-smart.d.ts +30 -0
  91. package/dist/tools/swap-smart.d.ts.map +1 -0
  92. package/dist/tools/swap-smart.js +135 -0
  93. package/dist/tools/swap-smart.js.map +1 -0
  94. package/dist/tools/swap.d.ts +93 -0
  95. package/dist/tools/swap.d.ts.map +1 -0
  96. package/dist/tools/swap.js +150 -0
  97. package/dist/tools/swap.js.map +1 -0
  98. package/dist/tools/treasury.d.ts +267 -0
  99. package/dist/tools/treasury.d.ts.map +1 -0
  100. package/dist/tools/treasury.js +722 -0
  101. package/dist/tools/treasury.js.map +1 -0
  102. package/dist/tools/trust-graph.d.ts +105 -0
  103. package/dist/tools/trust-graph.d.ts.map +1 -0
  104. package/dist/tools/trust-graph.js +232 -0
  105. package/dist/tools/trust-graph.js.map +1 -0
  106. package/dist/tools/webhooks.d.ts +60 -0
  107. package/dist/tools/webhooks.d.ts.map +1 -0
  108. package/dist/tools/webhooks.js +133 -0
  109. package/dist/tools/webhooks.js.map +1 -0
  110. package/dist/types/index.d.ts +84 -0
  111. package/dist/types/index.d.ts.map +1 -0
  112. package/dist/{lib/types.js → types/index.js} +1 -1
  113. package/dist/types/index.js.map +1 -0
  114. package/dist/utils/contracts.d.ts +553 -0
  115. package/dist/utils/contracts.d.ts.map +1 -0
  116. package/dist/utils/contracts.js +403 -0
  117. package/dist/utils/contracts.js.map +1 -0
  118. package/package.json +11 -20
  119. package/BUILD_SUMMARY.md +0 -294
  120. package/CHANGELOG.md +0 -77
  121. package/COMPLETION_REPORT.md +0 -284
  122. package/INTEGRATION.md +0 -286
  123. package/QUICKSTART.md +0 -226
  124. package/dist/lib/config.d.ts +0 -7
  125. package/dist/lib/config.d.ts.map +0 -1
  126. package/dist/lib/config.js +0 -16
  127. package/dist/lib/config.js.map +0 -1
  128. package/dist/lib/contracts.d.ts +0 -15
  129. package/dist/lib/contracts.d.ts.map +0 -1
  130. package/dist/lib/contracts.js +0 -148
  131. package/dist/lib/contracts.js.map +0 -1
  132. package/dist/lib/types.d.ts +0 -39
  133. package/dist/lib/types.d.ts.map +0 -1
  134. package/dist/lib/types.js.map +0 -1
  135. package/dist/resources/agent.d.ts +0 -3
  136. package/dist/resources/agent.d.ts.map +0 -1
  137. package/dist/resources/agent.js +0 -36
  138. package/dist/resources/agent.js.map +0 -1
  139. package/dist/resources/escrow.d.ts +0 -3
  140. package/dist/resources/escrow.d.ts.map +0 -1
  141. package/dist/resources/escrow.js +0 -33
  142. package/dist/resources/escrow.js.map +0 -1
  143. package/dist/resources/services.d.ts +0 -2
  144. package/dist/resources/services.d.ts.map +0 -1
  145. package/dist/resources/services.js +0 -55
  146. package/dist/resources/services.js.map +0 -1
  147. package/dist/tools/agent.d.ts +0 -17
  148. package/dist/tools/agent.d.ts.map +0 -1
  149. package/dist/tools/agent.js +0 -51
  150. package/dist/tools/agent.js.map +0 -1
  151. package/examples/test-server.ts +0 -36
  152. package/examples/test-tools.ts +0 -64
  153. package/src/__tests__/server.test.ts +0 -24
  154. package/src/index.ts +0 -24
  155. package/src/lib/config.ts +0 -22
  156. package/src/lib/contracts.ts +0 -164
  157. package/src/lib/types.ts +0 -44
  158. package/src/resources/agent.ts +0 -40
  159. package/src/resources/escrow.ts +0 -35
  160. package/src/resources/services.ts +0 -53
  161. package/src/server.ts +0 -190
  162. package/src/tools/agent.ts +0 -56
  163. package/src/tools/balance.ts +0 -61
  164. package/src/tools/escrow.ts +0 -142
  165. package/src/tools/reputation.ts +0 -69
  166. package/src/tools/search.ts +0 -148
  167. package/tsconfig.json +0 -20
@@ -0,0 +1,722 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.treasurySpendLimitsSchema = exports.treasuryWithdrawEthSchema = exports.treasurySetIntegrationSchema = exports.treasuryApproveSpenderSchema = exports.treasurySetReserveSchema = exports.treasuryRevokeRoleSchema = exports.treasuryLookupSchema = exports.treasurySetLimitSchema = exports.treasurySetBudgetSchema = exports.treasuryGrantRoleSchema = exports.treasuryMembersSchema = exports.treasuryWithdrawSchema = exports.treasuryDepositSchema = exports.treasuryBalancesSchema = exports.treasuryInfoSchema = exports.treasuryCreateSchema = void 0;
4
+ exports.treasuryCreate = treasuryCreate;
5
+ exports.treasuryInfo = treasuryInfo;
6
+ exports.treasuryBalances = treasuryBalances;
7
+ exports.treasuryDeposit = treasuryDeposit;
8
+ exports.treasuryWithdraw = treasuryWithdraw;
9
+ exports.treasuryMembers = treasuryMembers;
10
+ exports.treasuryGrantRole = treasuryGrantRole;
11
+ exports.treasurySetBudget = treasurySetBudget;
12
+ exports.treasurySetLimit = treasurySetLimit;
13
+ exports.treasuryLookup = treasuryLookup;
14
+ exports.treasuryRevokeRole = treasuryRevokeRole;
15
+ exports.treasurySetReserve = treasurySetReserve;
16
+ exports.treasuryApproveSpender = treasuryApproveSpender;
17
+ exports.treasurySetIntegration = treasurySetIntegration;
18
+ exports.treasuryWithdrawEth = treasuryWithdrawEth;
19
+ exports.treasurySpendLimits = treasurySpendLimits;
20
+ const zod_1 = require("zod");
21
+ // Treasury Factory address on Base
22
+ const TREASURY_FACTORY_ADDRESS = '0x171a685f28546a0ebb13059184db1f808b915066';
23
+ // Schema for treasury_create
24
+ exports.treasuryCreateSchema = zod_1.z.object({
25
+ name: zod_1.z.string().describe('Treasury name'),
26
+ });
27
+ // Schema for treasury_info
28
+ exports.treasuryInfoSchema = zod_1.z.object({
29
+ address: zod_1.z.string().describe('Treasury address'),
30
+ });
31
+ // Schema for treasury_balances
32
+ exports.treasuryBalancesSchema = zod_1.z.object({
33
+ treasuryAddress: zod_1.z.string().describe('Treasury address'),
34
+ });
35
+ // Schema for treasury_deposit
36
+ exports.treasuryDepositSchema = zod_1.z.object({
37
+ treasuryAddress: zod_1.z.string().describe('Treasury address'),
38
+ token: zod_1.z.string().describe('Token address'),
39
+ amount: zod_1.z.string().describe('Amount to deposit (in token units)'),
40
+ });
41
+ // Schema for treasury_withdraw
42
+ exports.treasuryWithdrawSchema = zod_1.z.object({
43
+ treasuryAddress: zod_1.z.string().describe('Treasury address'),
44
+ token: zod_1.z.string().describe('Token address'),
45
+ to: zod_1.z.string().describe('Recipient address'),
46
+ amount: zod_1.z.string().describe('Amount to withdraw (in token units)'),
47
+ reason: zod_1.z.string().describe('Withdrawal reason'),
48
+ });
49
+ // Schema for treasury_members
50
+ exports.treasuryMembersSchema = zod_1.z.object({
51
+ treasuryAddress: zod_1.z.string().describe('Treasury address'),
52
+ });
53
+ // Schema for treasury_grant_role
54
+ exports.treasuryGrantRoleSchema = zod_1.z.object({
55
+ treasuryAddress: zod_1.z.string().describe('Treasury address'),
56
+ account: zod_1.z.string().describe('Account address'),
57
+ role: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).describe('Role (MANAGER=1, OPERATOR=2, AUDITOR=3)'),
58
+ });
59
+ // Schema for treasury_set_budget
60
+ exports.treasurySetBudgetSchema = zod_1.z.object({
61
+ treasuryAddress: zod_1.z.string().describe('Treasury address'),
62
+ opsBps: zod_1.z.number().describe('Operations budget (basis points, 0-10000)'),
63
+ growthBps: zod_1.z.number().describe('Growth budget (basis points, 0-10000)'),
64
+ reservesBps: zod_1.z.number().describe('Reserves budget (basis points, 0-10000)'),
65
+ yieldBps: zod_1.z.number().describe('Yield budget (basis points, 0-10000)'),
66
+ });
67
+ // Schema for treasury_set_limit
68
+ exports.treasurySetLimitSchema = zod_1.z.object({
69
+ treasuryAddress: zod_1.z.string().describe('Treasury address'),
70
+ operator: zod_1.z.string().describe('Operator address'),
71
+ maxPerTx: zod_1.z.string().describe('Maximum amount per transaction'),
72
+ maxPerDay: zod_1.z.string().describe('Maximum amount per day'),
73
+ });
74
+ // Schema for treasury_lookup
75
+ exports.treasuryLookupSchema = zod_1.z.object({
76
+ ownerAddress: zod_1.z.string().describe('Owner address'),
77
+ });
78
+ // Schema for treasury_revoke_role
79
+ exports.treasuryRevokeRoleSchema = zod_1.z.object({
80
+ treasuryAddress: zod_1.z.string().describe('Treasury address'),
81
+ account: zod_1.z.string().describe('Account address to revoke role from'),
82
+ });
83
+ // Schema for treasury_set_reserve
84
+ exports.treasurySetReserveSchema = zod_1.z.object({
85
+ treasuryAddress: zod_1.z.string().describe('Treasury address'),
86
+ lockBps: zod_1.z.number().min(0).max(5000).describe('Reserve lock in basis points (0-5000 = 0-50%)'),
87
+ });
88
+ // Schema for treasury_approve_spender
89
+ exports.treasuryApproveSpenderSchema = zod_1.z.object({
90
+ treasuryAddress: zod_1.z.string().describe('Treasury address'),
91
+ token: zod_1.z.string().describe('Token address'),
92
+ spender: zod_1.z.string().describe('Spender address'),
93
+ amount: zod_1.z.string().describe('Amount to approve'),
94
+ });
95
+ // Schema for treasury_set_integration
96
+ exports.treasurySetIntegrationSchema = zod_1.z.object({
97
+ treasuryAddress: zod_1.z.string().describe('Treasury address'),
98
+ name: zod_1.z.enum(['spendingMandate', 'policyRegistry', 'crossRailLedger']).describe('Integration name'),
99
+ address: zod_1.z.string().describe('Integration contract address'),
100
+ });
101
+ // Schema for treasury_withdraw_eth
102
+ exports.treasuryWithdrawEthSchema = zod_1.z.object({
103
+ treasuryAddress: zod_1.z.string().describe('Treasury address'),
104
+ to: zod_1.z.string().describe('Recipient address'),
105
+ amount: zod_1.z.string().describe('Amount in ETH (wei)'),
106
+ reason: zod_1.z.string().describe('Withdrawal reason'),
107
+ });
108
+ // Schema for treasury_spend_limits
109
+ exports.treasurySpendLimitsSchema = zod_1.z.object({
110
+ treasuryAddress: zod_1.z.string().describe('Treasury address'),
111
+ operator: zod_1.z.string().describe('Operator address'),
112
+ });
113
+ // Treasury Factory ABI (minimal for createTreasury and lookup)
114
+ const TREASURY_FACTORY_ABI = [
115
+ {
116
+ inputs: [{ name: '_name', type: 'string', internalType: 'string' }],
117
+ name: 'createTreasury',
118
+ outputs: [{ name: '', type: 'address', internalType: 'address' }],
119
+ stateMutability: 'nonpayable',
120
+ type: 'function',
121
+ },
122
+ {
123
+ inputs: [{ name: '', type: 'address', internalType: 'address' }],
124
+ name: 'treasuries',
125
+ outputs: [{ name: '', type: 'address', internalType: 'address' }],
126
+ stateMutability: 'view',
127
+ type: 'function',
128
+ },
129
+ ];
130
+ // Agent Treasury ABI
131
+ const AGENT_TREASURY_ABI = [
132
+ {
133
+ inputs: [],
134
+ name: 'getSummary',
135
+ outputs: [
136
+ { name: '_name', type: 'string', internalType: 'string' },
137
+ { name: '_owner', type: 'address', internalType: 'address' },
138
+ { name: 'ethBalance', type: 'uint256', internalType: 'uint256' },
139
+ { name: 'tokenCount', type: 'uint256', internalType: 'uint256' },
140
+ { name: 'memberCount', type: 'uint256', internalType: 'uint256' },
141
+ { name: '_totalDeposited', type: 'uint256', internalType: 'uint256' },
142
+ { name: '_totalWithdrawn', type: 'uint256', internalType: 'uint256' },
143
+ { name: '_reserveLockBps', type: 'uint256', internalType: 'uint256' },
144
+ { name: '_createdAt', type: 'uint256', internalType: 'uint256' },
145
+ ],
146
+ stateMutability: 'view',
147
+ type: 'function',
148
+ },
149
+ {
150
+ inputs: [],
151
+ name: 'getBalances',
152
+ outputs: [
153
+ {
154
+ name: '',
155
+ type: 'tuple[]',
156
+ internalType: 'struct AgentTreasury.TokenBalance[]',
157
+ components: [
158
+ { name: 'token', type: 'address', internalType: 'address' },
159
+ { name: 'balance', type: 'uint256', internalType: 'uint256' },
160
+ ],
161
+ },
162
+ ],
163
+ stateMutability: 'view',
164
+ type: 'function',
165
+ },
166
+ {
167
+ inputs: [],
168
+ name: 'getMembers',
169
+ outputs: [
170
+ { name: '', type: 'address[]', internalType: 'address[]' },
171
+ { name: '', type: 'uint8[]', internalType: 'enum AgentTreasury.Role[]' },
172
+ ],
173
+ stateMutability: 'view',
174
+ type: 'function',
175
+ },
176
+ {
177
+ inputs: [
178
+ { name: 'token', type: 'address', internalType: 'address' },
179
+ { name: 'amount', type: 'uint256', internalType: 'uint256' },
180
+ ],
181
+ name: 'deposit',
182
+ outputs: [],
183
+ stateMutability: 'nonpayable',
184
+ type: 'function',
185
+ },
186
+ {
187
+ inputs: [
188
+ { name: 'token', type: 'address', internalType: 'address' },
189
+ { name: 'to', type: 'address', internalType: 'address' },
190
+ { name: 'amount', type: 'uint256', internalType: 'uint256' },
191
+ { name: 'reason', type: 'string', internalType: 'string' },
192
+ ],
193
+ name: 'withdraw',
194
+ outputs: [],
195
+ stateMutability: 'nonpayable',
196
+ type: 'function',
197
+ },
198
+ {
199
+ inputs: [
200
+ { name: 'account', type: 'address', internalType: 'address' },
201
+ { name: 'role', type: 'uint8', internalType: 'enum AgentTreasury.Role' },
202
+ ],
203
+ name: 'grantRole',
204
+ outputs: [],
205
+ stateMutability: 'nonpayable',
206
+ type: 'function',
207
+ },
208
+ {
209
+ inputs: [
210
+ { name: 'operationsBps', type: 'uint256', internalType: 'uint256' },
211
+ { name: 'growthBps', type: 'uint256', internalType: 'uint256' },
212
+ { name: 'reservesBps', type: 'uint256', internalType: 'uint256' },
213
+ { name: 'yieldBps', type: 'uint256', internalType: 'uint256' },
214
+ ],
215
+ name: 'setBudget',
216
+ outputs: [],
217
+ stateMutability: 'nonpayable',
218
+ type: 'function',
219
+ },
220
+ {
221
+ inputs: [
222
+ { name: 'operator', type: 'address', internalType: 'address' },
223
+ { name: 'maxPerTx', type: 'uint256', internalType: 'uint256' },
224
+ { name: 'maxPerDay', type: 'uint256', internalType: 'uint256' },
225
+ ],
226
+ name: 'setSpendLimit',
227
+ outputs: [],
228
+ stateMutability: 'nonpayable',
229
+ type: 'function',
230
+ },
231
+ {
232
+ inputs: [{ name: 'account', type: 'address', internalType: 'address' }],
233
+ name: 'revokeRole',
234
+ outputs: [],
235
+ stateMutability: 'nonpayable',
236
+ type: 'function',
237
+ },
238
+ {
239
+ inputs: [{ name: 'newLockBps', type: 'uint256', internalType: 'uint256' }],
240
+ name: 'setReserveLock',
241
+ outputs: [],
242
+ stateMutability: 'nonpayable',
243
+ type: 'function',
244
+ },
245
+ {
246
+ inputs: [
247
+ { name: 'token', type: 'address', internalType: 'address' },
248
+ { name: 'spender', type: 'address', internalType: 'address' },
249
+ { name: 'amount', type: 'uint256', internalType: 'uint256' },
250
+ ],
251
+ name: 'approveSpender',
252
+ outputs: [],
253
+ stateMutability: 'nonpayable',
254
+ type: 'function',
255
+ },
256
+ {
257
+ inputs: [
258
+ { name: 'integrationName', type: 'string', internalType: 'string' },
259
+ { name: 'addr', type: 'address', internalType: 'address' },
260
+ ],
261
+ name: 'setIntegration',
262
+ outputs: [],
263
+ stateMutability: 'nonpayable',
264
+ type: 'function',
265
+ },
266
+ {
267
+ inputs: [
268
+ { name: 'to', type: 'address', internalType: 'address' },
269
+ { name: 'amount', type: 'uint256', internalType: 'uint256' },
270
+ { name: 'reason', type: 'string', internalType: 'string' },
271
+ ],
272
+ name: 'withdrawETH',
273
+ outputs: [],
274
+ stateMutability: 'nonpayable',
275
+ type: 'function',
276
+ },
277
+ {
278
+ inputs: [{ name: 'operator', type: 'address', internalType: 'address' }],
279
+ name: 'spendLimits',
280
+ outputs: [
281
+ { name: 'maxPerTx', type: 'uint256', internalType: 'uint256' },
282
+ { name: 'maxPerDay', type: 'uint256', internalType: 'uint256' },
283
+ { name: 'spentToday', type: 'uint256', internalType: 'uint256' },
284
+ { name: 'dayStart', type: 'uint256', internalType: 'uint256' },
285
+ ],
286
+ stateMutability: 'view',
287
+ type: 'function',
288
+ },
289
+ ];
290
+ // Role enum mapping
291
+ const ROLE_MAP = {
292
+ NONE: 0,
293
+ MANAGER: 1,
294
+ OPERATOR: 2,
295
+ AUDITOR: 3,
296
+ };
297
+ const ROLE_NAMES = {
298
+ 0: 'NONE',
299
+ 1: 'MANAGER',
300
+ 2: 'OPERATOR',
301
+ 3: 'AUDITOR',
302
+ };
303
+ async function treasuryCreate(params, client) {
304
+ try {
305
+ const walletClient = client.getWalletClient();
306
+ const account = client.getAccount();
307
+ // Simulate to get the transaction hash and result
308
+ const { request } = await client.getPublicClient().simulateContract({
309
+ address: TREASURY_FACTORY_ADDRESS,
310
+ abi: TREASURY_FACTORY_ABI,
311
+ functionName: 'createTreasury',
312
+ args: [params.name],
313
+ account: account.address,
314
+ });
315
+ const hash = await walletClient.writeContract(request);
316
+ return {
317
+ treasuryAddress: 'pending', // Will be available in transaction receipt
318
+ transaction: {
319
+ hash,
320
+ status: 'pending',
321
+ },
322
+ };
323
+ }
324
+ catch (error) {
325
+ throw new Error(`Failed to create treasury: ${error.message}`);
326
+ }
327
+ }
328
+ async function treasuryInfo(params, client) {
329
+ try {
330
+ const publicClient = client.getPublicClient();
331
+ const treasuryAddress = params.address;
332
+ // Get summary
333
+ const summary = await publicClient.readContract({
334
+ address: treasuryAddress,
335
+ abi: AGENT_TREASURY_ABI,
336
+ functionName: 'getSummary',
337
+ });
338
+ // Get balances
339
+ const balances = await publicClient.readContract({
340
+ address: treasuryAddress,
341
+ abi: AGENT_TREASURY_ABI,
342
+ functionName: 'getBalances',
343
+ });
344
+ // Get members
345
+ const [addresses, roles] = await publicClient.readContract({
346
+ address: treasuryAddress,
347
+ abi: AGENT_TREASURY_ABI,
348
+ functionName: 'getMembers',
349
+ });
350
+ return {
351
+ name: summary[0],
352
+ owner: summary[1],
353
+ ethBalance: summary[2].toString(),
354
+ tokenCount: Number(summary[3]),
355
+ memberCount: Number(summary[4]),
356
+ totalDeposited: summary[5].toString(),
357
+ totalWithdrawn: summary[6].toString(),
358
+ reserveLockBps: Number(summary[7]),
359
+ createdAt: Number(summary[8]),
360
+ balances: balances.map((b) => ({
361
+ token: b.token,
362
+ balance: b.balance.toString(),
363
+ })),
364
+ };
365
+ }
366
+ catch (error) {
367
+ throw new Error(`Failed to get treasury info: ${error.message}`);
368
+ }
369
+ }
370
+ async function treasuryBalances(params, client) {
371
+ try {
372
+ const publicClient = client.getPublicClient();
373
+ const treasuryAddress = params.treasuryAddress;
374
+ const balances = await publicClient.readContract({
375
+ address: treasuryAddress,
376
+ abi: AGENT_TREASURY_ABI,
377
+ functionName: 'getBalances',
378
+ });
379
+ return {
380
+ balances: balances.map((b) => ({
381
+ token: b.token,
382
+ balance: b.balance.toString(),
383
+ })),
384
+ };
385
+ }
386
+ catch (error) {
387
+ throw new Error(`Failed to get treasury balances: ${error.message}`);
388
+ }
389
+ }
390
+ async function treasuryDeposit(params, client) {
391
+ try {
392
+ const walletClient = client.getWalletClient();
393
+ const account = client.getAccount();
394
+ const { request } = await client.getPublicClient().simulateContract({
395
+ address: params.treasuryAddress,
396
+ abi: AGENT_TREASURY_ABI,
397
+ functionName: 'deposit',
398
+ args: [params.token, BigInt(params.amount)],
399
+ account: account.address,
400
+ });
401
+ const hash = await walletClient.writeContract(request);
402
+ return {
403
+ transaction: {
404
+ hash,
405
+ status: 'pending',
406
+ },
407
+ };
408
+ }
409
+ catch (error) {
410
+ throw new Error(`Failed to deposit to treasury: ${error.message}`);
411
+ }
412
+ }
413
+ async function treasuryWithdraw(params, client) {
414
+ try {
415
+ const walletClient = client.getWalletClient();
416
+ const account = client.getAccount();
417
+ const { request } = await client.getPublicClient().simulateContract({
418
+ address: params.treasuryAddress,
419
+ abi: AGENT_TREASURY_ABI,
420
+ functionName: 'withdraw',
421
+ args: [
422
+ params.token,
423
+ params.to,
424
+ BigInt(params.amount),
425
+ params.reason,
426
+ ],
427
+ account: account.address,
428
+ });
429
+ const hash = await walletClient.writeContract(request);
430
+ return {
431
+ transaction: {
432
+ hash,
433
+ status: 'pending',
434
+ },
435
+ };
436
+ }
437
+ catch (error) {
438
+ throw new Error(`Failed to withdraw from treasury: ${error.message}`);
439
+ }
440
+ }
441
+ async function treasuryMembers(params, client) {
442
+ try {
443
+ const publicClient = client.getPublicClient();
444
+ const treasuryAddress = params.treasuryAddress;
445
+ const [addresses, roles] = await publicClient.readContract({
446
+ address: treasuryAddress,
447
+ abi: AGENT_TREASURY_ABI,
448
+ functionName: 'getMembers',
449
+ });
450
+ const members = addresses.map((addr, idx) => ({
451
+ address: addr,
452
+ role: ROLE_NAMES[roles[idx]] || 'UNKNOWN',
453
+ }));
454
+ return { members };
455
+ }
456
+ catch (error) {
457
+ throw new Error(`Failed to get treasury members: ${error.message}`);
458
+ }
459
+ }
460
+ async function treasuryGrantRole(params, client) {
461
+ try {
462
+ const walletClient = client.getWalletClient();
463
+ const account = client.getAccount();
464
+ // Convert role to number if it's a string
465
+ let roleNumber;
466
+ if (typeof params.role === 'string') {
467
+ const roleStr = params.role.toUpperCase();
468
+ roleNumber = ROLE_MAP[roleStr] ?? parseInt(params.role);
469
+ if (isNaN(roleNumber) || roleNumber < 0 || roleNumber > 3) {
470
+ throw new Error(`Invalid role: ${params.role}. Use MANAGER (1), OPERATOR (2), or AUDITOR (3)`);
471
+ }
472
+ }
473
+ else {
474
+ roleNumber = params.role;
475
+ }
476
+ const { request } = await client.getPublicClient().simulateContract({
477
+ address: params.treasuryAddress,
478
+ abi: AGENT_TREASURY_ABI,
479
+ functionName: 'grantRole',
480
+ args: [params.account, roleNumber],
481
+ account: account.address,
482
+ });
483
+ const hash = await walletClient.writeContract(request);
484
+ return {
485
+ transaction: {
486
+ hash,
487
+ status: 'pending',
488
+ },
489
+ };
490
+ }
491
+ catch (error) {
492
+ throw new Error(`Failed to grant role: ${error.message}`);
493
+ }
494
+ }
495
+ async function treasurySetBudget(params, client) {
496
+ try {
497
+ const walletClient = client.getWalletClient();
498
+ const account = client.getAccount();
499
+ // Validate that basis points sum to 10000 (100%)
500
+ const total = params.opsBps + params.growthBps + params.reservesBps + params.yieldBps;
501
+ if (total !== 10000) {
502
+ throw new Error(`Budget allocations must sum to 10000 basis points (100%). Current total: ${total}`);
503
+ }
504
+ const { request } = await client.getPublicClient().simulateContract({
505
+ address: params.treasuryAddress,
506
+ abi: AGENT_TREASURY_ABI,
507
+ functionName: 'setBudget',
508
+ args: [
509
+ BigInt(params.opsBps),
510
+ BigInt(params.growthBps),
511
+ BigInt(params.reservesBps),
512
+ BigInt(params.yieldBps),
513
+ ],
514
+ account: account.address,
515
+ });
516
+ const hash = await walletClient.writeContract(request);
517
+ return {
518
+ transaction: {
519
+ hash,
520
+ status: 'pending',
521
+ },
522
+ };
523
+ }
524
+ catch (error) {
525
+ throw new Error(`Failed to set budget: ${error.message}`);
526
+ }
527
+ }
528
+ async function treasurySetLimit(params, client) {
529
+ try {
530
+ const walletClient = client.getWalletClient();
531
+ const account = client.getAccount();
532
+ const { request } = await client.getPublicClient().simulateContract({
533
+ address: params.treasuryAddress,
534
+ abi: AGENT_TREASURY_ABI,
535
+ functionName: 'setSpendLimit',
536
+ args: [
537
+ params.operator,
538
+ BigInt(params.maxPerTx),
539
+ BigInt(params.maxPerDay),
540
+ ],
541
+ account: account.address,
542
+ });
543
+ const hash = await walletClient.writeContract(request);
544
+ return {
545
+ transaction: {
546
+ hash,
547
+ status: 'pending',
548
+ },
549
+ };
550
+ }
551
+ catch (error) {
552
+ throw new Error(`Failed to set spend limit: ${error.message}`);
553
+ }
554
+ }
555
+ async function treasuryLookup(params, client) {
556
+ try {
557
+ const publicClient = client.getPublicClient();
558
+ const treasuryAddress = await publicClient.readContract({
559
+ address: TREASURY_FACTORY_ADDRESS,
560
+ abi: TREASURY_FACTORY_ABI,
561
+ functionName: 'treasuries',
562
+ args: [params.ownerAddress],
563
+ });
564
+ // If address is zero address, no treasury exists
565
+ const isZeroAddress = treasuryAddress === '0x0000000000000000000000000000000000000000';
566
+ return {
567
+ treasuryAddress: isZeroAddress ? null : treasuryAddress,
568
+ };
569
+ }
570
+ catch (error) {
571
+ throw new Error(`Failed to lookup treasury: ${error.message}`);
572
+ }
573
+ }
574
+ async function treasuryRevokeRole(params, client) {
575
+ try {
576
+ const walletClient = client.getWalletClient();
577
+ const account = client.getAccount();
578
+ const { request } = await client.getPublicClient().simulateContract({
579
+ address: params.treasuryAddress,
580
+ abi: AGENT_TREASURY_ABI,
581
+ functionName: 'revokeRole',
582
+ args: [params.account],
583
+ account: account.address,
584
+ });
585
+ const hash = await walletClient.writeContract(request);
586
+ return {
587
+ transaction: {
588
+ hash,
589
+ status: 'pending',
590
+ },
591
+ };
592
+ }
593
+ catch (error) {
594
+ throw new Error(`Failed to revoke role: ${error.message}`);
595
+ }
596
+ }
597
+ async function treasurySetReserve(params, client) {
598
+ try {
599
+ const walletClient = client.getWalletClient();
600
+ const account = client.getAccount();
601
+ if (params.lockBps < 0 || params.lockBps > 5000) {
602
+ throw new Error('Reserve lock must be between 0 and 5000 bps (0-50%)');
603
+ }
604
+ const { request } = await client.getPublicClient().simulateContract({
605
+ address: params.treasuryAddress,
606
+ abi: AGENT_TREASURY_ABI,
607
+ functionName: 'setReserveLock',
608
+ args: [BigInt(params.lockBps)],
609
+ account: account.address,
610
+ });
611
+ const hash = await walletClient.writeContract(request);
612
+ return {
613
+ transaction: {
614
+ hash,
615
+ status: 'pending',
616
+ },
617
+ };
618
+ }
619
+ catch (error) {
620
+ throw new Error(`Failed to set reserve lock: ${error.message}`);
621
+ }
622
+ }
623
+ async function treasuryApproveSpender(params, client) {
624
+ try {
625
+ const walletClient = client.getWalletClient();
626
+ const account = client.getAccount();
627
+ const { request } = await client.getPublicClient().simulateContract({
628
+ address: params.treasuryAddress,
629
+ abi: AGENT_TREASURY_ABI,
630
+ functionName: 'approveSpender',
631
+ args: [
632
+ params.token,
633
+ params.spender,
634
+ BigInt(params.amount),
635
+ ],
636
+ account: account.address,
637
+ });
638
+ const hash = await walletClient.writeContract(request);
639
+ return {
640
+ transaction: {
641
+ hash,
642
+ status: 'pending',
643
+ },
644
+ };
645
+ }
646
+ catch (error) {
647
+ throw new Error(`Failed to approve spender: ${error.message}`);
648
+ }
649
+ }
650
+ async function treasurySetIntegration(params, client) {
651
+ try {
652
+ const walletClient = client.getWalletClient();
653
+ const account = client.getAccount();
654
+ const { request } = await client.getPublicClient().simulateContract({
655
+ address: params.treasuryAddress,
656
+ abi: AGENT_TREASURY_ABI,
657
+ functionName: 'setIntegration',
658
+ args: [params.name, params.address],
659
+ account: account.address,
660
+ });
661
+ const hash = await walletClient.writeContract(request);
662
+ return {
663
+ transaction: {
664
+ hash,
665
+ status: 'pending',
666
+ },
667
+ };
668
+ }
669
+ catch (error) {
670
+ throw new Error(`Failed to set integration: ${error.message}`);
671
+ }
672
+ }
673
+ async function treasuryWithdrawEth(params, client) {
674
+ try {
675
+ const walletClient = client.getWalletClient();
676
+ const account = client.getAccount();
677
+ const { request } = await client.getPublicClient().simulateContract({
678
+ address: params.treasuryAddress,
679
+ abi: AGENT_TREASURY_ABI,
680
+ functionName: 'withdrawETH',
681
+ args: [
682
+ params.to,
683
+ BigInt(params.amount),
684
+ params.reason,
685
+ ],
686
+ account: account.address,
687
+ });
688
+ const hash = await walletClient.writeContract(request);
689
+ return {
690
+ transaction: {
691
+ hash,
692
+ status: 'pending',
693
+ },
694
+ };
695
+ }
696
+ catch (error) {
697
+ throw new Error(`Failed to withdraw ETH: ${error.message}`);
698
+ }
699
+ }
700
+ async function treasurySpendLimits(params, client) {
701
+ try {
702
+ const publicClient = client.getPublicClient();
703
+ const limits = await publicClient.readContract({
704
+ address: params.treasuryAddress,
705
+ abi: AGENT_TREASURY_ABI,
706
+ functionName: 'spendLimits',
707
+ args: [params.operator],
708
+ });
709
+ return {
710
+ limits: {
711
+ maxPerTx: limits[0].toString(),
712
+ maxPerDay: limits[1].toString(),
713
+ spentToday: limits[2].toString(),
714
+ dayStart: Number(limits[3]),
715
+ },
716
+ };
717
+ }
718
+ catch (error) {
719
+ throw new Error(`Failed to get spend limits: ${error.message}`);
720
+ }
721
+ }
722
+ //# sourceMappingURL=treasury.js.map