@boostxyz/sdk 0.0.0-alpha.2 → 0.0.0-alpha.20

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 (271) hide show
  1. package/dist/Actions/Action.cjs +2 -1
  2. package/dist/Actions/Action.cjs.map +1 -0
  3. package/dist/Actions/Action.d.ts +1 -1
  4. package/dist/Actions/Action.d.ts.map +1 -1
  5. package/dist/Actions/Action.js +14 -12
  6. package/dist/Actions/Action.js.map +1 -0
  7. package/dist/Actions/ContractAction.d.ts +57 -14
  8. package/dist/Actions/ContractAction.d.ts.map +1 -1
  9. package/dist/Actions/ERC721MintAction.d.ts +50 -23
  10. package/dist/Actions/ERC721MintAction.d.ts.map +1 -1
  11. package/dist/Actions/EventAction.cjs +2 -1
  12. package/dist/Actions/EventAction.cjs.map +1 -0
  13. package/dist/Actions/EventAction.d.ts +405 -36
  14. package/dist/Actions/EventAction.d.ts.map +1 -1
  15. package/dist/Actions/EventAction.js +15 -209
  16. package/dist/Actions/EventAction.js.map +1 -0
  17. package/dist/AllowLists/AllowList.cjs +2 -1
  18. package/dist/AllowLists/AllowList.cjs.map +1 -0
  19. package/dist/AllowLists/AllowList.d.ts +6 -5
  20. package/dist/AllowLists/AllowList.d.ts.map +1 -1
  21. package/dist/AllowLists/AllowList.js +46 -22
  22. package/dist/AllowLists/AllowList.js.map +1 -0
  23. package/dist/AllowLists/OpenAllowList.d.ts +423 -0
  24. package/dist/AllowLists/OpenAllowList.d.ts.map +1 -0
  25. package/dist/AllowLists/SimpleAllowList.cjs +2 -1
  26. package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
  27. package/dist/AllowLists/SimpleAllowList.d.ts +124 -40
  28. package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -1
  29. package/dist/AllowLists/SimpleAllowList.js +77 -77
  30. package/dist/AllowLists/SimpleAllowList.js.map +1 -0
  31. package/dist/AllowLists/SimpleDenyList.cjs +2 -1
  32. package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
  33. package/dist/AllowLists/SimpleDenyList.d.ts +234 -13
  34. package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -1
  35. package/dist/AllowLists/SimpleDenyList.js +12 -200
  36. package/dist/AllowLists/SimpleDenyList.js.map +1 -0
  37. package/dist/Auth/Auth.cjs +1 -0
  38. package/dist/Auth/Auth.cjs.map +1 -0
  39. package/dist/Auth/Auth.js +1 -0
  40. package/dist/Auth/Auth.js.map +1 -0
  41. package/dist/Auth/PassthroughAuth.cjs +2 -1
  42. package/dist/Auth/PassthroughAuth.cjs.map +1 -0
  43. package/dist/Auth/PassthroughAuth.js +5 -4
  44. package/dist/Auth/PassthroughAuth.js.map +1 -0
  45. package/dist/Boost.cjs +2 -1
  46. package/dist/Boost.cjs.map +1 -0
  47. package/dist/Boost.d.ts +111 -1
  48. package/dist/Boost.d.ts.map +1 -1
  49. package/dist/Boost.js +140 -5
  50. package/dist/Boost.js.map +1 -0
  51. package/dist/BoostCore-3-U1xTQN.cjs +3 -0
  52. package/dist/BoostCore-3-U1xTQN.cjs.map +1 -0
  53. package/dist/BoostCore-DVGBUr2y.js +1477 -0
  54. package/dist/BoostCore-DVGBUr2y.js.map +1 -0
  55. package/dist/BoostCore.cjs +2 -2
  56. package/dist/BoostCore.cjs.map +1 -0
  57. package/dist/BoostCore.d.ts +166 -43
  58. package/dist/BoostCore.d.ts.map +1 -1
  59. package/dist/BoostCore.js +30 -1103
  60. package/dist/BoostCore.js.map +1 -0
  61. package/dist/BoostRegistry.cjs +2 -1
  62. package/dist/BoostRegistry.cjs.map +1 -0
  63. package/dist/BoostRegistry.d.ts +64 -23
  64. package/dist/BoostRegistry.d.ts.map +1 -1
  65. package/dist/BoostRegistry.js +162 -88
  66. package/dist/BoostRegistry.js.map +1 -0
  67. package/dist/Budgets/Budget.cjs +2 -1
  68. package/dist/Budgets/Budget.cjs.map +1 -0
  69. package/dist/Budgets/Budget.d.ts +1 -1
  70. package/dist/Budgets/Budget.d.ts.map +1 -1
  71. package/dist/Budgets/Budget.js +15 -13
  72. package/dist/Budgets/Budget.js.map +1 -0
  73. package/dist/Budgets/ManagedBudget.cjs +2 -1
  74. package/dist/Budgets/ManagedBudget.cjs.map +1 -0
  75. package/dist/Budgets/ManagedBudget.d.ts +78 -188
  76. package/dist/Budgets/ManagedBudget.d.ts.map +1 -1
  77. package/dist/Budgets/ManagedBudget.js +86 -286
  78. package/dist/Budgets/ManagedBudget.js.map +1 -0
  79. package/dist/Budgets/VestingBudget.d.ts +243 -87
  80. package/dist/Budgets/VestingBudget.d.ts.map +1 -1
  81. package/dist/Deployable/Contract.cjs +2 -1
  82. package/dist/Deployable/Contract.cjs.map +1 -0
  83. package/dist/Deployable/Contract.d.ts +4 -5
  84. package/dist/Deployable/Contract.d.ts.map +1 -1
  85. package/dist/Deployable/Contract.js +7 -8
  86. package/dist/Deployable/Contract.js.map +1 -0
  87. package/dist/Deployable/Deployable.cjs +1 -0
  88. package/dist/Deployable/Deployable.cjs.map +1 -0
  89. package/dist/Deployable/Deployable.d.ts +9 -3
  90. package/dist/Deployable/Deployable.d.ts.map +1 -1
  91. package/dist/Deployable/Deployable.js +10 -5
  92. package/dist/Deployable/Deployable.js.map +1 -0
  93. package/dist/Deployable/DeployableTarget.cjs +2 -1
  94. package/dist/Deployable/DeployableTarget.cjs.map +1 -0
  95. package/dist/Deployable/DeployableTarget.d.ts +16 -15
  96. package/dist/Deployable/DeployableTarget.d.ts.map +1 -1
  97. package/dist/Deployable/DeployableTarget.js +49 -42
  98. package/dist/Deployable/DeployableTarget.js.map +1 -0
  99. package/dist/Deployable/DeployableTargetWithRBAC.cjs +2 -0
  100. package/dist/Deployable/DeployableTargetWithRBAC.cjs.map +1 -0
  101. package/dist/Deployable/DeployableTargetWithRBAC.d.ts +179 -0
  102. package/dist/Deployable/DeployableTargetWithRBAC.d.ts.map +1 -0
  103. package/dist/Deployable/DeployableTargetWithRBAC.js +222 -0
  104. package/dist/Deployable/DeployableTargetWithRBAC.js.map +1 -0
  105. package/dist/EventAction-CIPqmAoP.js +1450 -0
  106. package/dist/EventAction-CIPqmAoP.js.map +1 -0
  107. package/dist/EventAction-d-oeqZQs.cjs +2 -0
  108. package/dist/EventAction-d-oeqZQs.cjs.map +1 -0
  109. package/dist/Incentive-Bp8Sez7M.js +298 -0
  110. package/dist/Incentive-Bp8Sez7M.js.map +1 -0
  111. package/dist/Incentive-Djnzseoj.cjs +2 -0
  112. package/dist/Incentive-Djnzseoj.cjs.map +1 -0
  113. package/dist/Incentives/AllowListIncentive.cjs +2 -1
  114. package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
  115. package/dist/Incentives/AllowListIncentive.d.ts +49 -19
  116. package/dist/Incentives/AllowListIncentive.d.ts.map +1 -1
  117. package/dist/Incentives/AllowListIncentive.js +50 -34
  118. package/dist/Incentives/AllowListIncentive.js.map +1 -0
  119. package/dist/Incentives/CGDAIncentive.cjs +2 -1
  120. package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
  121. package/dist/Incentives/CGDAIncentive.d.ts +118 -22
  122. package/dist/Incentives/CGDAIncentive.d.ts.map +1 -1
  123. package/dist/Incentives/CGDAIncentive.js +67 -42
  124. package/dist/Incentives/CGDAIncentive.js.map +1 -0
  125. package/dist/Incentives/ERC1155Incentive.d.ts +99 -38
  126. package/dist/Incentives/ERC1155Incentive.d.ts.map +1 -1
  127. package/dist/Incentives/ERC20Incentive.cjs +2 -1
  128. package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
  129. package/dist/Incentives/ERC20Incentive.d.ts +73 -29
  130. package/dist/Incentives/ERC20Incentive.d.ts.map +1 -1
  131. package/dist/Incentives/ERC20Incentive.js +71 -48
  132. package/dist/Incentives/ERC20Incentive.js.map +1 -0
  133. package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts +523 -0
  134. package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts.map +1 -0
  135. package/dist/Incentives/ERC20VariableIncentive.d.ts +65 -28
  136. package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -1
  137. package/dist/Incentives/Incentive.cjs +2 -1
  138. package/dist/Incentives/Incentive.cjs.map +1 -0
  139. package/dist/Incentives/Incentive.d.ts +4 -7
  140. package/dist/Incentives/Incentive.d.ts.map +1 -1
  141. package/dist/Incentives/Incentive.js +17 -278
  142. package/dist/Incentives/Incentive.js.map +1 -0
  143. package/dist/Incentives/PointsIncentive.cjs +2 -1
  144. package/dist/Incentives/PointsIncentive.cjs.map +1 -0
  145. package/dist/Incentives/PointsIncentive.d.ts +65 -21
  146. package/dist/Incentives/PointsIncentive.d.ts.map +1 -1
  147. package/dist/Incentives/PointsIncentive.js +57 -36
  148. package/dist/Incentives/PointsIncentive.js.map +1 -0
  149. package/dist/SimpleDenyList-BwfNjRsg.cjs +2 -0
  150. package/dist/SimpleDenyList-BwfNjRsg.cjs.map +1 -0
  151. package/dist/SimpleDenyList-Cn5WpNn0.js +132 -0
  152. package/dist/SimpleDenyList-Cn5WpNn0.js.map +1 -0
  153. package/dist/Validators/SignerValidator.cjs +2 -1
  154. package/dist/Validators/SignerValidator.cjs.map +1 -0
  155. package/dist/Validators/SignerValidator.d.ts +310 -17
  156. package/dist/Validators/SignerValidator.d.ts.map +1 -1
  157. package/dist/Validators/SignerValidator.js +165 -36
  158. package/dist/Validators/SignerValidator.js.map +1 -0
  159. package/dist/Validators/Validator.cjs +2 -1
  160. package/dist/Validators/Validator.cjs.map +1 -0
  161. package/dist/Validators/Validator.d.ts +2 -2
  162. package/dist/Validators/Validator.d.ts.map +1 -1
  163. package/dist/Validators/Validator.js +12 -10
  164. package/dist/Validators/Validator.js.map +1 -0
  165. package/dist/claiming.cjs +2 -0
  166. package/dist/claiming.cjs.map +1 -0
  167. package/dist/claiming.d.ts +43 -0
  168. package/dist/claiming.d.ts.map +1 -0
  169. package/dist/claiming.js +17 -0
  170. package/dist/claiming.js.map +1 -0
  171. package/dist/componentInterfaces-D09mhzxO.cjs +2 -0
  172. package/dist/componentInterfaces-D09mhzxO.cjs.map +1 -0
  173. package/dist/componentInterfaces-RXBMI5yH.js +14 -0
  174. package/dist/componentInterfaces-RXBMI5yH.js.map +1 -0
  175. package/dist/deployments-BM42vImE.js +43 -0
  176. package/dist/deployments-BM42vImE.js.map +1 -0
  177. package/dist/deployments-CMdF5uEC.cjs +2 -0
  178. package/dist/deployments-CMdF5uEC.cjs.map +1 -0
  179. package/dist/deployments.json +41 -0
  180. package/dist/errors.cjs +2 -1
  181. package/dist/errors.cjs.map +1 -0
  182. package/dist/errors.d.ts +403 -1
  183. package/dist/errors.d.ts.map +1 -1
  184. package/dist/errors.js +285 -39
  185. package/dist/errors.js.map +1 -0
  186. package/dist/generated-B0tk-c9b.cjs +3 -0
  187. package/dist/generated-B0tk-c9b.cjs.map +1 -0
  188. package/dist/{generated-x_abr3Yv.js → generated-B7VaSah4.js} +2058 -2541
  189. package/dist/generated-B7VaSah4.js.map +1 -0
  190. package/dist/index.cjs +2 -1
  191. package/dist/index.cjs.map +1 -0
  192. package/dist/index.d.ts +10 -9
  193. package/dist/index.d.ts.map +1 -1
  194. package/dist/index.js +143 -1353
  195. package/dist/index.js.map +1 -0
  196. package/dist/transfers.cjs +2 -0
  197. package/dist/transfers.cjs.map +1 -0
  198. package/dist/transfers.d.ts +198 -0
  199. package/dist/transfers.d.ts.map +1 -0
  200. package/dist/transfers.js +84 -0
  201. package/dist/transfers.js.map +1 -0
  202. package/dist/utils.cjs +2 -1
  203. package/dist/utils.cjs.map +1 -0
  204. package/dist/utils.d.ts +26 -1350
  205. package/dist/utils.d.ts.map +1 -1
  206. package/dist/utils.js +38 -636
  207. package/dist/utils.js.map +1 -0
  208. package/package.json +37 -11
  209. package/src/Actions/Action.test.ts +79 -0
  210. package/src/Actions/Action.ts +61 -0
  211. package/src/Actions/ContractAction.test.ts +197 -0
  212. package/src/Actions/ContractAction.ts +300 -0
  213. package/src/Actions/ERC721MintAction.test.ts +112 -0
  214. package/src/Actions/ERC721MintAction.ts +291 -0
  215. package/src/Actions/EventAction.test.ts +787 -0
  216. package/src/Actions/EventAction.ts +1214 -0
  217. package/src/AllowLists/AllowList.test.ts +64 -0
  218. package/src/AllowLists/AllowList.ts +62 -0
  219. package/src/AllowLists/OpenAllowList.test.ts +40 -0
  220. package/src/AllowLists/OpenAllowList.ts +45 -0
  221. package/src/AllowLists/SimpleAllowList.test.ts +52 -0
  222. package/src/AllowLists/SimpleAllowList.ts +262 -0
  223. package/src/AllowLists/SimpleDenyList.test.ts +52 -0
  224. package/src/AllowLists/SimpleDenyList.ts +250 -0
  225. package/src/Auth/Auth.ts +11 -0
  226. package/src/Auth/PassthroughAuth.test.ts +12 -0
  227. package/src/Auth/PassthroughAuth.ts +80 -0
  228. package/src/Boost.ts +309 -0
  229. package/src/BoostCore.test.ts +827 -0
  230. package/src/BoostCore.ts +1447 -0
  231. package/src/BoostRegistry.ts +543 -0
  232. package/src/Budgets/Budget.test.ts +27 -0
  233. package/src/Budgets/Budget.ts +60 -0
  234. package/src/Budgets/ManagedBudget.test.ts +217 -0
  235. package/src/Budgets/ManagedBudget.ts +534 -0
  236. package/src/Budgets/VestingBudget.test.ts +123 -0
  237. package/src/Budgets/VestingBudget.ts +530 -0
  238. package/src/Deployable/Contract.ts +228 -0
  239. package/src/Deployable/Deployable.ts +250 -0
  240. package/src/Deployable/DeployableTarget.ts +234 -0
  241. package/src/Deployable/DeployableTargetWithRBAC.ts +323 -0
  242. package/src/Incentives/AllowListIncentive.test.ts +143 -0
  243. package/src/Incentives/AllowListIncentive.ts +336 -0
  244. package/src/Incentives/CGDAIncentive.test.ts +132 -0
  245. package/src/Incentives/CGDAIncentive.ts +470 -0
  246. package/src/Incentives/ERC1155Incentive.test.ts +87 -0
  247. package/src/Incentives/ERC1155Incentive.ts +465 -0
  248. package/src/Incentives/ERC20Incentive.test.ts +130 -0
  249. package/src/Incentives/ERC20Incentive.ts +484 -0
  250. package/src/Incentives/ERC20VariableCriteriaIncentive.test.ts +184 -0
  251. package/src/Incentives/ERC20VariableCriteriaIncentive.ts +309 -0
  252. package/src/Incentives/ERC20VariableIncentive.test.ts +136 -0
  253. package/src/Incentives/ERC20VariableIncentive.ts +422 -0
  254. package/src/Incentives/Incentive.test.ts +92 -0
  255. package/src/Incentives/Incentive.ts +86 -0
  256. package/src/Incentives/PointsIncentive.test.ts +139 -0
  257. package/src/Incentives/PointsIncentive.ts +367 -0
  258. package/src/Validators/SignerValidator.test.ts +159 -0
  259. package/src/Validators/SignerValidator.ts +683 -0
  260. package/src/Validators/Validator.test.ts +21 -0
  261. package/src/Validators/Validator.ts +55 -0
  262. package/src/claiming.ts +56 -0
  263. package/src/errors.ts +844 -0
  264. package/src/index.test.ts +122 -0
  265. package/src/index.ts +58 -0
  266. package/src/transfers.ts +284 -0
  267. package/src/utils.test.ts +44 -0
  268. package/src/utils.ts +247 -0
  269. package/dist/Budgets/SimpleBudget.d.ts +0 -793
  270. package/dist/Budgets/SimpleBudget.d.ts.map +0 -1
  271. package/dist/generated-BaaleHW-.cjs +0 -2
@@ -0,0 +1,534 @@
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
+ encodeAbiParameters,
33
+ parseAbiParameters,
34
+ zeroAddress,
35
+ } from 'viem';
36
+ import { ManagedBudget as ManagedBudgetBases } from '../../dist/deployments.json';
37
+ import type {
38
+ DeployableOptions,
39
+ GenericDeployableParams,
40
+ } from '../Deployable/Deployable';
41
+ import { DeployableTarget } from '../Deployable/DeployableTarget';
42
+ import { DeployableTargetWithRBAC } from '../Deployable/DeployableTargetWithRBAC';
43
+ import {
44
+ DeployableUnknownOwnerProvidedError,
45
+ UnknownTransferPayloadSupplied,
46
+ } from '../errors';
47
+ import {
48
+ type ERC1155TransferPayload,
49
+ type FungibleTransferPayload,
50
+ prepareERC1155Transfer,
51
+ prepareFungibleTransfer,
52
+ } from '../transfers';
53
+ import {
54
+ type GenericLog,
55
+ type ReadParams,
56
+ RegistryType,
57
+ type WriteParams,
58
+ } from '../utils';
59
+ export { managedBudgetAbi };
60
+ export type { ERC1155TransferPayload, FungibleTransferPayload };
61
+
62
+ /**
63
+ * The object representation of a `ManagedBudgetPayload.InitPayload`
64
+ *
65
+ * @export
66
+ * @interface ManagedBudgetPayload
67
+ * @typedef {ManagedBudgetPayload}
68
+ */
69
+ export interface ManagedBudgetPayload {
70
+ /**
71
+ * The budget's owner
72
+ *
73
+ * @type {Address}
74
+ */
75
+ owner: Address;
76
+ /**
77
+ * List of accounts authorized to use the budget. This list should include a Boost core address to interact with the protocol.
78
+ *
79
+ * @type {Address[]}
80
+ */
81
+ authorized: Address[];
82
+ /**
83
+ * List of roles to assign to the corresponding account by index.
84
+ *
85
+ * @type {ManagedBudgetRoles[]}
86
+ */
87
+ roles: ManagedBudgetRoles[];
88
+ }
89
+
90
+ /**
91
+ * Enum representing available roles for use in the `ManagedBudget`.
92
+ * `MANAGER` can disburse funds.
93
+ * `ADMIN` can additionally manage authorized users on the budget.
94
+ *
95
+ * @export
96
+ * @type {{ readonly MANAGER: 1n; readonly ADMIN_ROLE: 2n; }}
97
+ * @enum {bigint}
98
+ */
99
+ export enum ManagedBudgetRoles {
100
+ //@ts-expect-error ts doesn't like bigint enum values
101
+ MANAGER = 1n,
102
+ //@ts-expect-error ts doesn't like bigint enum values
103
+ ADMIN = 2n,
104
+ }
105
+
106
+ /**
107
+ * A generic `viem.Log` event with support for `ManagedBudget` event types.
108
+ *
109
+ * @export
110
+ * @typedef {ManagedBudgetLog}
111
+ * @template {ContractEventName<typeof managedBudgetAbi>} [event=ContractEventName<
112
+ * typeof managedBudgetAbi
113
+ * >]
114
+ */
115
+ export type ManagedBudgetLog<
116
+ event extends ContractEventName<typeof managedBudgetAbi> = ContractEventName<
117
+ typeof managedBudgetAbi
118
+ >,
119
+ > = GenericLog<typeof managedBudgetAbi, event>;
120
+
121
+ /**
122
+ * Typeguard to determine if a transfer payload is a Fungible Transfer
123
+ *
124
+ * @export
125
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
126
+ * @returns {transfer is FungibleTransferPayload}
127
+ */
128
+ export function isFungibleTransfer(
129
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
130
+ ): transfer is FungibleTransferPayload {
131
+ return (transfer as ERC1155TransferPayload).tokenId === undefined;
132
+ }
133
+
134
+ /**
135
+ * Typeguard to determine if a transfer payload is an ERC1155 Transfer
136
+ *
137
+ * @export
138
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
139
+ * @returns {transfer is ERC1155TransferPayload}
140
+ */
141
+ export function isERC1155TransferPayload(
142
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
143
+ ): transfer is ERC1155TransferPayload {
144
+ return (transfer as ERC1155TransferPayload).tokenId !== undefined;
145
+ }
146
+
147
+ /**
148
+ * Given either a Fungible transfer, or ERC1155 transfer, will properly encode parameters for transfers, claims, disbursements, allocations, etc.
149
+ *
150
+ * @export
151
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
152
+ * @returns {Hex}
153
+ * @throws {@link UnknownTransferPayloadSupplied}
154
+ */
155
+ export function prepareTransfer(
156
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
157
+ ) {
158
+ if (isFungibleTransfer(transfer)) {
159
+ return prepareFungibleTransfer(transfer);
160
+ }
161
+ if (isERC1155TransferPayload(transfer)) {
162
+ return prepareERC1155Transfer(transfer);
163
+ }
164
+ throw new UnknownTransferPayloadSupplied(transfer);
165
+ }
166
+
167
+ /**
168
+ * A minimal budget implementation that simply holds and distributes tokens (ERC20-like and native)
169
+ * This type of budget supports ETH, ERC20, and ERC1155 assets only
170
+ *
171
+ * @export
172
+ * @class ManagedBudget
173
+ * @typedef {ManagedBudget}
174
+ * @extends {DeployableTargetWithRBAC<ManagedBudgetPayload>}
175
+ */
176
+ export class ManagedBudget extends DeployableTargetWithRBAC<
177
+ ManagedBudgetPayload,
178
+ typeof managedBudgetAbi
179
+ > {
180
+ /**
181
+ * @inheritdoc
182
+ *
183
+ * @public
184
+ * @readonly
185
+ * @type {*}
186
+ */
187
+ public override readonly abi = managedBudgetAbi;
188
+ /**
189
+ * @inheritdoc
190
+ *
191
+ * @public
192
+ * @static
193
+ * @type {Record<number, Address>}
194
+ */
195
+ public static override bases: Record<number, Address> = {
196
+ ...(ManagedBudgetBases as Record<number, Address>),
197
+ };
198
+ /**
199
+ * @inheritdoc
200
+ *
201
+ * @public
202
+ * @static
203
+ * @type {RegistryType}
204
+ */
205
+ public static override registryType: RegistryType = RegistryType.BUDGET;
206
+
207
+ /**
208
+ * Allocates assets to the budget.
209
+ * The caller must have already approved the contract to transfer the asset
210
+ * If the asset transfer fails, the allocation will revert
211
+ *
212
+ * @public
213
+ * @async
214
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
215
+ * @param {?WriteParams} [params]
216
+ * @returns {Promise<boolean>} - True if the allocation was successful
217
+ */
218
+ public async allocate(
219
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
220
+ params?: WriteParams<typeof managedBudgetAbi, 'allocate'>,
221
+ ) {
222
+ return await this.awaitResult(this.allocateRaw(transfer, params));
223
+ }
224
+
225
+ /**
226
+ * Allocates assets to the budget.
227
+ * The caller must have already approved the contract to transfer the asset
228
+ * If the asset transfer fails, the allocation will revert
229
+ *
230
+ * @public
231
+ * @async
232
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
233
+ * @param {?WriteParams} [params]
234
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if the allocation was successful
235
+ */
236
+ public async allocateRaw(
237
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
238
+ params?: WriteParams<typeof managedBudgetAbi, 'allocate'>,
239
+ ) {
240
+ const { request, result } = await simulateManagedBudgetAllocate(
241
+ this._config,
242
+ {
243
+ address: this.assertValidAddress(),
244
+ args: [prepareTransfer(transfer)],
245
+ ...this.optionallyAttachAccount(),
246
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
247
+ ...(params as any),
248
+ },
249
+ );
250
+ const hash = await writeManagedBudgetAllocate(this._config, request);
251
+ return { hash, result };
252
+ }
253
+
254
+ /**
255
+ * Clawbacks assets from the budget.
256
+ * Only the owner can directly clawback assets from the budget
257
+ * If the amount is zero, the entire balance of the asset will be transferred to the receiver
258
+ * If the asset transfer fails, the reclamation will revert
259
+ *
260
+ * @public
261
+ * @async
262
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
263
+ * @param {?WriteParams} [params]
264
+ * @returns {Promise<boolean>} - True if the request was successful
265
+ */
266
+ public async clawback(
267
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
268
+ params?: WriteParams<typeof managedBudgetAbi, 'clawback'>,
269
+ ) {
270
+ return await this.awaitResult(this.clawbackRaw(transfer, params));
271
+ }
272
+
273
+ /**
274
+ * Clawbacks assets from the budget.
275
+ * Only the owner can directly clawback assets from the budget
276
+ * If the amount is zero, the entire balance of the asset will be transferred to the receiver
277
+ * If the asset transfer fails, the reclamation will revert
278
+ *
279
+ * @public
280
+ * @async
281
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
282
+ * @param {?WriteParams} [params]
283
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if the request was successful
284
+ */
285
+ public async clawbackRaw(
286
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
287
+ params?: WriteParams<typeof managedBudgetAbi, 'clawback'>,
288
+ ) {
289
+ const { request, result } = await simulateManagedBudgetClawback(
290
+ this._config,
291
+ {
292
+ address: this.assertValidAddress(),
293
+ args: [prepareTransfer(transfer)],
294
+ ...this.optionallyAttachAccount(),
295
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
296
+ ...(params as any),
297
+ },
298
+ );
299
+ const hash = await writeManagedBudgetClawback(this._config, request);
300
+ return { hash, result };
301
+ }
302
+
303
+ /**
304
+ * Disburses assets from the budget to a single recipient
305
+ * If the asset transfer fails, the disbursement will revert
306
+ *
307
+ * @public
308
+ * @async
309
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
310
+ * @param {?WriteParams} [params]
311
+ * @returns {Promise<boolean>} - True if the disbursement was successful
312
+ */
313
+ public async disburse(
314
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
315
+ params?: WriteParams<typeof managedBudgetAbi, 'disburse'>,
316
+ ) {
317
+ return await this.awaitResult(this.disburseRaw(transfer, params));
318
+ }
319
+
320
+ /**
321
+ * Disburses assets from the budget to a single recipient
322
+ * If the asset transfer fails, the disbursement will revert
323
+ *
324
+ * @public
325
+ * @async
326
+ * @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
327
+ * @param {?WriteParams} [params]
328
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if the disbursement was successful
329
+ */
330
+ public async disburseRaw(
331
+ transfer: FungibleTransferPayload | ERC1155TransferPayload,
332
+ params?: WriteParams<typeof managedBudgetAbi, 'disburse'>,
333
+ ) {
334
+ const { request, result } = await simulateManagedBudgetDisburse(
335
+ this._config,
336
+ {
337
+ address: this.assertValidAddress(),
338
+ args: [prepareTransfer(transfer)],
339
+ ...this.optionallyAttachAccount(),
340
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
341
+ ...(params as any),
342
+ },
343
+ );
344
+ const hash = await writeManagedBudgetDisburse(this._config, request);
345
+ return { hash, result };
346
+ }
347
+
348
+ /**
349
+ * Disburses assets from the budget to multiple recipients
350
+ *
351
+ * @public
352
+ * @async
353
+ * @param {Array<FungibleTransferPayload | ERC1155TransferPayload>} transfers
354
+ * @param {?WriteParams} [params]
355
+ * @returns {Promise<boolean>} - True if all disbursements were successful
356
+ */
357
+ public async disburseBatch(
358
+ transfers: Array<FungibleTransferPayload | ERC1155TransferPayload>,
359
+ params?: WriteParams<typeof managedBudgetAbi, 'disburseBatch'>,
360
+ ) {
361
+ return await this.awaitResult(this.disburseBatchRaw(transfers, params));
362
+ }
363
+
364
+ /**
365
+ * Disburses assets from the budget to multiple recipients
366
+ *
367
+ * @public
368
+ * @async
369
+ * @param {Array<FungibleTransferPayload | ERC1155TransferPayload>} transfers
370
+ * @param {?WriteParams} [params]
371
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if all disbursements were successful
372
+ */
373
+ public async disburseBatchRaw(
374
+ transfers: Array<FungibleTransferPayload | ERC1155TransferPayload>,
375
+ params?: WriteParams<typeof managedBudgetAbi, 'disburseBatch'>,
376
+ ) {
377
+ const { request, result } = await simulateManagedBudgetDisburseBatch(
378
+ this._config,
379
+ {
380
+ address: this.assertValidAddress(),
381
+ args: [transfers.map(prepareTransfer)],
382
+ ...this.optionallyAttachAccount(),
383
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
384
+ ...(params as any),
385
+ },
386
+ );
387
+ const hash = await writeManagedBudgetDisburseBatch(this._config, request);
388
+ return { hash, result };
389
+ }
390
+
391
+ /**
392
+ * Get the owner of the budget
393
+ *
394
+ * @public
395
+ * @param {?ReadParams} [params]
396
+ * @returns {Promise<Address>}
397
+ */
398
+ public owner(params?: ReadParams<typeof managedBudgetAbi, 'owner'>) {
399
+ return readManagedBudgetOwner(this._config, {
400
+ address: this.assertValidAddress(),
401
+ args: [],
402
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
403
+ ...(params as any),
404
+ });
405
+ }
406
+
407
+ /**
408
+ * Get the total amount of assets allocated to the budget, including any that have been distributed
409
+ * If a tokenId is provided, get the total amount of ERC1155 assets allocated to the budget, including any that have been distributed
410
+ *
411
+ * @public
412
+ * @param {Address} [asset="0x0000000000000000000000000000000000000000"] - The address of the asset
413
+ * @param {?(bigint | undefined)} [tokenId] - The ID of the token
414
+ * @param {?ReadParams} [params]
415
+ * @returns {Promise<bigint>} - The total amount of assets
416
+ */
417
+ public total(
418
+ asset: Address = zeroAddress,
419
+ tokenId?: bigint | undefined,
420
+ params?: ReadParams<typeof managedBudgetAbi, 'total'>,
421
+ ) {
422
+ return readManagedBudgetTotal(this._config, {
423
+ address: this.assertValidAddress(),
424
+ args: tokenId ? [asset, tokenId] : [asset],
425
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
426
+ ...(params as any),
427
+ });
428
+ }
429
+
430
+ /**
431
+ * Get the amount of assets available for distribution from the budget.
432
+ * If a tokenId is provided, get the amount of ERC1155 assets available for distribution from the budget
433
+ *
434
+ * @public
435
+ * @param {Address} [asset="0x0000000000000000000000000000000000000000"]
436
+ * @param {?(bigint | undefined)} [tokenId]
437
+ * @param {?ReadParams} [params]
438
+ * @returns {Promise<bigint>} - The amount of assets available
439
+ */
440
+ public available(
441
+ asset: Address = zeroAddress,
442
+ tokenId?: bigint | undefined,
443
+ params?: ReadParams<typeof managedBudgetAbi, 'available'>,
444
+ ) {
445
+ return readManagedBudgetAvailable(this._config, {
446
+ address: this.assertValidAddress(),
447
+ args: tokenId ? [asset, tokenId] : [asset],
448
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
449
+ ...(params as any),
450
+ });
451
+ }
452
+
453
+ /**
454
+ * Get the amount of assets that have been distributed from the budget.
455
+ * If a tokenId is provided, get the amount of ERC1155 assets that have been distributed from the budget
456
+ *
457
+ * @public
458
+ * @param {Address} [asset="0x0000000000000000000000000000000000000000"]
459
+ * @param {?(bigint | undefined)} [tokenId]
460
+ * @param {?ReadParams} [params]
461
+ * @returns {Promise<bigint>} - The amount of assets distributed
462
+ */
463
+ public distributed(
464
+ asset: Address = zeroAddress,
465
+ tokenId?: bigint | undefined,
466
+ params?: ReadParams<typeof managedBudgetAbi, 'distributed'>,
467
+ ) {
468
+ return readManagedBudgetDistributed(this._config, {
469
+ address: this.assertValidAddress(),
470
+ args: tokenId ? [asset, tokenId] : [asset],
471
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
472
+ ...(params as any),
473
+ });
474
+ }
475
+
476
+ /**
477
+ * @inheritdoc
478
+ *
479
+ * @public
480
+ * @param {?ManagedBudgetPayload} [_payload]
481
+ * @param {?DeployableOptions} [_options]
482
+ * @returns {GenericDeployableParams}
483
+ */
484
+ public override buildParameters(
485
+ _payload?: ManagedBudgetPayload,
486
+ _options?: DeployableOptions,
487
+ ): GenericDeployableParams {
488
+ const [payload, options] = this.validateDeploymentConfig(
489
+ _payload,
490
+ _options,
491
+ );
492
+ if (!payload.owner || payload.owner === zeroAddress) {
493
+ const owner = options.account
494
+ ? options.account.address
495
+ : options.config
496
+ ? getAccount(options.config).address
497
+ : this._account?.address;
498
+ if (owner) {
499
+ payload.owner = owner;
500
+ } else {
501
+ throw new DeployableUnknownOwnerProvidedError();
502
+ }
503
+ }
504
+ return {
505
+ abi: managedBudgetAbi,
506
+ bytecode: bytecode as Hex,
507
+ args: [prepareManagedBudgetPayload(payload)],
508
+ ...this.optionallyAttachAccount(options.account),
509
+ };
510
+ }
511
+ }
512
+
513
+ /**
514
+ * Given a {@link ManagedBudgetPayload}, properly encode a `ManagedBudget.InitPayload` for use with {@link ManagedBudget} initialization.
515
+ *
516
+ * @param {ManagedBudgetPayload} param0
517
+ * @param {Address} param0.owner - The budget's owner
518
+ * @param {{}} param0.authorized - List of accounts authorized to use the budget. This list should include a Boost core address to interact with the protocol.
519
+ * @param {{}} param0.roles - List of roles to assign to the corresponding account by index.
520
+ * @returns {Hex}
521
+ */
522
+ export const prepareManagedBudgetPayload = ({
523
+ owner,
524
+ authorized,
525
+ roles,
526
+ }: ManagedBudgetPayload) => {
527
+ return encodeAbiParameters(
528
+ parseAbiParameters([
529
+ 'ManagedBudgetPayload payload',
530
+ 'struct ManagedBudgetPayload { address owner; address[] authorized; uint256[] roles; }',
531
+ ]),
532
+ [{ owner, authorized, roles: roles as unknown as Array<bigint> }],
533
+ );
534
+ };
@@ -0,0 +1,123 @@
1
+ import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
2
+ import { isAddress, parseEther, zeroAddress } from 'viem';
3
+ import { beforeAll, beforeEach, describe, expect, test } from 'vitest';
4
+ import type { MockERC20 } from '@boostxyz/test/MockERC20';
5
+ import {
6
+ type Fixtures,
7
+ defaultOptions,
8
+ deployFixtures,
9
+ freshVestingBudget,
10
+ fundErc20,
11
+ fundVestingBudget,
12
+ } from '@boostxyz/test/helpers';
13
+ import { testAccount } from '@boostxyz/test/viem';
14
+ import { VestingBudget } from './VestingBudget';
15
+
16
+ let fixtures: Fixtures, budget: VestingBudget, erc20: MockERC20;
17
+
18
+ beforeAll(async () => {
19
+ fixtures = await loadFixture(deployFixtures(defaultOptions));
20
+ });
21
+
22
+ describe.skip('VestingBudget', () => {
23
+ test('can successfully be deployed', async () => {
24
+ const budget = new VestingBudget(defaultOptions, {
25
+ owner: testAccount.address,
26
+ authorized: [],
27
+ start: 0n,
28
+ duration: 100n,
29
+ cliff: 5n,
30
+ });
31
+ await budget.deploy();
32
+ expect(isAddress(budget.assertValidAddress())).toBe(true);
33
+ });
34
+
35
+ test('can be owned', async () => {
36
+ const budget = await loadFixture(
37
+ freshVestingBudget(defaultOptions, fixtures),
38
+ );
39
+ expect(await budget.owner()).toBe(defaultOptions.account.address);
40
+ });
41
+
42
+ test('can have authorized users', async () => {
43
+ const budget = await loadFixture(
44
+ freshVestingBudget(defaultOptions, fixtures),
45
+ );
46
+ expect(await budget.isAuthorized(defaultOptions.account.address)).toBe(
47
+ true,
48
+ );
49
+ expect(await budget.isAuthorized(zeroAddress)).toBe(false);
50
+ });
51
+
52
+ test('can have no initial balance', async () => {
53
+ const budget = await loadFixture(
54
+ freshVestingBudget(defaultOptions, fixtures),
55
+ );
56
+ expect(await budget.available()).toBe(0n);
57
+ });
58
+
59
+ describe('can allocate', () => {
60
+ beforeEach(async () => {
61
+ budget = await loadFixture(freshVestingBudget(defaultOptions, fixtures));
62
+ erc20 = await loadFixture(fundErc20(defaultOptions));
63
+ });
64
+
65
+ test('native assets', async () => {
66
+ await budget.allocate(
67
+ {
68
+ amount: parseEther('1.0'),
69
+ asset: zeroAddress,
70
+ target: defaultOptions.account.address,
71
+ },
72
+ {
73
+ value: parseEther('1.0'),
74
+ },
75
+ );
76
+ expect(await budget.available()).toBe(parseEther('1.0'));
77
+ });
78
+
79
+ test('erc20', async () => {
80
+ await erc20.approve(budget.assertValidAddress(), parseEther('100'));
81
+ await budget.allocate({
82
+ amount: parseEther('100'),
83
+ asset: erc20.assertValidAddress(),
84
+ target: defaultOptions.account.address,
85
+ });
86
+ expect(await budget.available(erc20.assertValidAddress())).toBe(
87
+ parseEther('100'),
88
+ );
89
+ });
90
+ });
91
+
92
+ describe('can disburse', () => {
93
+ beforeEach(async () => {
94
+ const budgetFixtures = await loadFixture(
95
+ fundVestingBudget(defaultOptions, fixtures),
96
+ );
97
+ budget = budgetFixtures.budget;
98
+ erc20 = budgetFixtures.erc20;
99
+ });
100
+
101
+ test('native assets', async () => {
102
+ await budget.disburse({
103
+ amount: parseEther('1.0'),
104
+ asset: zeroAddress,
105
+ target: defaultOptions.account.address,
106
+ });
107
+
108
+ expect(await budget.available()).toBe(0n);
109
+ });
110
+
111
+ test('erc20 assets', async () => {
112
+ await budget.disburse({
113
+ amount: parseEther('10'),
114
+ asset: erc20.assertValidAddress(),
115
+ target: defaultOptions.account.address,
116
+ });
117
+
118
+ expect(await budget.available(erc20.assertValidAddress())).toBe(
119
+ parseEther('90'),
120
+ );
121
+ });
122
+ });
123
+ });