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

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 (110) 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 +8 -8
  4. package/dist/Actions/EventAction.cjs +1 -1
  5. package/dist/Actions/EventAction.cjs.map +1 -1
  6. package/dist/Actions/EventAction.d.ts.map +1 -1
  7. package/dist/Actions/EventAction.js +320 -137
  8. package/dist/Actions/EventAction.js.map +1 -1
  9. package/dist/AllowLists/AllowList.cjs +1 -1
  10. package/dist/AllowLists/AllowList.cjs.map +1 -1
  11. package/dist/AllowLists/AllowList.js +3 -3
  12. package/dist/AllowLists/OpenAllowList.d.ts +183 -0
  13. package/dist/AllowLists/OpenAllowList.d.ts.map +1 -1
  14. package/dist/AllowLists/SimpleAllowList.cjs +1 -1
  15. package/dist/AllowLists/SimpleAllowList.cjs.map +1 -1
  16. package/dist/AllowLists/SimpleAllowList.d.ts +77 -31
  17. package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -1
  18. package/dist/AllowLists/SimpleAllowList.js +34 -70
  19. package/dist/AllowLists/SimpleAllowList.js.map +1 -1
  20. package/dist/AllowLists/SimpleDenyList.cjs +1 -1
  21. package/dist/AllowLists/SimpleDenyList.d.ts +186 -3
  22. package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -1
  23. package/dist/AllowLists/SimpleDenyList.js +4 -4
  24. package/dist/Auth/PassthroughAuth.cjs +1 -1
  25. package/dist/Auth/PassthroughAuth.js +1 -1
  26. package/dist/BoostCore.cjs +2 -2
  27. package/dist/BoostCore.js +54 -54
  28. package/dist/BoostRegistry.cjs +1 -1
  29. package/dist/BoostRegistry.js +10 -10
  30. package/dist/Budgets/Budget.cjs +1 -1
  31. package/dist/Budgets/Budget.cjs.map +1 -1
  32. package/dist/Budgets/Budget.d.ts.map +1 -1
  33. package/dist/Budgets/Budget.js +2 -2
  34. package/dist/Budgets/Budget.js.map +1 -1
  35. package/dist/Budgets/ManagedBudget.cjs +1 -1
  36. package/dist/Budgets/ManagedBudget.cjs.map +1 -1
  37. package/dist/Budgets/ManagedBudget.d.ts +6 -156
  38. package/dist/Budgets/ManagedBudget.d.ts.map +1 -1
  39. package/dist/Budgets/ManagedBudget.js +60 -282
  40. package/dist/Budgets/ManagedBudget.js.map +1 -1
  41. package/dist/Budgets/VestingBudget.d.ts +158 -54
  42. package/dist/Budgets/VestingBudget.d.ts.map +1 -1
  43. package/dist/Deployable/DeployableTarget.cjs +1 -1
  44. package/dist/Deployable/DeployableTarget.js +1 -1
  45. package/dist/Deployable/DeployableTargetWithRBAC.cjs +2 -0
  46. package/dist/Deployable/DeployableTargetWithRBAC.cjs.map +1 -0
  47. package/dist/Deployable/DeployableTargetWithRBAC.d.ts +179 -0
  48. package/dist/Deployable/DeployableTargetWithRBAC.d.ts.map +1 -0
  49. package/dist/Deployable/DeployableTargetWithRBAC.js +222 -0
  50. package/dist/Deployable/DeployableTargetWithRBAC.js.map +1 -0
  51. package/dist/{Incentive-CtuAJAjG.js → Incentive-DJf-vdyL.js} +23 -23
  52. package/dist/{Incentive-CtuAJAjG.js.map → Incentive-DJf-vdyL.js.map} +1 -1
  53. package/dist/{Incentive-CqX3fYEd.cjs → Incentive-DNwROd1r.cjs} +2 -2
  54. package/dist/{Incentive-CqX3fYEd.cjs.map → Incentive-DNwROd1r.cjs.map} +1 -1
  55. package/dist/Incentives/AllowListIncentive.cjs +1 -1
  56. package/dist/Incentives/AllowListIncentive.js +10 -10
  57. package/dist/Incentives/CGDAIncentive.cjs +1 -1
  58. package/dist/Incentives/CGDAIncentive.js +9 -9
  59. package/dist/Incentives/ERC20Incentive.cjs +1 -1
  60. package/dist/Incentives/ERC20Incentive.js +23 -23
  61. package/dist/Incentives/Incentive.cjs +1 -1
  62. package/dist/Incentives/Incentive.js +3 -3
  63. package/dist/Incentives/PointsIncentive.cjs +1 -1
  64. package/dist/Incentives/PointsIncentive.js +6 -6
  65. package/dist/SimpleDenyList-DMlUkmAn.cjs +2 -0
  66. package/dist/SimpleDenyList-DMlUkmAn.cjs.map +1 -0
  67. package/dist/SimpleDenyList-DvUvmOeE.js +132 -0
  68. package/dist/SimpleDenyList-DvUvmOeE.js.map +1 -0
  69. package/dist/Validators/SignerValidator.cjs +1 -1
  70. package/dist/Validators/SignerValidator.js +7 -7
  71. package/dist/Validators/Validator.cjs +1 -1
  72. package/dist/Validators/Validator.js +2 -2
  73. package/dist/componentInterfaces-BPVR_Ykd.js +13 -0
  74. package/dist/componentInterfaces-BPVR_Ykd.js.map +1 -0
  75. package/dist/{componentInterfaces-CKCBwG16.cjs → componentInterfaces-BfppSIl4.cjs} +2 -2
  76. package/dist/componentInterfaces-BfppSIl4.cjs.map +1 -0
  77. package/dist/generated-CMQ6ZC2_.cjs +3 -0
  78. package/dist/generated-CMQ6ZC2_.cjs.map +1 -0
  79. package/dist/{generated-DLMdMwD1.js → generated-C_7Jx3YG.js} +1654 -882
  80. package/dist/generated-C_7Jx3YG.js.map +1 -0
  81. package/dist/index.cjs +1 -1
  82. package/dist/index.d.ts +1 -0
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +100 -96
  85. package/dist/index.js.map +1 -1
  86. package/package.json +10 -3
  87. package/src/Actions/EventAction.test.ts +138 -0
  88. package/src/Actions/EventAction.ts +28 -7
  89. package/src/AllowLists/SimpleAllowList.ts +9 -54
  90. package/src/AllowLists/SimpleDenyList.ts +6 -3
  91. package/src/Budgets/Budget.ts +1 -2
  92. package/src/Budgets/ManagedBudget.ts +3 -277
  93. package/src/Budgets/VestingBudget.ts +3 -74
  94. package/src/Deployable/DeployableTargetWithRBAC.ts +323 -0
  95. package/src/index.test.ts +3 -4
  96. package/src/index.ts +1 -0
  97. package/dist/Budgets/SimpleBudget.d.ts +0 -824
  98. package/dist/Budgets/SimpleBudget.d.ts.map +0 -1
  99. package/dist/SimpleDenyList-9UIxZZKP.cjs +0 -2
  100. package/dist/SimpleDenyList-9UIxZZKP.cjs.map +0 -1
  101. package/dist/SimpleDenyList-DGPNc7ov.js +0 -132
  102. package/dist/SimpleDenyList-DGPNc7ov.js.map +0 -1
  103. package/dist/componentInterfaces-CKCBwG16.cjs.map +0 -1
  104. package/dist/componentInterfaces-Cmg8tUxq.js +0 -13
  105. package/dist/componentInterfaces-Cmg8tUxq.js.map +0 -1
  106. package/dist/generated-BLg7yPgI.cjs +0 -3
  107. package/dist/generated-BLg7yPgI.cjs.map +0 -1
  108. package/dist/generated-DLMdMwD1.js.map +0 -1
  109. package/src/Budgets/SimpleBudget.test.ts +0 -152
  110. package/src/Budgets/SimpleBudget.ts +0 -563
@@ -0,0 +1,323 @@
1
+ import {
2
+ rbacAbi,
3
+ readRbacHasAllRoles,
4
+ readRbacHasAnyRole,
5
+ readRbacIsAuthorized,
6
+ readRbacRolesOf,
7
+ simulateRbacGrantRoles,
8
+ simulateRbacRevokeRoles,
9
+ simulateRbacSetAuthorized,
10
+ writeRbacGrantRoles,
11
+ writeRbacRevokeRoles,
12
+ writeRbacSetAuthorized,
13
+ } from '@boostxyz/evm';
14
+ import type { Abi, Address, ContractEventName } from 'viem';
15
+ import { DeployableTarget } from '../Deployable/DeployableTarget';
16
+ import type { GenericLog, ReadParams, WriteParams } from '../utils';
17
+ export { rbacAbi };
18
+
19
+ /**
20
+ * Enum representing available roles for use with the `RBAC` authorization scheme.
21
+ * `MANAGER` has lowest level of write permissions, for specific implementations, see Budgets and ALlowLists
22
+ * `ADMIN` can additionally manage authorized users on the contract.
23
+ *
24
+ * @export
25
+ * @type {{ readonly MANAGER: 1n; readonly ADMIN_ROLE: 2n; }}
26
+ * @enum {bigint}
27
+ */
28
+ export enum Roles {
29
+ //@ts-expect-error ts doesn't like bigint enum values
30
+ MANAGER = 1n,
31
+ //@ts-expect-error ts doesn't like bigint enum values
32
+ ADMIN = 2n,
33
+ }
34
+
35
+ /**
36
+ * A generic `viem.Log` event with support for `Rbac` event types.
37
+ *
38
+ * @export
39
+ * @typedef {RBACLog}
40
+ * @template {ContractEventName<typeof rbacAbi>} [event=ContractEventName<
41
+ * typeof rbacAbi
42
+ * >]
43
+ */
44
+ export type RBACLog<
45
+ event extends ContractEventName<typeof rbacAbi> = ContractEventName<
46
+ typeof rbacAbi
47
+ >,
48
+ > = GenericLog<typeof rbacAbi, event>;
49
+
50
+ /**
51
+ * A minimal RBAC implementation that offers MANAGER and ADMIN roles, and
52
+ * Budgets and allowlists support this auth scheme
53
+ *
54
+ * @export
55
+ * @class DeployableTargetWithRBAC
56
+ * @typedef {DeployableTargetWithRBAC}
57
+ * @extends {DeployableTarget<RbacPayload>}
58
+ */
59
+ export class DeployableTargetWithRBAC<
60
+ Payload,
61
+ ABI extends Abi,
62
+ > extends DeployableTarget<Payload, ABI> {
63
+ /**
64
+ * Set the authorized status of the given accounts
65
+ * The mechanism for managing authorization is left to the implementing contract
66
+ *
67
+ * @public
68
+ * @async
69
+ * @param {Address[]} addresses - The accounts to authorize or deauthorize
70
+ * @param {boolean[]} allowed - The authorization status for the given accounts
71
+ * @param {?WriteParams<typeof rbacAbi, 'setAuthorized'>} [params]
72
+ * @returns {Promise<void>}
73
+ */
74
+ public async setAuthorized(
75
+ addresses: Address[],
76
+ allowed: boolean[],
77
+ params?: WriteParams<typeof rbacAbi, 'setAuthorized'>,
78
+ ) {
79
+ return await this.awaitResult(
80
+ this.setAuthorizedRaw(addresses, allowed, params),
81
+ );
82
+ }
83
+
84
+ /**
85
+ * Set the authorized status of the given accounts
86
+ * The mechanism for managing authorization is left to the implementing contract
87
+ *
88
+ * @public
89
+ * @async
90
+ * @param {Address[]} addresses - The accounts to authorize or deauthorize
91
+ * @param {boolean[]} allowed - The authorization status for the given accounts
92
+ * @param {?WriteParams<typeof rbacAbi, 'setAuthorized'>} [params]
93
+ * @returns {Promise<void>}
94
+ */
95
+ public async setAuthorizedRaw(
96
+ addresses: Address[],
97
+ allowed: boolean[],
98
+ params?: WriteParams<typeof rbacAbi, 'setAuthorized'>,
99
+ ) {
100
+ const { request, result } = await simulateRbacSetAuthorized(this._config, {
101
+ address: this.assertValidAddress(),
102
+ args: [addresses, allowed],
103
+ ...this.optionallyAttachAccount(),
104
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
105
+ ...(params as any),
106
+ });
107
+ const hash = await writeRbacSetAuthorized(this._config, request);
108
+ return { hash, result };
109
+ }
110
+
111
+ /**
112
+ * Grant many accounts permissions on the rbac.
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * await rbac.grantRoles(['0xfoo', '0xbar], [RbacRoles.MANAGER, RbacRoles.ADMIN])
117
+ * ```
118
+ * @public
119
+ * @async
120
+ * @param {Address[]} addresses
121
+ * @param {RbacRoles[]} roles
122
+ * @param {?WriteParams<typeof rbacAbi, 'grantRoles'>} [params]
123
+ * @returns {unknown}
124
+ */
125
+ public async grantRoles(
126
+ addresses: Address[],
127
+ roles: Roles[],
128
+ params?: WriteParams<typeof rbacAbi, 'grantRoles'>,
129
+ ) {
130
+ return await this.awaitResult(this.grantRolesRaw(addresses, roles, params));
131
+ }
132
+
133
+ /**
134
+ * Grant many accounts permissions on the rbac.
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * await rbac.grantRoles(['0xfoo', '0xbar], [Roles.MANAGER, Roles.ADMIN])
139
+ *
140
+ * @public
141
+ * @async
142
+ * @param {Address[]} addresses
143
+ * @param {RbacRoles[]} roles
144
+ * @param {?WriteParams<typeof rbacAbi, 'grantRoles'>} [params]
145
+ * @returns {unknown}
146
+ */
147
+ public async grantRolesRaw(
148
+ addresses: Address[],
149
+ roles: Roles[],
150
+ params?: WriteParams<typeof rbacAbi, 'grantRoles'>,
151
+ ) {
152
+ const { request, result } = await simulateRbacGrantRoles(this._config, {
153
+ address: this.assertValidAddress(),
154
+ args: [addresses, roles],
155
+ ...this.optionallyAttachAccount(),
156
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
157
+ ...(params as any),
158
+ });
159
+ const hash = await writeRbacGrantRoles(
160
+ this._config,
161
+ // biome-ignore lint/suspicious/noExplicitAny: negligible low level lack of type intersection
162
+ request as any,
163
+ );
164
+ return { hash, result };
165
+ }
166
+
167
+ /**
168
+ * Revoke many accounts' permissions on the rbac.
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * await rbac.revokeRoles(['0xfoo', '0xbar], [RbacRoles.MANAGER, RbacRoles.ADMIN])
173
+ *
174
+ * @public
175
+ * @async
176
+ * @param {Address[]} addresses
177
+ * @param {RbacRoles[]} roles
178
+ * @param {?WriteParams<typeof rbacAbi, 'revokeRoles'>} [params]
179
+ * @returns {unknown}
180
+ */
181
+ public async revokeRoles(
182
+ addresses: Address[],
183
+ roles: Roles[],
184
+ params?: WriteParams<typeof rbacAbi, 'revokeRoles'>,
185
+ ) {
186
+ return await this.awaitResult(
187
+ this.revokeRolesRaw(addresses, roles, params),
188
+ );
189
+ }
190
+
191
+ /**
192
+ * Revoke many accounts' permissions on the rbac.
193
+ *
194
+ * @example
195
+ * ```ts
196
+ * await rbac.revokeRoles(['0xfoo', '0xbar], [RbacRoles.MANAGER, RbacRoles.ADMIN])
197
+ * @public
198
+ * @async
199
+ * @param {Address[]} addresses
200
+ * @param {RbacRoles[]} roles
201
+ * @param {?WriteParams<typeof rbacAbi, 'revokeRoles'>} [params]
202
+ * @returns {unknown}
203
+ */
204
+ public async revokeRolesRaw(
205
+ addresses: Address[],
206
+ roles: Roles[],
207
+ params?: WriteParams<typeof rbacAbi, 'revokeRoles'>,
208
+ ) {
209
+ const { request, result } = await simulateRbacRevokeRoles(this._config, {
210
+ address: this.assertValidAddress(),
211
+ args: [addresses, roles],
212
+ ...this.optionallyAttachAccount(),
213
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
214
+ ...(params as any),
215
+ });
216
+ const hash = await writeRbacRevokeRoles(
217
+ this._config,
218
+ // biome-ignore lint/suspicious/noExplicitAny: negligible low level lack of type intersection
219
+ request as any,
220
+ );
221
+ return { hash, result };
222
+ }
223
+
224
+ /**
225
+ * Return an array of the roles assigned to the given account.
226
+ * @example
227
+ * ```ts
228
+ * (await rbac.rolesOf(0xfoo)).includes(RbacRoles.ADMIN)
229
+ * @public
230
+ * @param {Address} account
231
+ * @param {?ReadParams<typeof rbacAbi, 'rolesOf'>} [params]
232
+ * @returns {Promise<Array<RbacRoles>>}
233
+ */
234
+ public async rolesOf(
235
+ account: Address,
236
+ params?: ReadParams<typeof rbacAbi, 'rolesOf'>,
237
+ ) {
238
+ const roles = await readRbacRolesOf(this._config, {
239
+ address: this.assertValidAddress(),
240
+ args: [account],
241
+ ...this.optionallyAttachAccount(),
242
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
243
+ ...(params as any),
244
+ });
245
+ return ([Roles.MANAGER, Roles.ADMIN] as unknown as Array<bigint>).filter(
246
+ (role) => (roles & role) === role,
247
+ ) as unknown as Roles[];
248
+ }
249
+
250
+ /**
251
+ * Returns whether given account has any of the provided roles bitmap.
252
+ *
253
+ * @example
254
+ * ```ts
255
+ * await rbac.hasAnyRole(0xfoo, RbacRoles.ADMIN | RbacRoles.MANAGER)
256
+ * @public
257
+ * @param {Address} account
258
+ * @param {RbacRoles} roles
259
+ * @param {?ReadParams<typeof rbacAbi, 'hasAnyRole'>} [params]
260
+ * @returns {Promise<boolean>}
261
+ */
262
+ public hasAnyRole(
263
+ account: Address,
264
+ roles: Roles,
265
+ params?: ReadParams<typeof rbacAbi, 'hasAnyRole'>,
266
+ ) {
267
+ return readRbacHasAnyRole(this._config, {
268
+ address: this.assertValidAddress(),
269
+ args: [account, roles],
270
+ ...this.optionallyAttachAccount(),
271
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
272
+ ...(params as any),
273
+ });
274
+ }
275
+
276
+ /**
277
+ * Returns whether given account has all of the provided roles bitmap.
278
+ *
279
+ * @example
280
+ * ```ts
281
+ * await rbac.hasAllRoles(0xfoo, RbacRoles.ADMIN & RbacRoles.MANAGER)
282
+ *
283
+ * @public
284
+ * @param {Address} account
285
+ * @param {RbacRoles} roles
286
+ * @param {?ReadParams<typeof rbacAbi, 'hasAllRoles'>} [params]
287
+ * @returns {*}
288
+ */
289
+ public hasAllRoles(
290
+ account: Address,
291
+ roles: Roles,
292
+ params?: ReadParams<typeof rbacAbi, 'hasAllRoles'>,
293
+ ) {
294
+ return readRbacHasAllRoles(this._config, {
295
+ address: this.assertValidAddress(),
296
+ args: [account, roles],
297
+ ...this.optionallyAttachAccount(),
298
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
299
+ ...(params as any),
300
+ });
301
+ }
302
+
303
+ /**
304
+ * Check if the given account is authorized to use the rbac
305
+ *
306
+ * @public
307
+ * @param {Address} account
308
+ * @param {?ReadParams<typeof rbacAbi, 'isAuthorized'>} [params]
309
+ * @returns {Promise<boolean>} - True if the account is authorized
310
+ */
311
+ public isAuthorized(
312
+ account: Address,
313
+ params?: ReadParams<typeof rbacAbi, 'isAuthorized'>,
314
+ ) {
315
+ return readRbacIsAuthorized(this._config, {
316
+ address: this.assertValidAddress(),
317
+ args: [account],
318
+ ...this.optionallyAttachAccount(),
319
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
320
+ ...(params as any),
321
+ });
322
+ }
323
+ }
package/src/index.test.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { describe, expect, test } from 'vitest';
2
- import * as SDK from './index';
1
+ import { describe, expect, test } from "vitest";
2
+ import * as SDK from "./index";
3
3
 
4
- describe('sdk exports', () => {
4
+ describe("sdk exports", () => {
5
5
  test(`should export all public API`, () => {
6
6
  expect(SDK.BoostRegistry).toBeDefined();
7
7
  expect(SDK.BoostCore).toBeDefined();
@@ -14,7 +14,6 @@ describe('sdk exports', () => {
14
14
  expect(SDK.SimpleAllowList).toBeDefined();
15
15
  expect(SDK.SimpleDenyList).toBeDefined();
16
16
  expect(SDK.ManagedBudget).toBeDefined();
17
- // expect(SDK.SimpleBudget).toBeDefined();
18
17
  // expect(SDK.VestingBudget).toBeDefined();
19
18
  expect(SDK.AllowListIncentive).toBeDefined();
20
19
  expect(SDK.CGDAIncentive).toBeDefined();
package/src/index.ts CHANGED
@@ -27,6 +27,7 @@ export * from './Budgets/ManagedBudget';
27
27
  export * from './Deployable/Deployable';
28
28
  export * from './Deployable/Contract';
29
29
  export * from './Deployable/DeployableTarget';
30
+ export * from './Deployable/DeployableTargetWithRBAC';
30
31
 
31
32
  // Incentives
32
33