@boostxyz/sdk 1.1.0-alpha.22 → 1.1.0-alpha.23
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.
- package/dist/Actions/Action.cjs +1 -1
- package/dist/Actions/Action.cjs.map +1 -1
- package/dist/Actions/Action.js +6 -6
- package/dist/Actions/EventAction.cjs +1 -1
- package/dist/Actions/EventAction.cjs.map +1 -1
- package/dist/Actions/EventAction.d.ts +9 -6
- package/dist/Actions/EventAction.d.ts.map +1 -1
- package/dist/Actions/EventAction.js +820 -15
- package/dist/Actions/EventAction.js.map +1 -1
- package/dist/AllowLists/AllowList.cjs +1 -1
- package/dist/AllowLists/AllowList.js +2 -2
- package/dist/AllowLists/OpenAllowList.d.ts +28 -28
- package/dist/AllowLists/SimpleAllowList.cjs +1 -1
- package/dist/AllowLists/SimpleAllowList.cjs.map +1 -1
- package/dist/AllowLists/SimpleAllowList.d.ts +28 -28
- package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -1
- package/dist/AllowLists/SimpleAllowList.js +11 -10
- package/dist/AllowLists/SimpleAllowList.js.map +1 -1
- package/dist/AllowLists/SimpleDenyList.cjs +1 -1
- package/dist/AllowLists/SimpleDenyList.d.ts +28 -28
- package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -1
- package/dist/AllowLists/SimpleDenyList.js +3 -3
- package/dist/Auth/PassthroughAuth.cjs +1 -1
- package/dist/Auth/PassthroughAuth.js +1 -1
- package/dist/BoostCore-Btl5BdAs.cjs +3 -0
- package/dist/BoostCore-Btl5BdAs.cjs.map +1 -0
- package/dist/{BoostCore-BVZExPPu.js → BoostCore-CD56zbYX.js} +1678 -499
- package/dist/BoostCore-CD56zbYX.js.map +1 -0
- package/dist/BoostCore.cjs +1 -1
- package/dist/BoostCore.d.ts +7 -7
- package/dist/BoostCore.d.ts.map +1 -1
- package/dist/BoostCore.js +6 -6
- package/dist/BoostRegistry.cjs +1 -1
- package/dist/BoostRegistry.cjs.map +1 -1
- package/dist/BoostRegistry.d.ts +6 -6
- package/dist/BoostRegistry.d.ts.map +1 -1
- package/dist/BoostRegistry.js +50 -50
- package/dist/BoostRegistry.js.map +1 -1
- package/dist/Budgets/Budget.cjs +1 -1
- package/dist/Budgets/Budget.js +1 -1
- package/dist/Budgets/ManagedBudget.cjs +1 -1
- package/dist/Budgets/ManagedBudget.cjs.map +1 -1
- package/dist/Budgets/ManagedBudget.d.ts +28 -28
- package/dist/Budgets/ManagedBudget.d.ts.map +1 -1
- package/dist/Budgets/ManagedBudget.js +30 -29
- package/dist/Budgets/ManagedBudget.js.map +1 -1
- package/dist/Budgets/VestingBudget.d.ts +28 -28
- package/dist/Budgets/VestingBudget.d.ts.map +1 -1
- package/dist/Deployable/DeployableTarget.cjs +1 -1
- package/dist/Deployable/DeployableTarget.js +1 -1
- package/dist/Deployable/DeployableTargetWithRBAC.cjs +1 -1
- package/dist/Deployable/DeployableTargetWithRBAC.cjs.map +1 -1
- package/dist/Deployable/DeployableTargetWithRBAC.d.ts +92 -23
- package/dist/Deployable/DeployableTargetWithRBAC.d.ts.map +1 -1
- package/dist/Deployable/DeployableTargetWithRBAC.js +145 -47
- package/dist/Deployable/DeployableTargetWithRBAC.js.map +1 -1
- package/dist/{Incentive-BhHaK3PZ.cjs → Incentive-CcnOIc8L.cjs} +2 -2
- package/dist/{Incentive-BhHaK3PZ.cjs.map → Incentive-CcnOIc8L.cjs.map} +1 -1
- package/dist/{Incentive-Cqg1w6wD.js → Incentive-rM5nKznp.js} +30 -29
- package/dist/{Incentive-Cqg1w6wD.js.map → Incentive-rM5nKznp.js.map} +1 -1
- package/dist/Incentives/AllowListIncentive.cjs +1 -1
- package/dist/Incentives/AllowListIncentive.cjs.map +1 -1
- package/dist/Incentives/AllowListIncentive.d.ts.map +1 -1
- package/dist/Incentives/AllowListIncentive.js +11 -10
- package/dist/Incentives/AllowListIncentive.js.map +1 -1
- package/dist/Incentives/CGDAIncentive.cjs +1 -1
- package/dist/Incentives/CGDAIncentive.cjs.map +1 -1
- package/dist/Incentives/CGDAIncentive.d.ts +28 -28
- package/dist/Incentives/CGDAIncentive.d.ts.map +1 -1
- package/dist/Incentives/CGDAIncentive.js +12 -11
- package/dist/Incentives/CGDAIncentive.js.map +1 -1
- package/dist/Incentives/ERC1155Incentive.d.ts +28 -28
- package/dist/Incentives/ERC1155Incentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20Incentive.cjs +1 -1
- package/dist/Incentives/ERC20Incentive.cjs.map +1 -1
- package/dist/Incentives/ERC20Incentive.d.ts +34 -31
- package/dist/Incentives/ERC20Incentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20Incentive.js +30 -27
- package/dist/Incentives/ERC20Incentive.js.map +1 -1
- package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts +28 -28
- package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20VariableIncentive.d.ts +28 -28
- package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -1
- package/dist/Incentives/Incentive.cjs +1 -1
- package/dist/Incentives/Incentive.js +2 -2
- package/dist/Incentives/PointsIncentive.cjs +1 -1
- package/dist/Incentives/PointsIncentive.cjs.map +1 -1
- package/dist/Incentives/PointsIncentive.d.ts.map +1 -1
- package/dist/Incentives/PointsIncentive.js +12 -11
- package/dist/Incentives/PointsIncentive.js.map +1 -1
- package/dist/{SimpleDenyList-CGaWjuld.js → SimpleDenyList-BDXpY74P.js} +18 -17
- package/dist/SimpleDenyList-BDXpY74P.js.map +1 -0
- package/dist/{SimpleDenyList-BUR17Tt1.cjs → SimpleDenyList-DNj5qDWM.cjs} +2 -2
- package/dist/SimpleDenyList-DNj5qDWM.cjs.map +1 -0
- package/dist/Validators/SignerValidator.cjs +1 -1
- package/dist/Validators/SignerValidator.cjs.map +1 -1
- package/dist/Validators/SignerValidator.d.ts.map +1 -1
- package/dist/Validators/SignerValidator.js +13 -12
- package/dist/Validators/SignerValidator.js.map +1 -1
- package/dist/Validators/Validator.cjs +1 -1
- package/dist/Validators/Validator.js +1 -1
- package/dist/deployments-DF_6-7hH.cjs +2 -0
- package/dist/deployments-DF_6-7hH.cjs.map +1 -0
- package/dist/deployments-fJsWblwS.js +56 -0
- package/dist/deployments-fJsWblwS.js.map +1 -0
- package/dist/deployments.json +26 -12
- package/dist/{generated-CKt2yCQd.js → generated-CsNyWPKA.js} +458 -443
- package/dist/generated-CsNyWPKA.js.map +1 -0
- package/dist/generated-DHerxf1y.cjs +3 -0
- package/dist/generated-DHerxf1y.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +33 -33
- package/package.json +4 -4
- package/src/Actions/EventAction.test.ts +19 -13
- package/src/Actions/EventAction.ts +16 -35
- package/src/AllowLists/SimpleAllowList.ts +1 -0
- package/src/AllowLists/SimpleDenyList.ts +1 -0
- package/src/BoostCore.test.ts +78 -78
- package/src/BoostCore.ts +19 -13
- package/src/BoostRegistry.ts +10 -10
- package/src/Budgets/ManagedBudget.test.ts +41 -17
- package/src/Budgets/ManagedBudget.ts +1 -11
- package/src/Budgets/VestingBudget.ts +3 -1
- package/src/Deployable/DeployableTargetWithRBAC.test.ts +103 -0
- package/src/Deployable/DeployableTargetWithRBAC.ts +160 -36
- package/src/Incentives/AllowListIncentive.test.ts +7 -7
- package/src/Incentives/AllowListIncentive.ts +1 -0
- package/src/Incentives/CGDAIncentive.ts +1 -0
- package/src/Incentives/ERC1155Incentive.ts +3 -1
- package/src/Incentives/ERC20Incentive.ts +10 -3
- package/src/Incentives/ERC20VariableCriteriaIncentive.ts +1 -0
- package/src/Incentives/ERC20VariableIncentive.ts +1 -0
- package/src/Incentives/PointsIncentive.ts +1 -0
- package/src/Validators/SignerValidator.ts +1 -0
- package/dist/BoostCore-BVZExPPu.js.map +0 -1
- package/dist/BoostCore-D-E-cnGI.cjs +0 -3
- package/dist/BoostCore-D-E-cnGI.cjs.map +0 -1
- package/dist/EventAction-BZt5cjbe.cjs +0 -2
- package/dist/EventAction-BZt5cjbe.cjs.map +0 -1
- package/dist/EventAction-C_-hJXWm.js +0 -1541
- package/dist/EventAction-C_-hJXWm.js.map +0 -1
- package/dist/SimpleDenyList-BUR17Tt1.cjs.map +0 -1
- package/dist/SimpleDenyList-CGaWjuld.js.map +0 -1
- package/dist/deployments-DVXioW2i.cjs +0 -2
- package/dist/deployments-DVXioW2i.cjs.map +0 -1
- package/dist/deployments-oykLv3_Z.js +0 -43
- package/dist/deployments-oykLv3_Z.js.map +0 -1
- package/dist/generated-CKt2yCQd.js.map +0 -1
- package/dist/generated-CyTNlOwM.cjs +0 -3
- package/dist/generated-CyTNlOwM.cjs.map +0 -1
|
@@ -9,14 +9,14 @@ import {
|
|
|
9
9
|
type Fixtures,
|
|
10
10
|
defaultOptions,
|
|
11
11
|
deployFixtures,
|
|
12
|
-
freshBudget,
|
|
13
12
|
freshManagedBudget,
|
|
14
13
|
fundErc20,
|
|
15
14
|
fundErc1155,
|
|
16
15
|
fundManagedBudget,
|
|
17
16
|
} from '@boostxyz/test/helpers';
|
|
18
17
|
import { testAccount } from '@boostxyz/test/viem';
|
|
19
|
-
import { ManagedBudget
|
|
18
|
+
import { ManagedBudget } from './ManagedBudget';
|
|
19
|
+
import { Roles } from '../Deployable/DeployableTargetWithRBAC';
|
|
20
20
|
|
|
21
21
|
let fixtures: Fixtures,
|
|
22
22
|
budget: ManagedBudget,
|
|
@@ -45,51 +45,75 @@ describe('ManagedBudget', () => {
|
|
|
45
45
|
const one = accounts[1].account;
|
|
46
46
|
const two = accounts[2].account;
|
|
47
47
|
await budget.setAuthorized([one, two], [true, true]);
|
|
48
|
-
expect(await budget.hasAllRoles(one,
|
|
49
|
-
expect(await budget.hasAllRoles(one,
|
|
48
|
+
expect(await budget.hasAllRoles(one, Roles.ADMIN)).toBe(false);
|
|
49
|
+
expect(await budget.hasAllRoles(one, Roles.MANAGER)).toBe(
|
|
50
50
|
true,
|
|
51
51
|
);
|
|
52
|
-
expect(await budget.hasAllRoles(two,
|
|
52
|
+
expect(await budget.hasAllRoles(two, Roles.MANAGER)).toBe(
|
|
53
53
|
true,
|
|
54
54
|
);
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
test('can grant
|
|
57
|
+
test('can grant role', async () => {
|
|
58
|
+
const budget = await loadFixture(
|
|
59
|
+
freshManagedBudget(defaultOptions, fixtures),
|
|
60
|
+
);
|
|
61
|
+
const manager = accounts[1].account;
|
|
62
|
+
await budget.grantRoles(manager, Roles.MANAGER);
|
|
63
|
+
expect(await budget.hasAllRoles(manager, Roles.ADMIN)).toBe(false);
|
|
64
|
+
expect(await budget.hasAllRoles(manager, Roles.MANAGER)).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('can revoke role', async () => {
|
|
68
|
+
const budget = await loadFixture(
|
|
69
|
+
freshManagedBudget(defaultOptions, fixtures),
|
|
70
|
+
);
|
|
71
|
+
const manager = accounts[1].account;
|
|
72
|
+
await budget.grantRoles(manager, Roles.MANAGER);
|
|
73
|
+
await budget.grantRoles(manager, Roles.ADMIN);
|
|
74
|
+
await budget.revokeRoles(manager, Roles.MANAGER);
|
|
75
|
+
expect(await budget.hasAllRoles(manager, Roles.MANAGER)).toBe(false);
|
|
76
|
+
expect(await budget.hasAllRoles(manager, Roles.ADMIN)).toBe(true);
|
|
77
|
+
await budget.revokeRoles(manager, Roles.ADMIN);
|
|
78
|
+
expect(await budget.hasAllRoles(manager, Roles.ADMIN)).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('can grant many roles', async () => {
|
|
58
82
|
const budget = await loadFixture(
|
|
59
83
|
freshManagedBudget(defaultOptions, fixtures),
|
|
60
84
|
);
|
|
61
85
|
const admin = accounts[1].account;
|
|
62
86
|
const manager = accounts[2].account;
|
|
63
|
-
await budget.
|
|
87
|
+
await budget.grantManyRoles(
|
|
64
88
|
[admin, manager],
|
|
65
|
-
[
|
|
89
|
+
[Roles.ADMIN, Roles.MANAGER],
|
|
66
90
|
);
|
|
67
|
-
expect(await budget.hasAllRoles(admin,
|
|
91
|
+
expect(await budget.hasAllRoles(admin, Roles.ADMIN)).toBe(
|
|
68
92
|
true,
|
|
69
93
|
);
|
|
70
|
-
expect(await budget.hasAllRoles(manager,
|
|
94
|
+
expect(await budget.hasAllRoles(manager, Roles.MANAGER)).toBe(
|
|
71
95
|
true,
|
|
72
96
|
);
|
|
73
97
|
});
|
|
74
98
|
|
|
75
|
-
test('can revoke roles', async () => {
|
|
99
|
+
test('can revoke many roles', async () => {
|
|
76
100
|
const budget = await loadFixture(
|
|
77
101
|
freshManagedBudget(defaultOptions, fixtures),
|
|
78
102
|
);
|
|
79
103
|
const admin = accounts[1].account;
|
|
80
104
|
const manager = accounts[2].account;
|
|
81
|
-
await budget.
|
|
105
|
+
await budget.grantManyRoles(
|
|
82
106
|
[admin, manager],
|
|
83
|
-
[
|
|
107
|
+
[Roles.ADMIN, Roles.MANAGER],
|
|
84
108
|
);
|
|
85
|
-
await budget.
|
|
109
|
+
await budget.revokeManyRoles(
|
|
86
110
|
[admin, manager],
|
|
87
|
-
[
|
|
111
|
+
[Roles.ADMIN, Roles.MANAGER],
|
|
88
112
|
);
|
|
89
|
-
expect(await budget.hasAllRoles(admin,
|
|
113
|
+
expect(await budget.hasAllRoles(admin, Roles.ADMIN)).toBe(
|
|
90
114
|
false,
|
|
91
115
|
);
|
|
92
|
-
expect(await budget.hasAllRoles(manager,
|
|
116
|
+
expect(await budget.hasAllRoles(manager, Roles.MANAGER)).toBe(
|
|
93
117
|
false,
|
|
94
118
|
);
|
|
95
119
|
});
|
|
@@ -2,26 +2,16 @@ import {
|
|
|
2
2
|
managedBudgetAbi,
|
|
3
3
|
readManagedBudgetAvailable,
|
|
4
4
|
readManagedBudgetDistributed,
|
|
5
|
-
readManagedBudgetHasAllRoles,
|
|
6
|
-
readManagedBudgetHasAnyRole,
|
|
7
|
-
readManagedBudgetIsAuthorized,
|
|
8
5
|
readManagedBudgetOwner,
|
|
9
|
-
readManagedBudgetRolesOf,
|
|
10
6
|
readManagedBudgetTotal,
|
|
11
7
|
simulateManagedBudgetAllocate,
|
|
12
8
|
simulateManagedBudgetClawback,
|
|
13
9
|
simulateManagedBudgetDisburse,
|
|
14
10
|
simulateManagedBudgetDisburseBatch,
|
|
15
|
-
simulateManagedBudgetGrantRoles,
|
|
16
|
-
simulateManagedBudgetRevokeRoles,
|
|
17
|
-
simulateManagedBudgetSetAuthorized,
|
|
18
11
|
writeManagedBudgetAllocate,
|
|
19
12
|
writeManagedBudgetClawback,
|
|
20
13
|
writeManagedBudgetDisburse,
|
|
21
14
|
writeManagedBudgetDisburseBatch,
|
|
22
|
-
writeManagedBudgetGrantRoles,
|
|
23
|
-
writeManagedBudgetRevokeRoles,
|
|
24
|
-
writeManagedBudgetSetAuthorized,
|
|
25
15
|
} from '@boostxyz/evm';
|
|
26
16
|
import { bytecode } from '@boostxyz/evm/artifacts/contracts/budgets/ManagedBudget.sol/ManagedBudget.json';
|
|
27
17
|
import { getAccount } from '@wagmi/core';
|
|
@@ -38,7 +28,6 @@ import type {
|
|
|
38
28
|
DeployableOptions,
|
|
39
29
|
GenericDeployableParams,
|
|
40
30
|
} from '../Deployable/Deployable';
|
|
41
|
-
import { DeployableTarget } from '../Deployable/DeployableTarget';
|
|
42
31
|
import { DeployableTargetWithRBAC } from '../Deployable/DeployableTargetWithRBAC';
|
|
43
32
|
import {
|
|
44
33
|
DeployableUnknownOwnerProvidedError,
|
|
@@ -193,6 +182,7 @@ export class ManagedBudget extends DeployableTargetWithRBAC<
|
|
|
193
182
|
* @type {Record<number, Address>}
|
|
194
183
|
*/
|
|
195
184
|
public static override bases: Record<number, Address> = {
|
|
185
|
+
31337: import.meta.env.VITE_MANAGED_BUDGET_BASE,
|
|
196
186
|
...(ManagedBudgetBases as Record<number, Address>),
|
|
197
187
|
};
|
|
198
188
|
/**
|
|
@@ -129,7 +129,9 @@ export class VestingBudget extends DeployableTargetWithRBAC<
|
|
|
129
129
|
* @static
|
|
130
130
|
* @type {Record<number, Address>}
|
|
131
131
|
*/
|
|
132
|
-
public static override bases: Record<number, Address> = {
|
|
132
|
+
public static override bases: Record<number, Address> = {
|
|
133
|
+
31337: import.meta.env.VITE_VESTING_BUDGET_BASE,
|
|
134
|
+
};
|
|
133
135
|
/**
|
|
134
136
|
* @inheritdoc
|
|
135
137
|
*
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
|
|
2
|
+
import { beforeAll, describe, expect, test } from 'vitest';
|
|
3
|
+
import { accounts } from '@boostxyz/test/accounts';
|
|
4
|
+
import {
|
|
5
|
+
type Fixtures,
|
|
6
|
+
defaultOptions,
|
|
7
|
+
deployFixtures,
|
|
8
|
+
freshManagedBudget,
|
|
9
|
+
} from '@boostxyz/test/helpers';
|
|
10
|
+
import { Roles } from './DeployableTargetWithRBAC';
|
|
11
|
+
|
|
12
|
+
let fixtures: Fixtures;
|
|
13
|
+
|
|
14
|
+
beforeAll(async () => {
|
|
15
|
+
fixtures = await loadFixture(deployFixtures(defaultOptions));
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('RBAC', () => {
|
|
19
|
+
test('can grant roles', async () => {
|
|
20
|
+
const budget = await loadFixture(freshManagedBudget(defaultOptions, fixtures));
|
|
21
|
+
const manager = accounts[0].account;
|
|
22
|
+
expect(await budget.rolesOf(manager)).not.toContain(Roles.MANAGER);
|
|
23
|
+
await budget.grantRoles(manager, Roles.MANAGER);
|
|
24
|
+
expect(await budget.rolesOf(manager)).toContain(Roles.MANAGER);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('can revoke roles', async () => {
|
|
28
|
+
const budget = await loadFixture(freshManagedBudget(defaultOptions, fixtures));
|
|
29
|
+
const admin = accounts[1].account;
|
|
30
|
+
await budget.grantRoles(admin, Roles.ADMIN);
|
|
31
|
+
expect(await budget.rolesOf(admin)).toContain(Roles.ADMIN);
|
|
32
|
+
await budget.revokeRoles(admin, Roles.ADMIN);
|
|
33
|
+
expect(await budget.rolesOf(admin)).not.toContain(Roles.ADMIN);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('can grant many roles', async () => {
|
|
37
|
+
const budget = await loadFixture(freshManagedBudget(defaultOptions, fixtures));
|
|
38
|
+
const admin = accounts[2].account;
|
|
39
|
+
const manager = accounts[3].account;
|
|
40
|
+
await budget.grantManyRoles(
|
|
41
|
+
[admin, manager],
|
|
42
|
+
[Roles.ADMIN, Roles.MANAGER],
|
|
43
|
+
);
|
|
44
|
+
expect(await budget.hasAllRoles(admin, Roles.ADMIN)).toBe(true);
|
|
45
|
+
expect(await budget.hasAllRoles(manager, Roles.MANAGER)).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('can revoke many roles', async () => {
|
|
49
|
+
const budget = await loadFixture(freshManagedBudget(defaultOptions, fixtures));
|
|
50
|
+
const admin = accounts[4].account;
|
|
51
|
+
const manager = accounts[5].account;
|
|
52
|
+
await budget.grantManyRoles(
|
|
53
|
+
[admin, manager],
|
|
54
|
+
[Roles.ADMIN, Roles.MANAGER],
|
|
55
|
+
);
|
|
56
|
+
expect(await budget.hasAllRoles(admin, Roles.ADMIN)).toBe(true);
|
|
57
|
+
expect(await budget.hasAllRoles(manager, Roles.MANAGER)).toBe(true);
|
|
58
|
+
await budget.revokeManyRoles(
|
|
59
|
+
[admin, manager],
|
|
60
|
+
[Roles.ADMIN, Roles.MANAGER],
|
|
61
|
+
);
|
|
62
|
+
expect(await budget.hasAllRoles(admin, Roles.ADMIN)).toBe(false);
|
|
63
|
+
expect(await budget.hasAllRoles(manager, Roles.MANAGER)).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('can check for any role', async () => {
|
|
67
|
+
const budget = await loadFixture(freshManagedBudget(defaultOptions, fixtures));
|
|
68
|
+
const user = accounts[6].account;
|
|
69
|
+
expect(await budget.hasAnyRole(user, Roles.MANAGER | Roles.ADMIN)).toBe(false);
|
|
70
|
+
await budget.grantRoles(user, Roles.MANAGER);
|
|
71
|
+
expect(await budget.hasAnyRole(user, Roles.MANAGER | Roles.ADMIN)).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('can check for all roles', async () => {
|
|
75
|
+
const budget = await loadFixture(freshManagedBudget(defaultOptions, fixtures));
|
|
76
|
+
const user = accounts[7].account;
|
|
77
|
+
await budget.grantRoles(user, Roles.MANAGER);
|
|
78
|
+
expect(await budget.hasAllRoles(user, Roles.MANAGER | Roles.ADMIN)).toBe(false);
|
|
79
|
+
await budget.grantRoles(user, Roles.ADMIN);
|
|
80
|
+
expect(await budget.hasAllRoles(user, Roles.MANAGER | Roles.ADMIN)).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('can get roles of an account', async () => {
|
|
84
|
+
const budget = await loadFixture(freshManagedBudget(defaultOptions, fixtures));
|
|
85
|
+
const user = accounts[8].account;
|
|
86
|
+
await budget.grantRoles(user, Roles.MANAGER | Roles.ADMIN);
|
|
87
|
+
const roles = await budget.rolesOf(user);
|
|
88
|
+
expect(roles).toContain(Roles.MANAGER);
|
|
89
|
+
expect(roles).toContain(Roles.ADMIN);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('can set and check authorization', async () => {
|
|
93
|
+
const budget = await loadFixture(freshManagedBudget(defaultOptions, fixtures));
|
|
94
|
+
const user = accounts[9].account;
|
|
95
|
+
expect(await budget.rolesOf(user)).not.toContain(Roles.MANAGER);
|
|
96
|
+
await budget.setAuthorized([user], [true]);
|
|
97
|
+
expect(await budget.isAuthorized(user)).toBe(true);
|
|
98
|
+
expect(await budget.rolesOf(user)).toContain(Roles.MANAGER);
|
|
99
|
+
await budget.setAuthorized([user], [false]);
|
|
100
|
+
expect(await budget.isAuthorized(user)).toBe(false);
|
|
101
|
+
expect(await budget.rolesOf(user)).not.toContain(Roles.MANAGER);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -4,10 +4,14 @@ import {
|
|
|
4
4
|
readRbacHasAnyRole,
|
|
5
5
|
readRbacIsAuthorized,
|
|
6
6
|
readRbacRolesOf,
|
|
7
|
+
simulateRbacGrantManyRoles,
|
|
7
8
|
simulateRbacGrantRoles,
|
|
9
|
+
simulateRbacRevokeManyRoles,
|
|
8
10
|
simulateRbacRevokeRoles,
|
|
9
11
|
simulateRbacSetAuthorized,
|
|
12
|
+
writeRbacGrantManyRoles,
|
|
10
13
|
writeRbacGrantRoles,
|
|
14
|
+
writeRbacRevokeManyRoles,
|
|
11
15
|
writeRbacRevokeRoles,
|
|
12
16
|
writeRbacSetAuthorized,
|
|
13
17
|
} from '@boostxyz/evm';
|
|
@@ -109,49 +113,49 @@ export class DeployableTargetWithRBAC<
|
|
|
109
113
|
}
|
|
110
114
|
|
|
111
115
|
/**
|
|
112
|
-
* Grant
|
|
116
|
+
* Grant permissions for a user on the rbac.
|
|
113
117
|
*
|
|
114
118
|
* @example
|
|
115
119
|
* ```ts
|
|
116
|
-
* await rbac.grantRoles(
|
|
120
|
+
* await rbac.grantRoles('0xfoo', Roles.MANAGER)
|
|
117
121
|
* ```
|
|
118
122
|
* @public
|
|
119
123
|
* @async
|
|
120
|
-
* @param {Address
|
|
121
|
-
* @param {
|
|
122
|
-
* @param {?WriteParams} [params]
|
|
124
|
+
* @param {Address} address
|
|
125
|
+
* @param {Roles} role
|
|
126
|
+
* @param {?WriteParams<typeof rbacAbi, 'grantRoles'>} [params]
|
|
123
127
|
* @returns {Promise<void>}
|
|
124
128
|
*/
|
|
125
129
|
public async grantRoles(
|
|
126
|
-
|
|
127
|
-
|
|
130
|
+
address: Address,
|
|
131
|
+
role: Roles,
|
|
128
132
|
params?: WriteParams<typeof rbacAbi, 'grantRoles'>,
|
|
129
133
|
) {
|
|
130
|
-
return await this.awaitResult(this.grantRolesRaw(
|
|
134
|
+
return await this.awaitResult(this.grantRolesRaw(address, role, params));
|
|
131
135
|
}
|
|
132
136
|
|
|
133
137
|
/**
|
|
134
|
-
* Grant
|
|
138
|
+
* Grant permissions for a user on the rbac.
|
|
135
139
|
*
|
|
136
140
|
* @example
|
|
137
141
|
* ```ts
|
|
138
|
-
* await rbac.grantRoles(
|
|
139
|
-
*
|
|
142
|
+
* await rbac.grantRoles('0xfoo', Roles.MANAGER)
|
|
143
|
+
* ```
|
|
140
144
|
* @public
|
|
141
145
|
* @async
|
|
142
|
-
* @param {Address
|
|
143
|
-
* @param {
|
|
146
|
+
* @param {Address} address
|
|
147
|
+
* @param {Roles} role
|
|
144
148
|
* @param {?WriteParams} [params]
|
|
145
149
|
* @returns {Promise<{ hash: `0x${string}`; result: void; }>}
|
|
146
150
|
*/
|
|
147
151
|
public async grantRolesRaw(
|
|
148
|
-
|
|
149
|
-
|
|
152
|
+
address: Address,
|
|
153
|
+
role: Roles,
|
|
150
154
|
params?: WriteParams<typeof rbacAbi, 'grantRoles'>,
|
|
151
155
|
) {
|
|
152
156
|
const { request, result } = await simulateRbacGrantRoles(this._config, {
|
|
153
157
|
address: this.assertValidAddress(),
|
|
154
|
-
args: [
|
|
158
|
+
args: [address, role],
|
|
155
159
|
...this.optionallyAttachAccount(),
|
|
156
160
|
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
157
161
|
...(params as any),
|
|
@@ -165,55 +169,173 @@ export class DeployableTargetWithRBAC<
|
|
|
165
169
|
}
|
|
166
170
|
|
|
167
171
|
/**
|
|
168
|
-
* Revoke
|
|
172
|
+
* Revoke permissions for a user on the rbac.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* await rbac.revokeRoles('0xfoo', Roles.MANAGER)
|
|
177
|
+
* ```
|
|
178
|
+
* @public
|
|
179
|
+
* @async
|
|
180
|
+
* @param {Address} address
|
|
181
|
+
* @param {Roles} role
|
|
182
|
+
* @param {?WriteParams} [params]
|
|
183
|
+
* @returns {Promise<void>}
|
|
184
|
+
*/
|
|
185
|
+
public async revokeRoles(
|
|
186
|
+
address: Address,
|
|
187
|
+
role: Roles,
|
|
188
|
+
params?: WriteParams<typeof rbacAbi, 'revokeRoles'>,
|
|
189
|
+
) {
|
|
190
|
+
return await this.awaitResult(this.revokeRolesRaw(address, role, params));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Revoke permissions for a user on the rbac.
|
|
169
195
|
*
|
|
170
196
|
* @example
|
|
171
197
|
* ```ts
|
|
172
|
-
* await rbac.revokeRoles(
|
|
198
|
+
* await rbac.revokeRoles('0xfoo', Roles.MANAGER)
|
|
199
|
+
* ```
|
|
200
|
+
* @public
|
|
201
|
+
* @async
|
|
202
|
+
* @param {Address} address
|
|
203
|
+
* @param {Roles} role
|
|
204
|
+
* @param {?WriteParams} [params]
|
|
205
|
+
* @returns {Promise<{ hash: `0x${string}`; result: void; }>}
|
|
206
|
+
*/
|
|
207
|
+
public async revokeRolesRaw(
|
|
208
|
+
address: Address,
|
|
209
|
+
role: Roles,
|
|
210
|
+
params?: WriteParams<typeof rbacAbi, 'revokeRoles'>,
|
|
211
|
+
) {
|
|
212
|
+
const { request, result } = await simulateRbacRevokeRoles(this._config, {
|
|
213
|
+
address: this.assertValidAddress(),
|
|
214
|
+
args: [address, role],
|
|
215
|
+
...this.optionallyAttachAccount(),
|
|
216
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
217
|
+
...(params as any),
|
|
218
|
+
});
|
|
219
|
+
const hash = await writeRbacRevokeRoles(
|
|
220
|
+
this._config,
|
|
221
|
+
// biome-ignore lint/suspicious/noExplicitAny: negligible low level lack of type intersection
|
|
222
|
+
request as any,
|
|
223
|
+
);
|
|
224
|
+
return { hash, result };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Grant many accounts permissions on the rbac.
|
|
173
229
|
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* await rbac.grantManyRoles(['0xfoo', '0xbar], [Roles.MANAGER, Roles.ADMIN])
|
|
233
|
+
* ```
|
|
174
234
|
* @public
|
|
175
235
|
* @async
|
|
176
236
|
* @param {Address[]} addresses
|
|
177
|
-
* @param {
|
|
237
|
+
* @param {Roles[]} roles
|
|
178
238
|
* @param {?WriteParams} [params]
|
|
179
239
|
* @returns {Promise<void>}
|
|
180
240
|
*/
|
|
181
|
-
public async
|
|
241
|
+
public async grantManyRoles(
|
|
182
242
|
addresses: Address[],
|
|
183
243
|
roles: Roles[],
|
|
184
|
-
params?: WriteParams<typeof rbacAbi, '
|
|
244
|
+
params?: WriteParams<typeof rbacAbi, 'grantManyRoles'>,
|
|
185
245
|
) {
|
|
186
246
|
return await this.awaitResult(
|
|
187
|
-
this.
|
|
247
|
+
this.grantManyRolesRaw(addresses, roles, params),
|
|
188
248
|
);
|
|
189
249
|
}
|
|
190
250
|
|
|
191
251
|
/**
|
|
192
|
-
*
|
|
252
|
+
* Grant many accounts permissions on the rbac.
|
|
193
253
|
*
|
|
194
254
|
* @example
|
|
195
255
|
* ```ts
|
|
196
|
-
* await rbac.
|
|
256
|
+
* await rbac.grantManyRoles(['0xfoo', '0xbar], [Roles.MANAGER, Roles.ADMIN])
|
|
257
|
+
* ```
|
|
197
258
|
* @public
|
|
198
259
|
* @async
|
|
199
260
|
* @param {Address[]} addresses
|
|
200
|
-
* @param {
|
|
261
|
+
* @param {Roles[]} roles
|
|
201
262
|
* @param {?WriteParams} [params]
|
|
202
263
|
* @returns {Promise<{ hash: `0x${string}`; result: void; }>}
|
|
203
264
|
*/
|
|
204
|
-
public async
|
|
265
|
+
public async grantManyRolesRaw(
|
|
205
266
|
addresses: Address[],
|
|
206
267
|
roles: Roles[],
|
|
207
|
-
params?: WriteParams<typeof rbacAbi, '
|
|
268
|
+
params?: WriteParams<typeof rbacAbi, 'grantManyRoles'>,
|
|
208
269
|
) {
|
|
209
|
-
const { request, result } = await
|
|
270
|
+
const { request, result } = await simulateRbacGrantManyRoles(this._config, {
|
|
210
271
|
address: this.assertValidAddress(),
|
|
211
272
|
args: [addresses, roles],
|
|
212
273
|
...this.optionallyAttachAccount(),
|
|
213
274
|
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
214
275
|
...(params as any),
|
|
215
276
|
});
|
|
216
|
-
const hash = await
|
|
277
|
+
const hash = await writeRbacGrantManyRoles(
|
|
278
|
+
this._config,
|
|
279
|
+
// biome-ignore lint/suspicious/noExplicitAny: negligible low level lack of type intersection
|
|
280
|
+
request as any,
|
|
281
|
+
);
|
|
282
|
+
return { hash, result };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Revoke many accounts' permissions on the rbac.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* await rbac.revokeManyRoles(['0xfoo', '0xbar], [Roles.MANAGER, Roles.ADMIN])
|
|
291
|
+
* ```
|
|
292
|
+
* @public
|
|
293
|
+
* @async
|
|
294
|
+
* @param {Address[]} addresses
|
|
295
|
+
* @param {Roles[]} roles
|
|
296
|
+
* @param {?WriteParams} [params]
|
|
297
|
+
* @returns {Promise<void>}
|
|
298
|
+
*/
|
|
299
|
+
public async revokeManyRoles(
|
|
300
|
+
addresses: Address[],
|
|
301
|
+
roles: Roles[],
|
|
302
|
+
params?: WriteParams<typeof rbacAbi, 'revokeManyRoles'>,
|
|
303
|
+
) {
|
|
304
|
+
return await this.awaitResult(
|
|
305
|
+
this.revokeManyRolesRaw(addresses, roles, params),
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Revoke many accounts' permissions on the rbac.
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```ts
|
|
314
|
+
* await rbac.revokeManyRoles(['0xfoo', '0xbar], [Roles.MANAGER, Roles.ADMIN])
|
|
315
|
+
* ```
|
|
316
|
+
* @public
|
|
317
|
+
* @async
|
|
318
|
+
* @param {Address[]} addresses
|
|
319
|
+
* @param {Roles[]} roles
|
|
320
|
+
* @param {?WriteParams} [params]
|
|
321
|
+
* @returns {Promise<{ hash: `0x${string}`; result: void; }>}
|
|
322
|
+
*/
|
|
323
|
+
public async revokeManyRolesRaw(
|
|
324
|
+
addresses: Address[],
|
|
325
|
+
roles: Roles[],
|
|
326
|
+
params?: WriteParams<typeof rbacAbi, 'revokeManyRoles'>,
|
|
327
|
+
) {
|
|
328
|
+
const { request, result } = await simulateRbacRevokeManyRoles(
|
|
329
|
+
this._config,
|
|
330
|
+
{
|
|
331
|
+
address: this.assertValidAddress(),
|
|
332
|
+
args: [addresses, roles],
|
|
333
|
+
...this.optionallyAttachAccount(),
|
|
334
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
335
|
+
...(params as any),
|
|
336
|
+
},
|
|
337
|
+
);
|
|
338
|
+
const hash = await writeRbacRevokeManyRoles(
|
|
217
339
|
this._config,
|
|
218
340
|
// biome-ignore lint/suspicious/noExplicitAny: negligible low level lack of type intersection
|
|
219
341
|
request as any,
|
|
@@ -225,11 +347,12 @@ export class DeployableTargetWithRBAC<
|
|
|
225
347
|
* Return an array of the roles assigned to the given account.
|
|
226
348
|
* @example
|
|
227
349
|
* ```ts
|
|
228
|
-
* (await rbac.rolesOf(0xfoo)).includes(
|
|
350
|
+
* (await rbac.rolesOf(0xfoo)).includes(Roles.ADMIN)
|
|
351
|
+
* ```
|
|
229
352
|
* @public
|
|
230
353
|
* @param {Address} account
|
|
231
354
|
* @param {?ReadParams} [params]
|
|
232
|
-
* @returns {Promise<Array<
|
|
355
|
+
* @returns {Promise<Array<Roles>>}
|
|
233
356
|
*/
|
|
234
357
|
public async rolesOf(
|
|
235
358
|
account: Address,
|
|
@@ -252,10 +375,11 @@ export class DeployableTargetWithRBAC<
|
|
|
252
375
|
*
|
|
253
376
|
* @example
|
|
254
377
|
* ```ts
|
|
255
|
-
* await rbac.hasAnyRole(0xfoo,
|
|
378
|
+
* await rbac.hasAnyRole(0xfoo, Roles.ADMIN | Roles.MANAGER)
|
|
379
|
+
* ```
|
|
256
380
|
* @public
|
|
257
381
|
* @param {Address} account
|
|
258
|
-
* @param {
|
|
382
|
+
* @param {Roles} roles
|
|
259
383
|
* @param {?ReadParams} [params]
|
|
260
384
|
* @returns {Promise<boolean>}
|
|
261
385
|
*/
|
|
@@ -278,11 +402,11 @@ export class DeployableTargetWithRBAC<
|
|
|
278
402
|
*
|
|
279
403
|
* @example
|
|
280
404
|
* ```ts
|
|
281
|
-
* await rbac.hasAllRoles(0xfoo,
|
|
282
|
-
*
|
|
405
|
+
* await rbac.hasAllRoles(0xfoo, Roles.ADMIN | Roles.MANAGER)
|
|
406
|
+
* ```
|
|
283
407
|
* @public
|
|
284
408
|
* @param {Address} account
|
|
285
|
-
* @param {
|
|
409
|
+
* @param {Roles} roles
|
|
286
410
|
* @param {?ReadParams} [params]
|
|
287
411
|
* @returns {Promise<boolean>}
|
|
288
412
|
*/
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
deployFixtures,
|
|
9
9
|
freshBoost,
|
|
10
10
|
} from '@boostxyz/test/helpers';
|
|
11
|
-
import { LIST_MANAGER_ROLE } from '../AllowLists/SimpleAllowList';
|
|
12
11
|
import { PointsIncentive } from './PointsIncentive';
|
|
12
|
+
import { Roles } from '../Deployable/DeployableTargetWithRBAC';
|
|
13
13
|
|
|
14
14
|
let fixtures: Fixtures;
|
|
15
15
|
|
|
@@ -57,9 +57,9 @@ describe('AllowListIncentive', () => {
|
|
|
57
57
|
const boost = await freshBoost(fixtures, {
|
|
58
58
|
incentives: [allowListIncentive],
|
|
59
59
|
});
|
|
60
|
-
await allowList.
|
|
61
|
-
allowListIncentive.assertValidAddress(),
|
|
62
|
-
|
|
60
|
+
await allowList.grantManyRoles(
|
|
61
|
+
[allowListIncentive.assertValidAddress()],
|
|
62
|
+
[Roles.MANAGER],
|
|
63
63
|
);
|
|
64
64
|
|
|
65
65
|
const claimant = trustedSigner.account;
|
|
@@ -103,9 +103,9 @@ describe('AllowListIncentive', () => {
|
|
|
103
103
|
const boost = await freshBoost(fixtures, {
|
|
104
104
|
incentives: [allowListIncentive],
|
|
105
105
|
});
|
|
106
|
-
await allowList.
|
|
107
|
-
allowListIncentive.assertValidAddress(),
|
|
108
|
-
|
|
106
|
+
await allowList.grantManyRoles(
|
|
107
|
+
[allowListIncentive.assertValidAddress()],
|
|
108
|
+
[Roles.MANAGER],
|
|
109
109
|
);
|
|
110
110
|
const incentiveQuantity = 1;
|
|
111
111
|
const claimant = trustedSigner.account;
|
|
@@ -97,6 +97,7 @@ export class AllowListIncentive extends DeployableTarget<
|
|
|
97
97
|
* @type {Record<number, Address>}
|
|
98
98
|
*/
|
|
99
99
|
public static override bases: Record<number, Address> = {
|
|
100
|
+
31337: import.meta.env.VITE_ALLOWLIST_INCENTIVE_BASE,
|
|
100
101
|
...(AllowListIncentiveBases as Record<number, Address>),
|
|
101
102
|
};
|
|
102
103
|
/**
|
|
@@ -155,6 +155,7 @@ export class CGDAIncentive extends DeployableTarget<
|
|
|
155
155
|
* @type {Record<number, Address>}
|
|
156
156
|
*/
|
|
157
157
|
public static override bases: Record<number, Address> = {
|
|
158
|
+
31337: import.meta.env.VITE_CGDA_INCENTIVE_BASE,
|
|
158
159
|
...(CGDAIncentiveBases as Record<number, Address>),
|
|
159
160
|
};
|
|
160
161
|
/**
|
|
@@ -129,7 +129,9 @@ export class ERC1155Incentive extends DeployableTarget<
|
|
|
129
129
|
* @static
|
|
130
130
|
* @type {Record<number, Address>}
|
|
131
131
|
*/
|
|
132
|
-
public static override bases: Record<number, Address> = {
|
|
132
|
+
public static override bases: Record<number, Address> = {
|
|
133
|
+
31337: import.meta.env.VITE_ERC1155_INCENTIVE_BASE,
|
|
134
|
+
};
|
|
133
135
|
/**
|
|
134
136
|
* @inheritdoc
|
|
135
137
|
*
|