@boostxyz/sdk 0.0.0-alpha.5 → 0.0.0-alpha.6

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 (164) hide show
  1. package/dist/Actions/Action.cjs +1 -0
  2. package/dist/Actions/Action.cjs.map +1 -0
  3. package/dist/Actions/Action.js +1 -0
  4. package/dist/Actions/Action.js.map +1 -0
  5. package/dist/Actions/EventAction.cjs +1 -0
  6. package/dist/Actions/EventAction.cjs.map +1 -0
  7. package/dist/Actions/EventAction.js +1 -0
  8. package/dist/Actions/EventAction.js.map +1 -0
  9. package/dist/AllowLists/AllowList.cjs +1 -0
  10. package/dist/AllowLists/AllowList.cjs.map +1 -0
  11. package/dist/AllowLists/AllowList.js +1 -0
  12. package/dist/AllowLists/AllowList.js.map +1 -0
  13. package/dist/AllowLists/SimpleAllowList.cjs +1 -0
  14. package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
  15. package/dist/AllowLists/SimpleAllowList.js +1 -0
  16. package/dist/AllowLists/SimpleAllowList.js.map +1 -0
  17. package/dist/AllowLists/SimpleDenyList.cjs +1 -0
  18. package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
  19. package/dist/AllowLists/SimpleDenyList.js +1 -0
  20. package/dist/AllowLists/SimpleDenyList.js.map +1 -0
  21. package/dist/Auth/Auth.cjs +1 -0
  22. package/dist/Auth/Auth.cjs.map +1 -0
  23. package/dist/Auth/Auth.js +1 -0
  24. package/dist/Auth/Auth.js.map +1 -0
  25. package/dist/Auth/PassthroughAuth.cjs +1 -0
  26. package/dist/Auth/PassthroughAuth.cjs.map +1 -0
  27. package/dist/Auth/PassthroughAuth.js +1 -0
  28. package/dist/Auth/PassthroughAuth.js.map +1 -0
  29. package/dist/Boost.cjs +1 -0
  30. package/dist/Boost.cjs.map +1 -0
  31. package/dist/Boost.js +1 -0
  32. package/dist/Boost.js.map +1 -0
  33. package/dist/BoostCore.cjs +1 -0
  34. package/dist/BoostCore.cjs.map +1 -0
  35. package/dist/BoostCore.js +1 -0
  36. package/dist/BoostCore.js.map +1 -0
  37. package/dist/BoostRegistry.cjs +1 -0
  38. package/dist/BoostRegistry.cjs.map +1 -0
  39. package/dist/BoostRegistry.js +1 -0
  40. package/dist/BoostRegistry.js.map +1 -0
  41. package/dist/Budgets/Budget.cjs +1 -0
  42. package/dist/Budgets/Budget.cjs.map +1 -0
  43. package/dist/Budgets/Budget.js +1 -0
  44. package/dist/Budgets/Budget.js.map +1 -0
  45. package/dist/Budgets/ManagedBudget.cjs +1 -0
  46. package/dist/Budgets/ManagedBudget.cjs.map +1 -0
  47. package/dist/Budgets/ManagedBudget.js +1 -0
  48. package/dist/Budgets/ManagedBudget.js.map +1 -0
  49. package/dist/Deployable/Contract.cjs +1 -0
  50. package/dist/Deployable/Contract.cjs.map +1 -0
  51. package/dist/Deployable/Contract.js +1 -0
  52. package/dist/Deployable/Contract.js.map +1 -0
  53. package/dist/Deployable/Deployable.cjs +1 -0
  54. package/dist/Deployable/Deployable.cjs.map +1 -0
  55. package/dist/Deployable/Deployable.js +1 -0
  56. package/dist/Deployable/Deployable.js.map +1 -0
  57. package/dist/Deployable/DeployableTarget.cjs +1 -0
  58. package/dist/Deployable/DeployableTarget.cjs.map +1 -0
  59. package/dist/Deployable/DeployableTarget.js +1 -0
  60. package/dist/Deployable/DeployableTarget.js.map +1 -0
  61. package/dist/Incentives/AllowListIncentive.cjs +1 -0
  62. package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
  63. package/dist/Incentives/AllowListIncentive.js +1 -0
  64. package/dist/Incentives/AllowListIncentive.js.map +1 -0
  65. package/dist/Incentives/CGDAIncentive.cjs +1 -0
  66. package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
  67. package/dist/Incentives/CGDAIncentive.js +1 -0
  68. package/dist/Incentives/CGDAIncentive.js.map +1 -0
  69. package/dist/Incentives/ERC20Incentive.cjs +1 -0
  70. package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
  71. package/dist/Incentives/ERC20Incentive.js +1 -0
  72. package/dist/Incentives/ERC20Incentive.js.map +1 -0
  73. package/dist/Incentives/Incentive.cjs +1 -0
  74. package/dist/Incentives/Incentive.cjs.map +1 -0
  75. package/dist/Incentives/Incentive.js +1 -0
  76. package/dist/Incentives/Incentive.js.map +1 -0
  77. package/dist/Incentives/PointsIncentive.cjs +1 -0
  78. package/dist/Incentives/PointsIncentive.cjs.map +1 -0
  79. package/dist/Incentives/PointsIncentive.js +1 -0
  80. package/dist/Incentives/PointsIncentive.js.map +1 -0
  81. package/dist/Validators/SignerValidator.cjs +1 -0
  82. package/dist/Validators/SignerValidator.cjs.map +1 -0
  83. package/dist/Validators/SignerValidator.js +1 -0
  84. package/dist/Validators/SignerValidator.js.map +1 -0
  85. package/dist/Validators/Validator.cjs +1 -0
  86. package/dist/Validators/Validator.cjs.map +1 -0
  87. package/dist/Validators/Validator.js +1 -0
  88. package/dist/Validators/Validator.js.map +1 -0
  89. package/dist/componentInterfaces-CKCBwG16.cjs +1 -0
  90. package/dist/componentInterfaces-CKCBwG16.cjs.map +1 -0
  91. package/dist/componentInterfaces-DYkaxBda.js +1 -0
  92. package/dist/componentInterfaces-DYkaxBda.js.map +1 -0
  93. package/dist/errors.cjs +1 -0
  94. package/dist/errors.cjs.map +1 -0
  95. package/dist/errors.js +1 -0
  96. package/dist/errors.js.map +1 -0
  97. package/dist/generated-Cd-Fe7W7.cjs +1 -0
  98. package/dist/generated-Cd-Fe7W7.cjs.map +1 -0
  99. package/dist/generated-DGpIVcv5.js +1 -0
  100. package/dist/generated-DGpIVcv5.js.map +1 -0
  101. package/dist/index.cjs +1 -0
  102. package/dist/index.cjs.map +1 -0
  103. package/dist/index.js +1 -0
  104. package/dist/index.js.map +1 -0
  105. package/dist/utils.cjs +1 -0
  106. package/dist/utils.cjs.map +1 -0
  107. package/dist/utils.js +1 -0
  108. package/dist/utils.js.map +1 -0
  109. package/package.json +3 -2
  110. package/src/Actions/Action.test.ts +77 -0
  111. package/src/Actions/Action.ts +61 -0
  112. package/src/Actions/ContractAction.test.ts +199 -0
  113. package/src/Actions/ContractAction.ts +238 -0
  114. package/src/Actions/ERC721MintAction.test.ts +112 -0
  115. package/src/Actions/ERC721MintAction.ts +238 -0
  116. package/src/Actions/EventAction.test.ts +182 -0
  117. package/src/Actions/EventAction.ts +382 -0
  118. package/src/AllowLists/AllowList.test.ts +64 -0
  119. package/src/AllowLists/AllowList.ts +60 -0
  120. package/src/AllowLists/SimpleAllowList.test.ts +52 -0
  121. package/src/AllowLists/SimpleAllowList.ts +240 -0
  122. package/src/AllowLists/SimpleDenyList.test.ts +52 -0
  123. package/src/AllowLists/SimpleDenyList.ts +289 -0
  124. package/src/Auth/Auth.ts +11 -0
  125. package/src/Auth/PassthroughAuth.test.ts +12 -0
  126. package/src/Auth/PassthroughAuth.ts +80 -0
  127. package/src/Boost.ts +155 -0
  128. package/src/BoostCore.test.ts +846 -0
  129. package/src/BoostCore.ts +1192 -0
  130. package/src/BoostRegistry.ts +449 -0
  131. package/src/Budgets/Budget.test.ts +27 -0
  132. package/src/Budgets/Budget.ts +61 -0
  133. package/src/Budgets/ManagedBudget.test.ts +154 -0
  134. package/src/Budgets/ManagedBudget.ts +743 -0
  135. package/src/Budgets/SimpleBudget.test.ts +152 -0
  136. package/src/Budgets/SimpleBudget.ts +521 -0
  137. package/src/Budgets/VestingBudget.test.ts +123 -0
  138. package/src/Budgets/VestingBudget.ts +532 -0
  139. package/src/Deployable/Contract.ts +229 -0
  140. package/src/Deployable/Deployable.ts +244 -0
  141. package/src/Deployable/DeployableTarget.ts +210 -0
  142. package/src/Incentives/AllowListIncentive.test.ts +146 -0
  143. package/src/Incentives/AllowListIncentive.ts +290 -0
  144. package/src/Incentives/CGDAIncentive.test.ts +136 -0
  145. package/src/Incentives/CGDAIncentive.ts +364 -0
  146. package/src/Incentives/ERC1155Incentive.test.ts +98 -0
  147. package/src/Incentives/ERC1155Incentive.ts +384 -0
  148. package/src/Incentives/ERC20Incentive.test.ts +141 -0
  149. package/src/Incentives/ERC20Incentive.ts +417 -0
  150. package/src/Incentives/ERC20VariableIncentive.test.ts +156 -0
  151. package/src/Incentives/ERC20VariableIncentive.ts +368 -0
  152. package/src/Incentives/Incentive.test.ts +92 -0
  153. package/src/Incentives/Incentive.ts +85 -0
  154. package/src/Incentives/PointsIncentive.test.ts +142 -0
  155. package/src/Incentives/PointsIncentive.ts +303 -0
  156. package/src/Validators/SignerValidator.test.ts +163 -0
  157. package/src/Validators/SignerValidator.ts +272 -0
  158. package/src/Validators/Validator.test.ts +21 -0
  159. package/src/Validators/Validator.ts +55 -0
  160. package/src/errors.ts +524 -0
  161. package/src/index.test.ts +40 -0
  162. package/src/index.ts +50 -0
  163. package/src/utils.test.ts +44 -0
  164. package/src/utils.ts +2247 -0
@@ -0,0 +1,743 @@
1
+ import {
2
+ managedBudgetAbi,
3
+ readManagedBudgetAvailable,
4
+ readManagedBudgetDistributed,
5
+ readManagedBudgetHasAllRoles,
6
+ readManagedBudgetHasAnyRole,
7
+ readManagedBudgetIsAuthorized,
8
+ readManagedBudgetOwner,
9
+ readManagedBudgetRolesOf,
10
+ readManagedBudgetTotal,
11
+ simulateManagedBudgetAllocate,
12
+ simulateManagedBudgetClawback,
13
+ simulateManagedBudgetDisburse,
14
+ simulateManagedBudgetDisburseBatch,
15
+ simulateManagedBudgetGrantRoles,
16
+ simulateManagedBudgetRevokeRoles,
17
+ simulateManagedBudgetSetAuthorized,
18
+ writeManagedBudgetAllocate,
19
+ writeManagedBudgetClawback,
20
+ writeManagedBudgetDisburse,
21
+ writeManagedBudgetDisburseBatch,
22
+ writeManagedBudgetGrantRoles,
23
+ writeManagedBudgetRevokeRoles,
24
+ writeManagedBudgetSetAuthorized,
25
+ } from '@boostxyz/evm';
26
+ import { bytecode } from '@boostxyz/evm/artifacts/contracts/budgets/ManagedBudget.sol/ManagedBudget.json';
27
+ import { getAccount } from '@wagmi/core';
28
+ import {
29
+ type Address,
30
+ type ContractEventName,
31
+ type Hex,
32
+ zeroAddress,
33
+ } from 'viem';
34
+ import type {
35
+ DeployableOptions,
36
+ GenericDeployableParams,
37
+ } from '../Deployable/Deployable';
38
+ import { DeployableTarget } from '../Deployable/DeployableTarget';
39
+ import {
40
+ DeployableUnknownOwnerProvidedError,
41
+ UnknownTransferPayloadSupplied,
42
+ } from '../errors';
43
+ import {
44
+ type ERC1155TransferPayload,
45
+ type FungibleTransferPayload,
46
+ type GenericLog,
47
+ type ManagedBudgetPayload,
48
+ type ReadParams,
49
+ RegistryType,
50
+ type WriteParams,
51
+ prepareERC1155Transfer,
52
+ prepareFungibleTransfer,
53
+ prepareManagedBudgetPayload,
54
+ } from '../utils';
55
+
56
+ export { managedBudgetAbi };
57
+ export type {
58
+ ERC1155TransferPayload,
59
+ FungibleTransferPayload,
60
+ ManagedBudgetPayload,
61
+ };
62
+
63
+ /**
64
+ * Enum representing available roles for use in the `ManagedBudget`.
65
+ * `MANAGER` can disburse funds.
66
+ * `ADMIN` can additionally manage authorized users on the budget.
67
+ *
68
+ * @type {{ readonly MANAGER: 1n; readonly ADMIN_ROLE: 2n; }}
69
+ */
70
+ export const ManagedBudgetRoles = {
71
+ MANAGER: 1n,
72
+ ADMIN: 2n,
73
+ } as const;
74
+
75
+ /**
76
+ * A generic `viem.Log` event with support for `ManagedBudget` event types.
77
+ *
78
+ * @export
79
+ * @typedef {ManagedBudgetLog}
80
+ * @template {ContractEventName<typeof managedBudgetAbi>} [event=ContractEventName<
81
+ * typeof managedBudgetAbi
82
+ * >]
83
+ */
84
+ export type ManagedBudgetLog<
85
+ event extends ContractEventName<typeof managedBudgetAbi> = ContractEventName<
86
+ typeof managedBudgetAbi
87
+ >,
88
+ > = GenericLog<typeof managedBudgetAbi, event>;
89
+
90
+ /**
91
+ * Typeguard to determine if a transfer payload is a Fungible Transfer
92
+ *
93
+ * @export
94
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
95
+ * @returns {transfer is FungibleTransferPayload}
96
+ */
97
+ export function isFungibleTransfer(
98
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
99
+ ): transfer is FungibleTransferPayload {
100
+ return (transfer as ERC1155TransferPayload).tokenId === undefined;
101
+ }
102
+
103
+ /**
104
+ * Typeguard to determine if a transfer payload is an ERC1155 Transfer
105
+ *
106
+ * @export
107
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
108
+ * @returns {transfer is ERC1155TransferPayload}
109
+ */
110
+ export function isERC1155TransferPayload(
111
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
112
+ ): transfer is ERC1155TransferPayload {
113
+ return (transfer as ERC1155TransferPayload).tokenId !== undefined;
114
+ }
115
+
116
+ /**
117
+ * Given either a Fungible transfer, or ERC1155 transfer, will properly encode parameters for transfers, claims, disbursements, allocations, etc.
118
+ *
119
+ * @export
120
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
121
+ * @returns {*}
122
+ * @throws {@link UnknownTransferPayloadSupplied}
123
+ */
124
+ export function prepareTransfer(
125
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
126
+ ) {
127
+ if (isFungibleTransfer(transfer)) {
128
+ return prepareFungibleTransfer(transfer);
129
+ } else if (isERC1155TransferPayload(transfer)) {
130
+ return prepareERC1155Transfer(transfer);
131
+ } else throw new UnknownTransferPayloadSupplied(transfer);
132
+ }
133
+
134
+ /**
135
+ * A minimal budget implementation that simply holds and distributes tokens (ERC20-like and native)
136
+ * This type of budget supports ETH, ERC20, and ERC1155 assets only
137
+ *
138
+ * @export
139
+ * @class ManagedBudget
140
+ * @typedef {ManagedBudget}
141
+ * @extends {DeployableTarget<ManagedBudgetPayload>}
142
+ */
143
+ export class ManagedBudget extends DeployableTarget<
144
+ ManagedBudgetPayload,
145
+ typeof managedBudgetAbi
146
+ > {
147
+ /**
148
+ * @inheritdoc
149
+ *
150
+ * @public
151
+ * @readonly
152
+ * @type {*}
153
+ */
154
+ public override readonly abi = managedBudgetAbi;
155
+ /**
156
+ * @inheritdoc
157
+ *
158
+ * @public
159
+ * @static
160
+ * @type {Address}
161
+ */
162
+ public static override base: Address = import.meta.env
163
+ .VITE_MANAGED_BUDGET_BASE;
164
+ /**
165
+ * @inheritdoc
166
+ *
167
+ * @public
168
+ * @static
169
+ * @type {RegistryType}
170
+ */
171
+ public static override registryType: RegistryType = RegistryType.BUDGET;
172
+
173
+ /**
174
+ * Allocates assets to the budget.
175
+ * The caller must have already approved the contract to transfer the asset
176
+ * If the asset transfer fails, the allocation will revert
177
+ *
178
+ * @public
179
+ * @async
180
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
181
+ * @param {?WriteParams<typeof managedBudgetAbi, 'allocate'>} [params]
182
+ * @returns {Promise<boolean>} - True if the allocation was successful
183
+ */
184
+ public async allocate(
185
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
186
+ params?: WriteParams<typeof managedBudgetAbi, 'allocate'>,
187
+ ) {
188
+ return this.awaitResult(this.allocateRaw(transfer, params));
189
+ }
190
+
191
+ /**
192
+ * Allocates assets to the budget.
193
+ * The caller must have already approved the contract to transfer the asset
194
+ * If the asset transfer fails, the allocation will revert
195
+ *
196
+ * @public
197
+ * @async
198
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
199
+ * @param {?WriteParams<typeof managedBudgetAbi, 'allocate'>} [params]
200
+ * @returns {Promise<boolean>} - True if the allocation was successful
201
+ */
202
+ public async allocateRaw(
203
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
204
+ params?: WriteParams<typeof managedBudgetAbi, 'allocate'>,
205
+ ) {
206
+ const { request, result } = await simulateManagedBudgetAllocate(
207
+ this._config,
208
+ {
209
+ address: this.assertValidAddress(),
210
+ args: [prepareTransfer(transfer)],
211
+ ...this.optionallyAttachAccount(),
212
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
213
+ ...(params as any),
214
+ },
215
+ );
216
+ const hash = await writeManagedBudgetAllocate(this._config, request);
217
+ return { hash, result };
218
+ }
219
+
220
+ /**
221
+ * Clawbacks assets from the budget.
222
+ * Only the owner can directly clawback assets from the budget
223
+ * If the amount is zero, the entire balance of the asset will be transferred to the receiver
224
+ * If the asset transfer fails, the reclamation will revert
225
+ *
226
+ * @public
227
+ * @async
228
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
229
+ * @param {?WriteParams<typeof managedBudgetAbi, 'clawback'>} [params]
230
+ * @returns {Promise<boolean>} - True if the request was successful
231
+ */
232
+ public async clawback(
233
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
234
+ params?: WriteParams<typeof managedBudgetAbi, 'clawback'>,
235
+ ) {
236
+ return this.awaitResult(this.clawbackRaw(transfer, params));
237
+ }
238
+
239
+ /**
240
+ * Clawbacks assets from the budget.
241
+ * Only the owner can directly clawback assets from the budget
242
+ * If the amount is zero, the entire balance of the asset will be transferred to the receiver
243
+ * If the asset transfer fails, the reclamation will revert
244
+ *
245
+ * @public
246
+ * @async
247
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
248
+ * @param {?WriteParams<typeof managedBudgetAbi, 'clawback'>} [params]
249
+ * @returns {Promise<boolean>} - True if the request was successful
250
+ */
251
+ public async clawbackRaw(
252
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
253
+ params?: WriteParams<typeof managedBudgetAbi, 'clawback'>,
254
+ ) {
255
+ const { request, result } = await simulateManagedBudgetClawback(
256
+ this._config,
257
+ {
258
+ address: this.assertValidAddress(),
259
+ args: [prepareTransfer(transfer)],
260
+ ...this.optionallyAttachAccount(),
261
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
262
+ ...(params as any),
263
+ },
264
+ );
265
+ const hash = await writeManagedBudgetClawback(this._config, request);
266
+ return { hash, result };
267
+ }
268
+
269
+ /**
270
+ * Disburses assets from the budget to a single recipient
271
+ * If the asset transfer fails, the disbursement will revert
272
+ *
273
+ * @public
274
+ * @async
275
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
276
+ * @param {?WriteParams<typeof managedBudgetAbi, 'disburse'>} [params]
277
+ * @returns {Promise<boolean>} - True if the disbursement was successful
278
+ */
279
+ public async disburse(
280
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
281
+ params?: WriteParams<typeof managedBudgetAbi, 'disburse'>,
282
+ ) {
283
+ return this.awaitResult(this.disburseRaw(transfer, params));
284
+ }
285
+
286
+ /**
287
+ * Disburses assets from the budget to a single recipient
288
+ * If the asset transfer fails, the disbursement will revert
289
+ *
290
+ * @public
291
+ * @async
292
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
293
+ * @param {?WriteParams<typeof managedBudgetAbi, 'disburse'>} [params]
294
+ * @returns {Promise<boolean>} - True if the disbursement was successful
295
+ */
296
+ public async disburseRaw(
297
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
298
+ params?: WriteParams<typeof managedBudgetAbi, 'disburse'>,
299
+ ) {
300
+ const { request, result } = await simulateManagedBudgetDisburse(
301
+ this._config,
302
+ {
303
+ address: this.assertValidAddress(),
304
+ args: [prepareTransfer(transfer)],
305
+ ...this.optionallyAttachAccount(),
306
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
307
+ ...(params as any),
308
+ },
309
+ );
310
+ const hash = await writeManagedBudgetDisburse(this._config, request);
311
+ return { hash, result };
312
+ }
313
+
314
+ /**
315
+ * Disburses assets from the budget to multiple recipients
316
+ *
317
+ * @public
318
+ * @async
319
+ * @param {Array<FungibleTransferPayload | ERC1155TransferPayload>} transfers
320
+ * @param {?WriteParams<typeof managedBudgetAbi, 'disburseBatch'>} [params]
321
+ * @returns {Promise<boolean>} - True if all disbursements were successful
322
+ */
323
+ public async disburseBatch(
324
+ transfers: Array<FungibleTransferPayload | ERC1155TransferPayload>,
325
+ params?: WriteParams<typeof managedBudgetAbi, 'disburseBatch'>,
326
+ ) {
327
+ return this.awaitResult(this.disburseBatchRaw(transfers, params));
328
+ }
329
+
330
+ /**
331
+ * Disburses assets from the budget to multiple recipients
332
+ *
333
+ * @public
334
+ * @async
335
+ * @param {Array<FungibleTransferPayload | ERC1155TransferPayload>} transfers
336
+ * @param {?WriteParams<typeof managedBudgetAbi, 'disburseBatch'>} [params]
337
+ * @returns {Promise<boolean>} - True if all disbursements were successful
338
+ */
339
+ public async disburseBatchRaw(
340
+ transfers: Array<FungibleTransferPayload | ERC1155TransferPayload>,
341
+ params?: WriteParams<typeof managedBudgetAbi, 'disburseBatch'>,
342
+ ) {
343
+ const { request, result } = await simulateManagedBudgetDisburseBatch(
344
+ this._config,
345
+ {
346
+ address: this.assertValidAddress(),
347
+ args: [transfers.map(prepareTransfer)],
348
+ ...this.optionallyAttachAccount(),
349
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
350
+ ...(params as any),
351
+ },
352
+ );
353
+ const hash = await writeManagedBudgetDisburseBatch(this._config, request);
354
+ return { hash, result };
355
+ }
356
+
357
+ /**
358
+ * Set the authorized status of the given accounts
359
+ * The mechanism for managing authorization is left to the implementing contract
360
+ *
361
+ * @public
362
+ * @async
363
+ * @param {Address[]} addresses - The accounts to authorize or deauthorize
364
+ * @param {boolean[]} allowed - The authorization status for the given accounts
365
+ * @param {?WriteParams<typeof managedBudgetAbi, 'setAuthorized'>} [params]
366
+ * @returns {Promise<void>}
367
+ */
368
+ public async setAuthorized(
369
+ addresses: Address[],
370
+ allowed: boolean[],
371
+ params?: WriteParams<typeof managedBudgetAbi, 'setAuthorized'>,
372
+ ) {
373
+ return this.awaitResult(this.setAuthorizedRaw(addresses, allowed, params));
374
+ }
375
+
376
+ /**
377
+ * Set the authorized status of the given accounts
378
+ * The mechanism for managing authorization is left to the implementing contract
379
+ *
380
+ * @public
381
+ * @async
382
+ * @param {Address[]} addresses - The accounts to authorize or deauthorize
383
+ * @param {boolean[]} allowed - The authorization status for the given accounts
384
+ * @param {?WriteParams<typeof managedBudgetAbi, 'setAuthorized'>} [params]
385
+ * @returns {Promise<void>}
386
+ */
387
+ public async setAuthorizedRaw(
388
+ addresses: Address[],
389
+ allowed: boolean[],
390
+ params?: WriteParams<typeof managedBudgetAbi, 'setAuthorized'>,
391
+ ) {
392
+ const { request, result } = await simulateManagedBudgetSetAuthorized(
393
+ this._config,
394
+ {
395
+ address: this.assertValidAddress(),
396
+ args: [addresses, allowed],
397
+ ...this.optionallyAttachAccount(),
398
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
399
+ ...(params as any),
400
+ },
401
+ );
402
+ const hash = await writeManagedBudgetSetAuthorized(this._config, request);
403
+ return { hash, result };
404
+ }
405
+
406
+ /**
407
+ * Grant many accounts permissions on the budget.
408
+ *
409
+ * @example
410
+ * ```ts
411
+ * await budget.grantRoles(['0xfoo', '0xbar], [ManagedBudgetRoles.MANAGER, ManagedBudgetRoles.ADMIN])
412
+ * ```
413
+ * @public
414
+ * @async
415
+ * @param {Address[]} addresses
416
+ * @param {bigint[]} roles
417
+ * @param {?WriteParams<typeof managedBudgetAbi, 'grantRoles'>} [params]
418
+ * @returns {unknown}
419
+ */
420
+ public async grantRoles(
421
+ addresses: Address[],
422
+ roles: bigint[],
423
+ params?: WriteParams<typeof managedBudgetAbi, 'grantRoles'>,
424
+ ) {
425
+ return this.awaitResult(this.grantRolesRaw(addresses, roles, params));
426
+ }
427
+
428
+ /**
429
+ * Grant many accounts permissions on the budget.
430
+ *
431
+ * @example
432
+ * ```ts
433
+ * await budget.grantRoles(['0xfoo', '0xbar], [ManagedBudgetRoles.MANAGER, ManagedBudgetRoles.ADMIN])
434
+ *
435
+ * @public
436
+ * @async
437
+ * @param {Address[]} addresses
438
+ * @param {bigint[]} roles
439
+ * @param {?WriteParams<typeof managedBudgetAbi, 'grantRoles'>} [params]
440
+ * @returns {unknown}
441
+ */
442
+ public async grantRolesRaw(
443
+ addresses: Address[],
444
+ roles: bigint[],
445
+ params?: WriteParams<typeof managedBudgetAbi, 'grantRoles'>,
446
+ ) {
447
+ const { request, result } = await simulateManagedBudgetGrantRoles(
448
+ this._config,
449
+ {
450
+ address: this.assertValidAddress(),
451
+ args: [addresses, roles],
452
+ ...this.optionallyAttachAccount(),
453
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
454
+ ...(params as any),
455
+ },
456
+ );
457
+ const hash = await writeManagedBudgetGrantRoles(
458
+ this._config,
459
+ // biome-ignore lint/suspicious/noExplicitAny: negligible low level lack of type intersection
460
+ request as any,
461
+ );
462
+ return { hash, result };
463
+ }
464
+
465
+ /**
466
+ * Revoke many accounts' permissions on the budget.
467
+ *
468
+ * @example
469
+ * ```ts
470
+ * await budget.revokeRoles(['0xfoo', '0xbar], [ManagedBudgetRoles.MANAGER, ManagedBudgetRoles.ADMIN])
471
+ *
472
+ * @public
473
+ * @async
474
+ * @param {Address[]} addresses
475
+ * @param {bigint[]} roles
476
+ * @param {?WriteParams<typeof managedBudgetAbi, 'revokeRoles'>} [params]
477
+ * @returns {unknown}
478
+ */
479
+ public async revokeRoles(
480
+ addresses: Address[],
481
+ roles: bigint[],
482
+ params?: WriteParams<typeof managedBudgetAbi, 'revokeRoles'>,
483
+ ) {
484
+ return this.awaitResult(this.revokeRolesRaw(addresses, roles, params));
485
+ }
486
+
487
+ /**
488
+ * Revoke many accounts' permissions on the budget.
489
+ *
490
+ * @example
491
+ * ```ts
492
+ * await budget.revokeRoles(['0xfoo', '0xbar], [ManagedBudgetRoles.MANAGER, ManagedBudgetRoles.ADMIN])
493
+ * @public
494
+ * @async
495
+ * @param {Address[]} addresses
496
+ * @param {bigint[]} roles
497
+ * @param {?WriteParams<typeof managedBudgetAbi, 'revokeRoles'>} [params]
498
+ * @returns {unknown}
499
+ */
500
+ public async revokeRolesRaw(
501
+ addresses: Address[],
502
+ roles: bigint[],
503
+ params?: WriteParams<typeof managedBudgetAbi, 'revokeRoles'>,
504
+ ) {
505
+ const { request, result } = await simulateManagedBudgetRevokeRoles(
506
+ this._config,
507
+ {
508
+ address: this.assertValidAddress(),
509
+ args: [addresses, roles],
510
+ ...this.optionallyAttachAccount(),
511
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
512
+ ...(params as any),
513
+ },
514
+ );
515
+ const hash = await writeManagedBudgetRevokeRoles(
516
+ this._config,
517
+ // biome-ignore lint/suspicious/noExplicitAny: negligible low level lack of type intersection
518
+ request as any,
519
+ );
520
+ return { hash, result };
521
+ }
522
+
523
+ /**
524
+ * Return an array of the roles assigned to the given account.
525
+ * @example
526
+ * ```ts
527
+ * (await budget.rolesOf(0xfoo)).includes(ManagedBudgetRoles.ADMIN)
528
+ * @public
529
+ * @param {Address} account
530
+ * @param {?ReadParams<typeof managedBudgetAbi, 'rolesOf'>} [params]
531
+ * @returns {Promise<Array<bigint>>}
532
+ */
533
+ public async rolesOf(
534
+ account: Address,
535
+ params?: ReadParams<typeof managedBudgetAbi, 'rolesOf'>,
536
+ ) {
537
+ const roles = await readManagedBudgetRolesOf(this._config, {
538
+ address: this.assertValidAddress(),
539
+ args: [account],
540
+ ...this.optionallyAttachAccount(),
541
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
542
+ ...(params as any),
543
+ });
544
+ return [ManagedBudgetRoles.MANAGER, ManagedBudgetRoles.ADMIN].filter(
545
+ (role) => (roles & role) === role,
546
+ );
547
+ }
548
+
549
+ /**
550
+ * Returns whether given account has any of the provided roles bitmap.
551
+ *
552
+ * @example
553
+ * ```ts
554
+ * await budget.hasAnyRole(0xfoo, ManagedBudgetRoles.ADMIN | ManagedBudgetRoles.MANAGER)
555
+ * @public
556
+ * @param {Address} account
557
+ * @param {bigint} roles
558
+ * @param {?ReadParams<typeof managedBudgetAbi, 'hasAnyRole'>} [params]
559
+ * @returns {Promise<boolean>}
560
+ */
561
+ public hasAnyRole(
562
+ account: Address,
563
+ roles: bigint,
564
+ params?: ReadParams<typeof managedBudgetAbi, 'hasAnyRole'>,
565
+ ) {
566
+ return readManagedBudgetHasAnyRole(this._config, {
567
+ address: this.assertValidAddress(),
568
+ args: [account, roles],
569
+ ...this.optionallyAttachAccount(),
570
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
571
+ ...(params as any),
572
+ });
573
+ }
574
+
575
+ /**
576
+ * Returns whether given account has all of the provided roles bitmap.
577
+ *
578
+ * @example
579
+ * ```ts
580
+ * await budget.hasAllRoles(0xfoo, ManagedBudgetRoles.ADMIN & ManagedBudgetRoles.MANAGER)
581
+ *
582
+ * @public
583
+ * @param {Address} account
584
+ * @param {bigint} roles
585
+ * @param {?ReadParams<typeof managedBudgetAbi, 'hasAllRoles'>} [params]
586
+ * @returns {*}
587
+ */
588
+ public hasAllRoles(
589
+ account: Address,
590
+ roles: bigint,
591
+ params?: ReadParams<typeof managedBudgetAbi, 'hasAllRoles'>,
592
+ ) {
593
+ return readManagedBudgetHasAllRoles(this._config, {
594
+ address: this.assertValidAddress(),
595
+ args: [account, roles],
596
+ ...this.optionallyAttachAccount(),
597
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
598
+ ...(params as any),
599
+ });
600
+ }
601
+
602
+ /**
603
+ * Check if the given account is authorized to use the budget
604
+ *
605
+ * @public
606
+ * @param {Address} account
607
+ * @param {?ReadParams<typeof managedBudgetAbi, 'isAuthorized'>} [params]
608
+ * @returns {Promise<boolean>} - True if the account is authorized
609
+ */
610
+ public isAuthorized(
611
+ account: Address,
612
+ params?: ReadParams<typeof managedBudgetAbi, 'isAuthorized'>,
613
+ ) {
614
+ return readManagedBudgetIsAuthorized(this._config, {
615
+ address: this.assertValidAddress(),
616
+ args: [account],
617
+ ...this.optionallyAttachAccount(),
618
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
619
+ ...(params as any),
620
+ });
621
+ }
622
+
623
+ /**
624
+ * Get the owner of the budget
625
+ *
626
+ * @public
627
+ * @param {?ReadParams<typeof managedBudgetAbi, 'owner'>} [params]
628
+ * @returns {Promise<Address>}
629
+ */
630
+ public owner(params?: ReadParams<typeof managedBudgetAbi, 'owner'>) {
631
+ return readManagedBudgetOwner(this._config, {
632
+ address: this.assertValidAddress(),
633
+ args: [],
634
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
635
+ ...(params as any),
636
+ });
637
+ }
638
+
639
+ /**
640
+ * Get the total amount of assets allocated to the budget, including any that have been distributed
641
+ * If a tokenId is provided, get the total amount of ERC1155 assets allocated to the budget, including any that have been distributed
642
+ *
643
+ * @public
644
+ * @param {Address} asset - The address of the asset
645
+ * @param {?(bigint | undefined)} [tokenId] - The ID of the token
646
+ * @param {?ReadParams<typeof managedBudgetAbi, 'total'>} [params]
647
+ * @returns {Promise<bigint>} - The total amount of assets
648
+ */
649
+ public total(
650
+ asset: Address,
651
+ tokenId?: bigint | undefined,
652
+ params?: ReadParams<typeof managedBudgetAbi, 'total'>,
653
+ ) {
654
+ return readManagedBudgetTotal(this._config, {
655
+ address: this.assertValidAddress(),
656
+ args: tokenId ? [asset, tokenId] : [asset],
657
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
658
+ ...(params as any),
659
+ });
660
+ }
661
+
662
+ /**
663
+ * Get the amount of assets available for distribution from the budget.
664
+ * If a tokenId is provided, get the amount of ERC1155 assets available for distribution from the budget
665
+ *
666
+ * @public
667
+ * @param {Address} asset
668
+ * @param {?(bigint | undefined)} [tokenId]
669
+ * @param {?ReadParams<typeof managedBudgetAbi, 'available'>} [params]
670
+ * @returns {Promise<bigint>} - The amount of assets available
671
+ */
672
+ public available(
673
+ asset: Address,
674
+ tokenId?: bigint | undefined,
675
+ params?: ReadParams<typeof managedBudgetAbi, 'available'>,
676
+ ) {
677
+ return readManagedBudgetAvailable(this._config, {
678
+ address: this.assertValidAddress(),
679
+ args: tokenId ? [asset, tokenId] : [asset],
680
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
681
+ ...(params as any),
682
+ });
683
+ }
684
+
685
+ /**
686
+ * Get the amount of assets that have been distributed from the budget.
687
+ * If a tokenId is provided, get the amount of ERC1155 assets that have been distributed from the budget
688
+ *
689
+ * @public
690
+ * @param {Address} asset
691
+ * @param {?(bigint | undefined)} [tokenId]
692
+ * @param {?ReadParams<typeof managedBudgetAbi, 'distributed'>} [params]
693
+ * @returns {Promise<bigint>} - The amount of assets distributed
694
+ */
695
+ public distributed(
696
+ asset: Address,
697
+ tokenId?: bigint | undefined,
698
+ params?: ReadParams<typeof managedBudgetAbi, 'distributed'>,
699
+ ) {
700
+ return readManagedBudgetDistributed(this._config, {
701
+ address: this.assertValidAddress(),
702
+ args: tokenId ? [asset, tokenId] : [asset],
703
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
704
+ ...(params as any),
705
+ });
706
+ }
707
+
708
+ /**
709
+ * @inheritdoc
710
+ *
711
+ * @public
712
+ * @param {?ManagedBudgetPayload} [_payload]
713
+ * @param {?DeployableOptions} [_options]
714
+ * @returns {GenericDeployableParams}
715
+ */
716
+ public override buildParameters(
717
+ _payload?: ManagedBudgetPayload,
718
+ _options?: DeployableOptions,
719
+ ): GenericDeployableParams {
720
+ const [payload, options] = this.validateDeploymentConfig(
721
+ _payload,
722
+ _options,
723
+ );
724
+ if (!payload.owner || payload.owner === zeroAddress) {
725
+ const owner = options.account
726
+ ? options.account.address
727
+ : options.config
728
+ ? getAccount(options.config).address
729
+ : this._account?.address;
730
+ if (owner) {
731
+ payload.owner = owner;
732
+ } else {
733
+ throw new DeployableUnknownOwnerProvidedError();
734
+ }
735
+ }
736
+ return {
737
+ abi: managedBudgetAbi,
738
+ bytecode: bytecode as Hex,
739
+ args: [prepareManagedBudgetPayload(payload)],
740
+ ...this.optionallyAttachAccount(options.account),
741
+ };
742
+ }
743
+ }