@boostxyz/sdk 5.5.0 → 6.0.1

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 (178) hide show
  1. package/dist/Actions/Action.cjs +1 -1
  2. package/dist/Actions/Action.js +4 -4
  3. package/dist/Actions/EventAction.cjs +1 -1
  4. package/dist/Actions/EventAction.cjs.map +1 -1
  5. package/dist/Actions/EventAction.d.ts +2 -1
  6. package/dist/Actions/EventAction.d.ts.map +1 -1
  7. package/dist/Actions/EventAction.js +110 -105
  8. package/dist/Actions/EventAction.js.map +1 -1
  9. package/dist/AllowLists/AllowList.cjs +1 -1
  10. package/dist/AllowLists/AllowList.js +3 -3
  11. package/dist/AllowLists/SimpleAllowList.cjs +1 -1
  12. package/dist/AllowLists/SimpleAllowList.cjs.map +1 -1
  13. package/dist/AllowLists/SimpleAllowList.d.ts +2 -2
  14. package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -1
  15. package/dist/AllowLists/SimpleAllowList.js +25 -25
  16. package/dist/AllowLists/SimpleAllowList.js.map +1 -1
  17. package/dist/AllowLists/SimpleDenyList.cjs +1 -1
  18. package/dist/AllowLists/SimpleDenyList.js +3 -3
  19. package/dist/Auth/PassthroughAuth.cjs +1 -1
  20. package/dist/Auth/PassthroughAuth.cjs.map +1 -1
  21. package/dist/Auth/PassthroughAuth.js +14 -14
  22. package/dist/Boost.cjs.map +1 -1
  23. package/dist/Boost.js.map +1 -1
  24. package/dist/BoostCore.cjs +2 -2
  25. package/dist/BoostCore.cjs.map +1 -1
  26. package/dist/BoostCore.d.ts +261 -0
  27. package/dist/BoostCore.d.ts.map +1 -1
  28. package/dist/BoostCore.js +442 -262
  29. package/dist/BoostCore.js.map +1 -1
  30. package/dist/BoostRegistry.cjs +1 -1
  31. package/dist/BoostRegistry.cjs.map +1 -1
  32. package/dist/BoostRegistry.js +43 -43
  33. package/dist/BoostRegistry.js.map +1 -1
  34. package/dist/Budget-CsqSI4NH.cjs +2 -0
  35. package/dist/Budget-CsqSI4NH.cjs.map +1 -0
  36. package/dist/Budget-bMiAGF8s.js +922 -0
  37. package/dist/Budget-bMiAGF8s.js.map +1 -0
  38. package/dist/Budgets/Budget.cjs +1 -1
  39. package/dist/Budgets/Budget.d.ts +5 -4
  40. package/dist/Budgets/Budget.d.ts.map +1 -1
  41. package/dist/Budgets/Budget.js +3 -3
  42. package/dist/Budgets/ManagedBudget.cjs +1 -1
  43. package/dist/Budgets/ManagedBudget.cjs.map +1 -1
  44. package/dist/Budgets/ManagedBudget.js +53 -53
  45. package/dist/Budgets/ManagedBudgetWithFees.d.ts +26 -0
  46. package/dist/Budgets/ManagedBudgetWithFees.d.ts.map +1 -1
  47. package/dist/Budgets/ManagedBudgetWithFeesV2.d.ts +1331 -0
  48. package/dist/Budgets/ManagedBudgetWithFeesV2.d.ts.map +1 -0
  49. package/dist/Deployable/DeployableTarget.cjs +1 -1
  50. package/dist/Deployable/DeployableTarget.js +1 -1
  51. package/dist/Deployable/DeployableTargetWithRBAC.cjs +1 -1
  52. package/dist/Deployable/DeployableTargetWithRBAC.js +15 -15
  53. package/dist/Incentive-DZLG6T1-.js +1036 -0
  54. package/dist/Incentive-DZLG6T1-.js.map +1 -0
  55. package/dist/Incentive-DvNdIJ_x.cjs +2 -0
  56. package/dist/Incentive-DvNdIJ_x.cjs.map +1 -0
  57. package/dist/Incentives/AllowListIncentive.cjs +1 -1
  58. package/dist/Incentives/AllowListIncentive.cjs.map +1 -1
  59. package/dist/Incentives/AllowListIncentive.d.ts +9 -1
  60. package/dist/Incentives/AllowListIncentive.d.ts.map +1 -1
  61. package/dist/Incentives/AllowListIncentive.js +64 -47
  62. package/dist/Incentives/AllowListIncentive.js.map +1 -1
  63. package/dist/Incentives/CGDAIncentive.cjs +1 -1
  64. package/dist/Incentives/CGDAIncentive.cjs.map +1 -1
  65. package/dist/Incentives/CGDAIncentive.d.ts +12 -1
  66. package/dist/Incentives/CGDAIncentive.d.ts.map +1 -1
  67. package/dist/Incentives/CGDAIncentive.js +64 -33
  68. package/dist/Incentives/CGDAIncentive.js.map +1 -1
  69. package/dist/Incentives/ERC20Incentive.cjs +1 -1
  70. package/dist/Incentives/ERC20Incentive.cjs.map +1 -1
  71. package/dist/Incentives/ERC20Incentive.d.ts +37 -1
  72. package/dist/Incentives/ERC20Incentive.d.ts.map +1 -1
  73. package/dist/Incentives/ERC20Incentive.js +73 -49
  74. package/dist/Incentives/ERC20Incentive.js.map +1 -1
  75. package/dist/Incentives/ERC20PeggedIncentive.d.ts +35 -0
  76. package/dist/Incentives/ERC20PeggedIncentive.d.ts.map +1 -1
  77. package/dist/Incentives/ERC20PeggedVariableCriteriaIncentive.d.ts +35 -0
  78. package/dist/Incentives/ERC20PeggedVariableCriteriaIncentive.d.ts.map +1 -1
  79. package/dist/Incentives/ERC20VariableCriteriaIncentive.cjs +1 -1
  80. package/dist/Incentives/ERC20VariableCriteriaIncentive.cjs.map +1 -1
  81. package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts +25 -0
  82. package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts.map +1 -1
  83. package/dist/Incentives/ERC20VariableCriteriaIncentive.js +24 -24
  84. package/dist/Incentives/ERC20VariableCriteriaIncentive.js.map +1 -1
  85. package/dist/Incentives/ERC20VariableIncentive.cjs +1 -1
  86. package/dist/Incentives/ERC20VariableIncentive.cjs.map +1 -1
  87. package/dist/Incentives/ERC20VariableIncentive.d.ts +35 -0
  88. package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -1
  89. package/dist/Incentives/ERC20VariableIncentive.js +55 -38
  90. package/dist/Incentives/ERC20VariableIncentive.js.map +1 -1
  91. package/dist/Incentives/Incentive.cjs +1 -1
  92. package/dist/Incentives/Incentive.d.ts +25 -0
  93. package/dist/Incentives/Incentive.d.ts.map +1 -1
  94. package/dist/Incentives/Incentive.js +3 -3
  95. package/dist/Incentives/PointsIncentive.cjs +1 -1
  96. package/dist/Incentives/PointsIncentive.cjs.map +1 -1
  97. package/dist/Incentives/PointsIncentive.d.ts +8 -0
  98. package/dist/Incentives/PointsIncentive.d.ts.map +1 -1
  99. package/dist/Incentives/PointsIncentive.js +50 -28
  100. package/dist/Incentives/PointsIncentive.js.map +1 -1
  101. package/dist/SimpleDenyList-BAIrFBAW.cjs +2 -0
  102. package/dist/{SimpleDenyList-CsRXJPwm.cjs.map → SimpleDenyList-BAIrFBAW.cjs.map} +1 -1
  103. package/dist/SimpleDenyList-C734XLxt.js +133 -0
  104. package/dist/{SimpleDenyList-ByAr4X1r.js.map → SimpleDenyList-C734XLxt.js.map} +1 -1
  105. package/dist/Validators/LimitedSignerValidator.cjs +1 -1
  106. package/dist/Validators/LimitedSignerValidator.cjs.map +1 -1
  107. package/dist/Validators/LimitedSignerValidator.d.ts +1 -1
  108. package/dist/Validators/LimitedSignerValidator.d.ts.map +1 -1
  109. package/dist/Validators/LimitedSignerValidator.js +33 -33
  110. package/dist/Validators/LimitedSignerValidator.js.map +1 -1
  111. package/dist/Validators/SignerValidator.cjs +1 -1
  112. package/dist/Validators/SignerValidator.cjs.map +1 -1
  113. package/dist/Validators/SignerValidator.d.ts +1 -1
  114. package/dist/Validators/SignerValidator.d.ts.map +1 -1
  115. package/dist/Validators/SignerValidator.js +26 -26
  116. package/dist/Validators/SignerValidator.js.map +1 -1
  117. package/dist/Validators/Validator.cjs +1 -1
  118. package/dist/Validators/Validator.js +4 -4
  119. package/dist/componentInterfaces-5Ezh3Pvx.js +19 -0
  120. package/dist/componentInterfaces-5Ezh3Pvx.js.map +1 -0
  121. package/dist/componentInterfaces-Cm4Zfn1v.cjs +2 -0
  122. package/dist/componentInterfaces-Cm4Zfn1v.cjs.map +1 -0
  123. package/dist/{deployments-D0fs26TV.js → deployments-3RHH-eW7.js} +47 -47
  124. package/dist/{deployments-D0fs26TV.js.map → deployments-3RHH-eW7.js.map} +1 -1
  125. package/dist/deployments-CIXw_WKk.cjs +2 -0
  126. package/dist/deployments-CIXw_WKk.cjs.map +1 -0
  127. package/dist/deployments.json +24 -24
  128. package/dist/errors.cjs +1 -1
  129. package/dist/errors.cjs.map +1 -1
  130. package/dist/errors.js +1 -1
  131. package/dist/errors.js.map +1 -1
  132. package/dist/generated-BPiHi7W2.cjs +3 -0
  133. package/dist/generated-BPiHi7W2.cjs.map +1 -0
  134. package/dist/{generated-Cyvr_Tjx.js → generated-CElkFqkY.js} +1510 -608
  135. package/dist/generated-CElkFqkY.js.map +1 -0
  136. package/dist/index.cjs +1 -1
  137. package/dist/index.d.ts +1 -0
  138. package/dist/index.d.ts.map +1 -1
  139. package/dist/index.js +153 -150
  140. package/package.json +2 -2
  141. package/src/Actions/EventAction.ts +25 -6
  142. package/src/AllowLists/SimpleAllowList.ts +2 -2
  143. package/src/BoostCore.test.ts +124 -2
  144. package/src/BoostCore.ts +259 -0
  145. package/src/Budgets/Budget.ts +8 -2
  146. package/src/Budgets/ManagedBudgetWithFees.test.ts +0 -1
  147. package/src/Budgets/ManagedBudgetWithFeesV2.test.ts +327 -0
  148. package/src/Budgets/ManagedBudgetWithFeesV2.ts +713 -0
  149. package/src/Incentives/AllowListIncentive.ts +17 -0
  150. package/src/Incentives/CGDAIncentive.ts +31 -0
  151. package/src/Incentives/ERC20Incentive.ts +27 -0
  152. package/src/Incentives/ERC20PeggedIncentive.ts +18 -0
  153. package/src/Incentives/ERC20PeggedVariableCriteriaIncentive.ts +26 -0
  154. package/src/Incentives/ERC20VariableIncentive.ts +18 -0
  155. package/src/Incentives/PointsIncentive.ts +22 -0
  156. package/src/Validators/LimitedSignerValidator.ts +1 -1
  157. package/src/Validators/SignerValidator.ts +1 -1
  158. package/src/errors.ts +1 -1
  159. package/src/index.ts +1 -0
  160. package/dist/Budget-AoNx7uFd.cjs +0 -2
  161. package/dist/Budget-AoNx7uFd.cjs.map +0 -1
  162. package/dist/Budget-DYIV9iNK.js +0 -463
  163. package/dist/Budget-DYIV9iNK.js.map +0 -1
  164. package/dist/Incentive-BbkfwGOb.cjs +0 -2
  165. package/dist/Incentive-BbkfwGOb.cjs.map +0 -1
  166. package/dist/Incentive-qlnv5kQB.js +0 -991
  167. package/dist/Incentive-qlnv5kQB.js.map +0 -1
  168. package/dist/SimpleDenyList-ByAr4X1r.js +0 -133
  169. package/dist/SimpleDenyList-CsRXJPwm.cjs +0 -2
  170. package/dist/componentInterfaces-D7r9xJmt.cjs +0 -2
  171. package/dist/componentInterfaces-D7r9xJmt.cjs.map +0 -1
  172. package/dist/componentInterfaces-PR3ijhgZ.js +0 -18
  173. package/dist/componentInterfaces-PR3ijhgZ.js.map +0 -1
  174. package/dist/deployments-DoIOqxco.cjs +0 -2
  175. package/dist/deployments-DoIOqxco.cjs.map +0 -1
  176. package/dist/generated-Cyvr_Tjx.js.map +0 -1
  177. package/dist/generated-DtYPHhtX.cjs +0 -3
  178. package/dist/generated-DtYPHhtX.cjs.map +0 -1
@@ -0,0 +1,713 @@
1
+ import {
2
+ managedBudgetWithFeesV2Abi,
3
+ readManagedBudgetAvailable,
4
+ readManagedBudgetDistributed,
5
+ readManagedBudgetOwner,
6
+ readManagedBudgetTotal,
7
+ readManagedBudgetWithFeesV2ManagementFee,
8
+ simulateManagedBudgetAllocate,
9
+ simulateManagedBudgetClawback,
10
+ simulateManagedBudgetClawbackFromTarget,
11
+ simulateManagedBudgetDisburse,
12
+ simulateManagedBudgetDisburseBatch,
13
+ simulateManagedBudgetWithFeesPayManagementFee,
14
+ simulateManagedBudgetWithFeesV2PayManagementFee,
15
+ simulateManagedBudgetWithFeesV2SetManagementFee,
16
+ writeManagedBudgetAllocate,
17
+ writeManagedBudgetClawback,
18
+ writeManagedBudgetClawbackFromTarget,
19
+ writeManagedBudgetDisburse,
20
+ writeManagedBudgetDisburseBatch,
21
+ writeManagedBudgetWithFeesPayManagementFee,
22
+ writeManagedBudgetWithFeesV2PayManagementFee,
23
+ writeManagedBudgetWithFeesV2SetManagementFee,
24
+ } from '@boostxyz/evm';
25
+ import { bytecode } from '@boostxyz/evm/artifacts/contracts/budgets/ManagedBudgetWithFeesV2.sol/ManagedBudgetWithFeesV2.json';
26
+ import { getAccount } from '@wagmi/core';
27
+ import {
28
+ type Address,
29
+ type ContractEventName,
30
+ type Hex,
31
+ encodeAbiParameters,
32
+ parseAbiParameters,
33
+ zeroAddress,
34
+ } from 'viem';
35
+ import { ManagedBudgetWithFees as ManagedBudgetWithFeesV2Bases } from '../../dist/deployments.json';
36
+ import type {
37
+ DeployableOptions,
38
+ GenericDeployableParams,
39
+ } from '../Deployable/Deployable';
40
+ import {
41
+ DeployableTargetWithRBAC,
42
+ type Roles,
43
+ } from '../Deployable/DeployableTargetWithRBAC';
44
+ import { DeployableUnknownOwnerProvidedError } from '../errors';
45
+ import type {
46
+ ERC1155TransferPayload,
47
+ FungibleTransferPayload,
48
+ } from '../transfers';
49
+ import {
50
+ type GenericLog,
51
+ type ReadParams,
52
+ RegistryType,
53
+ type WriteParams,
54
+ } from '../utils';
55
+ import { prepareTransfer } from './ManagedBudget';
56
+ export { managedBudgetWithFeesV2Abi };
57
+ export type { ERC1155TransferPayload, FungibleTransferPayload };
58
+
59
+ /**
60
+ * The object representation of a `ManagedBudgetWithFeesV2Payload.InitPayload`
61
+ *
62
+ * @export
63
+ * @interface ManagedBudgetWithFeesV2Payload
64
+ * @typedef {ManagedBudgetWithFeesV2Payload}
65
+ */
66
+ export interface ManagedBudgetWithFeesV2Payload {
67
+ /**
68
+ * The budget's owner
69
+ *
70
+ * @type {Address}
71
+ */
72
+ owner: Address;
73
+ /**
74
+ * List of accounts authorized to use the budget. This list should include a Boost core address to interact with the protocol.
75
+ *
76
+ * @type {Address[]}
77
+ */
78
+ authorized: Address[];
79
+ /**
80
+ * List of roles to assign to the corresponding account by index.
81
+ *
82
+ * @type {Roles[]}
83
+ */
84
+ roles: Roles[];
85
+ /**
86
+ * Management Fee rate for incentive payouts
87
+ *
88
+ * @type {bigint}
89
+ */
90
+ managementFee: bigint;
91
+ }
92
+
93
+ /**
94
+ * A generic `viem.Log` event with support for `ManagedBudgetWithFeesV2` event types.
95
+ *
96
+ * @export
97
+ * @typedef {ManagedBudgetWithFeesV2Log}
98
+ * @template {ContractEventName<typeof managedBudgetWithFeesV2Abi>} [event=ContractEventName<
99
+ * typeof managedBudgetWithFeesV2Abi
100
+ * >]
101
+ */
102
+ export type ManagedBudgetWithFeesV2Log<
103
+ event extends ContractEventName<
104
+ typeof managedBudgetWithFeesV2Abi
105
+ > = ContractEventName<typeof managedBudgetWithFeesV2Abi>,
106
+ > = GenericLog<typeof managedBudgetWithFeesV2Abi, event>;
107
+
108
+ /**
109
+ * A minimal budget implementation that simply holds and distributes tokens (ERC20-like and native)
110
+ * This type of budget supports ETH, ERC20, and ERC1155 assets only
111
+ *
112
+ * @export
113
+ * @class ManagedBudgetWithFeesV2
114
+ * @typedef {ManagedBudgetWithFeesV2}
115
+ * @extends {DeployableTargetWithRBAC<ManagedBudgetWithFeesV2Payload>}
116
+ */
117
+ export class ManagedBudgetWithFeesV2 extends DeployableTargetWithRBAC<
118
+ ManagedBudgetWithFeesV2Payload,
119
+ typeof managedBudgetWithFeesV2Abi
120
+ > {
121
+ /**
122
+ * @inheritdoc
123
+ *
124
+ * @public
125
+ * @readonly
126
+ * @type {*}
127
+ */
128
+ public override readonly abi = managedBudgetWithFeesV2Abi;
129
+ /**
130
+ * @inheritdoc
131
+ *
132
+ * @public
133
+ * @static
134
+ * @type {Record<number, Address>}
135
+ */
136
+ public static override bases: Record<number, Address> = {
137
+ 31337: import.meta.env.VITE_MANAGED_BUDGET_WITH_FEES_BASE,
138
+ ...(ManagedBudgetWithFeesV2Bases as Record<number, Address>),
139
+ };
140
+ /**
141
+ * @inheritdoc
142
+ *
143
+ * @public
144
+ * @static
145
+ * @type {RegistryType}
146
+ */
147
+ public static override registryType: RegistryType = RegistryType.BUDGET;
148
+
149
+ /**
150
+ * Allocates assets to the budget.
151
+ * The caller must have already approved the contract to transfer the asset
152
+ * If the asset transfer fails, the allocation will revert
153
+ *
154
+ * @public
155
+ * @async
156
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
157
+ * @param {?WriteParams} [params]
158
+ * @returns {Promise<boolean>} - True if the allocation was successful
159
+ */
160
+ public async allocate(
161
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
162
+ params?: WriteParams,
163
+ ) {
164
+ return await this.awaitResult(this.allocateRaw(transfer, params));
165
+ }
166
+
167
+ /**
168
+ * Allocates assets to the budget.
169
+ * The caller must have already approved the contract to transfer the asset
170
+ * If the asset transfer fails, the allocation will revert
171
+ *
172
+ * @public
173
+ * @async
174
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
175
+ * @param {?WriteParams} [params]
176
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if the allocation was successful
177
+ */
178
+ public async allocateRaw(
179
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
180
+ params?: WriteParams,
181
+ ) {
182
+ const { request, result } = await simulateManagedBudgetAllocate(
183
+ this._config,
184
+ {
185
+ address: this.assertValidAddress(),
186
+ args: [prepareTransfer(transfer)],
187
+ ...this.optionallyAttachAccount(),
188
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
189
+ ...(params as any),
190
+ },
191
+ );
192
+ const hash = await writeManagedBudgetAllocate(this._config, request);
193
+ return { hash, result };
194
+ }
195
+
196
+ /**
197
+ * Clawbacks assets from the budget.
198
+ * Only the owner can directly clawback assets from the budget
199
+ * If the amount is zero, the entire balance of the asset will be transferred to the receiver
200
+ * If the asset transfer fails, the reclamation will revert
201
+ *
202
+ * @public
203
+ * @async
204
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
205
+ * @param {?WriteParams} [params]
206
+ * @returns {Promise<boolean>} - True if the request was successful
207
+ */
208
+ public async clawback(
209
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
210
+ params?: WriteParams,
211
+ ) {
212
+ return await this.awaitResult(this.clawbackRaw(transfer, params));
213
+ }
214
+
215
+ /**
216
+ * Clawbacks assets from the budget.
217
+ * Only the owner or admin can directly clawback assets from the budget
218
+ * If the amount is zero, the entire balance of the asset will be transferred to the receiver
219
+ * If the asset transfer fails, the reclamation will revert
220
+ *
221
+ * @public
222
+ * @async
223
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
224
+ * @param {?WriteParams} [params]
225
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if the request was successful
226
+ */
227
+ public async clawbackRaw(
228
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
229
+ params?: WriteParams,
230
+ ) {
231
+ const { request, result } = await simulateManagedBudgetClawback(
232
+ this._config,
233
+ {
234
+ address: this.assertValidAddress(),
235
+ args: [prepareTransfer(transfer)],
236
+ ...this.optionallyAttachAccount(),
237
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
238
+ ...(params as any),
239
+ },
240
+ );
241
+ const hash = await writeManagedBudgetClawback(this._config, request);
242
+ return { hash, result };
243
+ }
244
+
245
+ /**
246
+ * Clawbacks assets from an incentive associated with the budget via Boost Core.
247
+ * Only the authorized users can clawback assets from an incentive.
248
+ * If the asset transfer fails, the reclamation will revert.
249
+ *
250
+ * @example
251
+ * ```ts
252
+ * const [amount, address] = await budgets.budget.clawbackFromTarget(
253
+ * core.assertValidAddress(),
254
+ * erc20Incentive.buildClawbackData(1n),
255
+ * boost.id,
256
+ * incentiveId,
257
+ * );
258
+ * ```
259
+ * @public
260
+ * @async
261
+ * @param {Address} target - The address of a contract implementing clawback, typically `BoostCore`
262
+ * @param {Hex} data - The encoded data payload for the clawback, can be acquired with `incentive.buildClawbackData`
263
+ * @param {bigint | number} boostId - The ID of the boost
264
+ * @param {bigint | number} incentiveId - The ID of the incentive
265
+ * @param {?WriteParams} [params] - Optional write parameters
266
+ * @returns {Promise<[bigint, Address]>} - Returns a tuple of amount reclaimed and the address reclaimed from
267
+ */
268
+ public async clawbackFromTarget(
269
+ target: Address,
270
+ data: Hex,
271
+ boostId: bigint | number,
272
+ incentiveId: bigint | number,
273
+ params?: WriteParams,
274
+ ) {
275
+ return await this.awaitResult(
276
+ this.clawbackFromTargetRaw(target, data, boostId, incentiveId, params),
277
+ );
278
+ }
279
+
280
+ /**
281
+ * Clawbacks assets from an incentive associated with the budget via Boost Core.
282
+ * Only the authorized users can clawback assets from an incentive.
283
+ * If the asset transfer fails, the reclamation will revert.
284
+ *
285
+ * @example
286
+ * ```ts
287
+ * const { hash, result: [ amount, address ] } = await budgets.budget.clawbackFromTargetRaw(
288
+ * core.assertValidAddress(),
289
+ * erc20Incentive.buildClawbackData(1n),
290
+ * boost.id,
291
+ * incentiveId,
292
+ * );
293
+ * ```
294
+ * @public
295
+ * @async
296
+ * @param {Address} target - The address of a contract implementing clawback, typically `BoostCore`
297
+ * @param {Hex} data - The encoded data payload for the clawback, can be acquired with `incentive.buildClawbackData`
298
+ * @param {bigint | number} boostId - The ID of the boost
299
+ * @param {bigint | number} incentiveId - The ID of the incentive
300
+ * @param {?WriteParams} [params] - Optional write parameters
301
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - Returns transaction hash and simulated result
302
+ */
303
+ public async clawbackFromTargetRaw(
304
+ target: Address,
305
+ data: Hex,
306
+ boostId: bigint | number,
307
+ incentiveId: bigint | number,
308
+ params?: WriteParams,
309
+ ) {
310
+ const { request, result } = await simulateManagedBudgetClawbackFromTarget(
311
+ this._config,
312
+ {
313
+ address: this.assertValidAddress(),
314
+ args: [target, data, BigInt(boostId), BigInt(incentiveId)],
315
+ ...this.optionallyAttachAccount(),
316
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
317
+ ...(params as any),
318
+ },
319
+ );
320
+ const hash = await writeManagedBudgetClawbackFromTarget(
321
+ this._config,
322
+ request,
323
+ );
324
+ return { hash, result };
325
+ }
326
+
327
+ /**
328
+ * Disburses assets from the budget to a single recipient
329
+ * If the asset transfer fails, the disbursement will revert
330
+ *
331
+ * @public
332
+ * @async
333
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
334
+ * @param {?WriteParams} [params]
335
+ * @returns {Promise<boolean>} - True if the disbursement was successful
336
+ */
337
+ public async disburse(
338
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
339
+ params?: WriteParams,
340
+ ) {
341
+ return await this.awaitResult(this.disburseRaw(transfer, params));
342
+ }
343
+
344
+ /**
345
+ * Disburses assets from the budget to a single recipient
346
+ * If the asset transfer fails, the disbursement will revert
347
+ *
348
+ * @public
349
+ * @async
350
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
351
+ * @param {?WriteParams} [params]
352
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if the disbursement was successful
353
+ */
354
+ public async disburseRaw(
355
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
356
+ params?: WriteParams,
357
+ ) {
358
+ const { request, result } = await simulateManagedBudgetDisburse(
359
+ this._config,
360
+ {
361
+ address: this.assertValidAddress(),
362
+ args: [prepareTransfer(transfer)],
363
+ ...this.optionallyAttachAccount(),
364
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
365
+ ...(params as any),
366
+ },
367
+ );
368
+ const hash = await writeManagedBudgetDisburse(this._config, request);
369
+ return { hash, result };
370
+ }
371
+
372
+ /**
373
+ * Disburses assets from the budget to multiple recipients
374
+ *
375
+ * @public
376
+ * @async
377
+ * @param {Array<FungibleTransferPayload | ERC1155TransferPayload>} transfers
378
+ * @param {?WriteParams} [params]
379
+ * @returns {Promise<boolean>} - True if all disbursements were successful
380
+ */
381
+ public async disburseBatch(
382
+ transfers: Array<FungibleTransferPayload | ERC1155TransferPayload>,
383
+ params?: WriteParams,
384
+ ) {
385
+ return await this.awaitResult(this.disburseBatchRaw(transfers, params));
386
+ }
387
+
388
+ /**
389
+ * Disburses assets from the budget to multiple recipients
390
+ *
391
+ * @public
392
+ * @async
393
+ * @param {Array<FungibleTransferPayload | ERC1155TransferPayload>} transfers
394
+ * @param {?WriteParams} [params]
395
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if all disbursements were successful
396
+ */
397
+ public async disburseBatchRaw(
398
+ transfers: Array<FungibleTransferPayload | ERC1155TransferPayload>,
399
+ params?: WriteParams,
400
+ ) {
401
+ const { request, result } = await simulateManagedBudgetDisburseBatch(
402
+ this._config,
403
+ {
404
+ address: this.assertValidAddress(),
405
+ args: [transfers.map(prepareTransfer)],
406
+ ...this.optionallyAttachAccount(),
407
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
408
+ ...(params as any),
409
+ },
410
+ );
411
+ const hash = await writeManagedBudgetDisburseBatch(this._config, request);
412
+ return { hash, result };
413
+ }
414
+
415
+ /**
416
+ * Pays out reserved management fees to the boost owner
417
+ * for a given incentive
418
+ *
419
+ * @public
420
+ * @async
421
+ * @param {bigint | string} boostId
422
+ * @param {bigint | string} incentiveId
423
+ * @param {?WriteParams} [params]
424
+ * @returns {Promise<boolean>} - True if the payout was successful
425
+ */
426
+ public async payManagementFee(
427
+ boostId: bigint | string,
428
+ incentiveId: bigint | string,
429
+ boostCore?: Address,
430
+ params?: WriteParams,
431
+ ) {
432
+ return boostCore
433
+ ? await this.awaitResult(
434
+ this.payManagementFeeWithCoreRaw(boostCore, boostId, incentiveId),
435
+ )
436
+ : await this.awaitResult(
437
+ this.payManagementFeeRaw(boostId, incentiveId, params),
438
+ );
439
+ }
440
+
441
+ /**
442
+ * Pays out reserved management fees to the boost owner
443
+ *
444
+ * @public
445
+ * @async
446
+ * @param {Address} boostCore
447
+ * @param bigint boostId
448
+ * @param bigint incentiveId
449
+ * @param {?WriteParams} [params]
450
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if the payout was successful
451
+ */
452
+ public async payManagementFeeRaw(
453
+ boostId: bigint | string,
454
+ incentiveId: bigint | string,
455
+ params?: WriteParams,
456
+ ) {
457
+ const { request, result } =
458
+ await simulateManagedBudgetWithFeesPayManagementFee(this._config, {
459
+ address: this.assertValidAddress(),
460
+ args: [boostId, incentiveId],
461
+ ...this.optionallyAttachAccount(),
462
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
463
+ ...(params as any),
464
+ });
465
+ const hash = await writeManagedBudgetWithFeesPayManagementFee(
466
+ this._config,
467
+ // @ts-ignore getting a type: 'legacy' | undefined is not assignable to type 'eip7702' | undefined error
468
+ request,
469
+ );
470
+ return { hash, result };
471
+ }
472
+
473
+ /**
474
+ * Pays out reserved management fees to the boost owner
475
+ *
476
+ * @public
477
+ * @async
478
+ * @param {Address} boostCore
479
+ * @param bigint boostId
480
+ * @param bigint incentiveId
481
+ * @param {?WriteParams} [params]
482
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if the payout was successful
483
+ */
484
+ public async payManagementFeeWithCoreRaw(
485
+ boostCore: Address,
486
+ boostId: bigint | string,
487
+ incentiveId: bigint | string,
488
+ params?: WriteParams,
489
+ ) {
490
+ const { request, result } =
491
+ await simulateManagedBudgetWithFeesV2PayManagementFee(this._config, {
492
+ address: this.assertValidAddress(),
493
+ args: [boostCore, boostId, incentiveId],
494
+ ...this.optionallyAttachAccount(),
495
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
496
+ ...(params as any),
497
+ });
498
+ const hash = await writeManagedBudgetWithFeesV2PayManagementFee(
499
+ this._config,
500
+ // @ts-ignore getting a type: 'legacy' | undefined is not assignable to type 'eip7702' | undefined error
501
+ request,
502
+ );
503
+ return { hash, result };
504
+ }
505
+
506
+ /**
507
+ * Sets the management fee for the budget
508
+ * @public
509
+ * @async
510
+ * @param {bigint} managementFee
511
+ * @param {?WriteParams} [params]
512
+ * @returns {Promise<void>} - will throw if the transaction fails
513
+ */
514
+ public async setManagementFee(managementFee: bigint, params?: WriteParams) {
515
+ return await this.awaitResult(
516
+ this.setManagementFeeRaw(managementFee, params),
517
+ );
518
+ }
519
+
520
+ /**
521
+ * Sets the management fee for the budget
522
+ * @public
523
+ * @async
524
+ * @param {bigint} managementFee
525
+ * @param {?WriteParams} [params]
526
+ * @returns {Promise<{ hash: `0x${string}`; result: void; }>}
527
+ */
528
+ public async setManagementFeeRaw(
529
+ managementFee: bigint,
530
+ params?: WriteParams,
531
+ ) {
532
+ const { request, result } =
533
+ await simulateManagedBudgetWithFeesV2SetManagementFee(this._config, {
534
+ address: this.assertValidAddress(),
535
+ args: [managementFee],
536
+ ...this.optionallyAttachAccount(),
537
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
538
+ ...(params as any),
539
+ });
540
+ const hash = await writeManagedBudgetWithFeesV2SetManagementFee(
541
+ this._config,
542
+ request,
543
+ );
544
+ return { hash, result };
545
+ }
546
+
547
+ /**
548
+ * Get the configured management fee for the budget
549
+ * @public
550
+ * @param {?ReadParams} [params]
551
+ * @returns {Promise<bigint>} - The management fee
552
+ */
553
+ public async managementFee(params?: ReadParams) {
554
+ return await readManagedBudgetWithFeesV2ManagementFee(this._config, {
555
+ address: this.assertValidAddress(),
556
+ args: [],
557
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
558
+ ...(params as any),
559
+ });
560
+ }
561
+
562
+ /**
563
+ * Get the owner of the budget
564
+ *
565
+ * @public
566
+ * @param {?ReadParams} [params]
567
+ * @returns {Promise<Address>}
568
+ */
569
+ public owner(params?: ReadParams) {
570
+ return readManagedBudgetOwner(this._config, {
571
+ address: this.assertValidAddress(),
572
+ args: [],
573
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
574
+ ...(params as any),
575
+ });
576
+ }
577
+
578
+ /**
579
+ * Get the total amount of assets allocated to the budget, including any that have been distributed
580
+ * If a tokenId is provided, get the total amount of ERC1155 assets allocated to the budget, including any that have been distributed
581
+ *
582
+ * @public
583
+ * @param {Address} [asset="0x0000000000000000000000000000000000000000"] - The address of the asset
584
+ * @param {?(bigint | undefined)} [tokenId] - The ID of the token
585
+ * @param {?ReadParams} [params]
586
+ * @returns {Promise<bigint>} - The total amount of assets
587
+ */
588
+ public total(
589
+ asset: Address = zeroAddress,
590
+ tokenId?: bigint | undefined,
591
+ params?: ReadParams,
592
+ ) {
593
+ return readManagedBudgetTotal(this._config, {
594
+ address: this.assertValidAddress(),
595
+ args: tokenId ? [asset, tokenId] : [asset],
596
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
597
+ ...(params as any),
598
+ });
599
+ }
600
+
601
+ /**
602
+ * Get the amount of assets available for distribution from the budget.
603
+ * If a tokenId is provided, get the amount of ERC1155 assets available for distribution from the budget
604
+ *
605
+ * @public
606
+ * @param {Address} [asset="0x0000000000000000000000000000000000000000"]
607
+ * @param {?(bigint | undefined)} [tokenId]
608
+ * @param {?ReadParams} [params]
609
+ * @returns {Promise<bigint>} - The amount of assets available
610
+ */
611
+ public available(
612
+ asset: Address = zeroAddress,
613
+ tokenId?: bigint | undefined,
614
+ params?: ReadParams,
615
+ ) {
616
+ return readManagedBudgetAvailable(this._config, {
617
+ address: this.assertValidAddress(),
618
+ args: tokenId ? [asset, tokenId] : [asset],
619
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
620
+ ...(params as any),
621
+ });
622
+ }
623
+
624
+ /**
625
+ * Get the amount of assets that have been distributed from the budget.
626
+ * If a tokenId is provided, get the amount of ERC1155 assets that have been distributed from the budget
627
+ *
628
+ * @public
629
+ * @param {Address} [asset="0x0000000000000000000000000000000000000000"]
630
+ * @param {?(bigint | undefined)} [tokenId]
631
+ * @param {?ReadParams} [params]
632
+ * @returns {Promise<bigint>} - The amount of assets distributed
633
+ */
634
+ public distributed(
635
+ asset: Address = zeroAddress,
636
+ tokenId?: bigint | undefined,
637
+ params?: ReadParams,
638
+ ) {
639
+ return readManagedBudgetDistributed(this._config, {
640
+ address: this.assertValidAddress(),
641
+ args: tokenId ? [asset, tokenId] : [asset],
642
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
643
+ ...(params as any),
644
+ });
645
+ }
646
+
647
+ /**
648
+ * @inheritdoc
649
+ *
650
+ * @public
651
+ * @param {?ManagedBudgetWithFeesV2Payload} [_payload]
652
+ * @param {?DeployableOptions} [_options]
653
+ * @returns {GenericDeployableParams}
654
+ */
655
+ public override buildParameters(
656
+ _payload?: ManagedBudgetWithFeesV2Payload,
657
+ _options?: DeployableOptions,
658
+ ): GenericDeployableParams {
659
+ const [payload, options] = this.validateDeploymentConfig(
660
+ _payload,
661
+ _options,
662
+ );
663
+ if (!payload.owner || payload.owner === zeroAddress) {
664
+ const owner = options.account
665
+ ? options.account.address
666
+ : options.config
667
+ ? getAccount(options.config).address
668
+ : this._account?.address;
669
+ if (owner) {
670
+ payload.owner = owner;
671
+ } else {
672
+ throw new DeployableUnknownOwnerProvidedError();
673
+ }
674
+ }
675
+ return {
676
+ abi: managedBudgetWithFeesV2Abi,
677
+ bytecode: bytecode as Hex,
678
+ args: [prepareManagedBudgetWithFeesV2Payload(payload)],
679
+ ...this.optionallyAttachAccount(options.account),
680
+ };
681
+ }
682
+ }
683
+
684
+ /**
685
+ * Given a {@link ManagedBudgetWithFeesV2Payload}, properly encode a `ManagedBudgetWithFeesV2.InitPayload` for use with {@link ManagedBudgetWithFeesV2} initialization.
686
+ *
687
+ * @param {ManagedBudgetWithFeesV2Payload} param0
688
+ * @param {Address} param0.owner - The budget's owner
689
+ * @param {{}} param0.authorized - List of accounts authorized to use the budget. This list should include a Boost core address to interact with the protocol.
690
+ * @param {{}} param0.roles - List of roles to assign to the corresponding account by index.
691
+ * @returns {Hex}
692
+ */
693
+ export const prepareManagedBudgetWithFeesV2Payload = ({
694
+ owner,
695
+ authorized,
696
+ roles,
697
+ managementFee,
698
+ }: ManagedBudgetWithFeesV2Payload) => {
699
+ return encodeAbiParameters(
700
+ parseAbiParameters([
701
+ 'ManagedBudgetWithFeesV2Payload payload',
702
+ 'struct ManagedBudgetWithFeesV2Payload { address owner; address[] authorized; uint256[] roles; uint256 managementFee; }',
703
+ ]),
704
+ [
705
+ {
706
+ owner,
707
+ authorized,
708
+ roles: roles as unknown as Array<bigint>,
709
+ managementFee,
710
+ },
711
+ ],
712
+ );
713
+ };