@boostxyz/sdk 0.0.0-alpha.16 → 0.0.0-alpha.18

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