@boostxyz/sdk 0.0.0-alpha.9 → 1.1.0-alpha.22
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 +7 -7
- package/dist/Actions/ContractAction.d.ts +11 -11
- package/dist/Actions/ContractAction.d.ts.map +1 -1
- package/dist/Actions/ERC721MintAction.d.ts +14 -14
- package/dist/Actions/ERC721MintAction.d.ts.map +1 -1
- package/dist/Actions/EventAction.cjs +1 -1
- package/dist/Actions/EventAction.cjs.map +1 -1
- package/dist/Actions/EventAction.d.ts +171 -41
- package/dist/Actions/EventAction.d.ts.map +1 -1
- package/dist/Actions/EventAction.js +15 -392
- package/dist/Actions/EventAction.js.map +1 -1
- package/dist/AllowLists/AllowList.cjs +1 -1
- package/dist/AllowLists/AllowList.cjs.map +1 -1
- package/dist/AllowLists/AllowList.d.ts +6 -4
- package/dist/AllowLists/AllowList.d.ts.map +1 -1
- package/dist/AllowLists/AllowList.js +45 -23
- package/dist/AllowLists/AllowList.js.map +1 -1
- package/dist/AllowLists/OpenAllowList.d.ts +423 -0
- package/dist/AllowLists/OpenAllowList.d.ts.map +1 -0
- package/dist/AllowLists/SimpleAllowList.cjs +1 -1
- package/dist/AllowLists/SimpleAllowList.cjs.map +1 -1
- package/dist/AllowLists/SimpleAllowList.d.ts +92 -37
- package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -1
- package/dist/AllowLists/SimpleAllowList.js +55 -71
- package/dist/AllowLists/SimpleAllowList.js.map +1 -1
- package/dist/AllowLists/SimpleDenyList.cjs +1 -1
- package/dist/AllowLists/SimpleDenyList.cjs.map +1 -1
- package/dist/AllowLists/SimpleDenyList.d.ts +203 -11
- package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -1
- package/dist/AllowLists/SimpleDenyList.js +11 -112
- package/dist/AllowLists/SimpleDenyList.js.map +1 -1
- package/dist/Auth/PassthroughAuth.cjs +1 -1
- package/dist/Auth/PassthroughAuth.js +1 -1
- package/dist/Boost.cjs +1 -1
- package/dist/Boost.cjs.map +1 -1
- package/dist/Boost.d.ts +20 -21
- package/dist/Boost.d.ts.map +1 -1
- package/dist/Boost.js +43 -57
- package/dist/Boost.js.map +1 -1
- package/dist/BoostCore-BVZExPPu.js +1462 -0
- package/dist/BoostCore-BVZExPPu.js.map +1 -0
- package/dist/BoostCore-D-E-cnGI.cjs +3 -0
- package/dist/BoostCore-D-E-cnGI.cjs.map +1 -0
- package/dist/BoostCore.cjs +1 -2
- package/dist/BoostCore.cjs.map +1 -1
- package/dist/BoostCore.d.ts +748 -77
- package/dist/BoostCore.d.ts.map +1 -1
- package/dist/BoostCore.js +29 -1150
- package/dist/BoostCore.js.map +1 -1
- package/dist/BoostRegistry.cjs +1 -1
- package/dist/BoostRegistry.cjs.map +1 -1
- package/dist/BoostRegistry.d.ts +80 -25
- package/dist/BoostRegistry.d.ts.map +1 -1
- package/dist/BoostRegistry.js +165 -83
- package/dist/BoostRegistry.js.map +1 -1
- package/dist/Budgets/Budget.cjs +1 -1
- package/dist/Budgets/Budget.cjs.map +1 -1
- package/dist/Budgets/Budget.d.ts.map +1 -1
- package/dist/Budgets/Budget.js +2 -2
- package/dist/Budgets/Budget.js.map +1 -1
- package/dist/Budgets/ManagedBudget.cjs +1 -1
- package/dist/Budgets/ManagedBudget.cjs.map +1 -1
- package/dist/Budgets/ManagedBudget.d.ts +75 -193
- package/dist/Budgets/ManagedBudget.d.ts.map +1 -1
- package/dist/Budgets/ManagedBudget.js +80 -298
- package/dist/Budgets/ManagedBudget.js.map +1 -1
- package/dist/Budgets/VestingBudget.d.ts +223 -89
- package/dist/Budgets/VestingBudget.d.ts.map +1 -1
- package/dist/Deployable/Contract.cjs +1 -1
- package/dist/Deployable/Contract.cjs.map +1 -1
- package/dist/Deployable/Contract.d.ts +4 -5
- package/dist/Deployable/Contract.d.ts.map +1 -1
- package/dist/Deployable/Contract.js +5 -7
- package/dist/Deployable/Contract.js.map +1 -1
- package/dist/Deployable/Deployable.cjs.map +1 -1
- package/dist/Deployable/Deployable.d.ts +1 -1
- package/dist/Deployable/Deployable.d.ts.map +1 -1
- package/dist/Deployable/Deployable.js +3 -5
- package/dist/Deployable/Deployable.js.map +1 -1
- package/dist/Deployable/DeployableTarget.cjs +1 -1
- package/dist/Deployable/DeployableTarget.cjs.map +1 -1
- package/dist/Deployable/DeployableTarget.d.ts +13 -13
- package/dist/Deployable/DeployableTarget.d.ts.map +1 -1
- package/dist/Deployable/DeployableTarget.js +28 -25
- package/dist/Deployable/DeployableTarget.js.map +1 -1
- package/dist/Deployable/DeployableTargetWithRBAC.cjs +2 -0
- package/dist/Deployable/DeployableTargetWithRBAC.cjs.map +1 -0
- package/dist/Deployable/DeployableTargetWithRBAC.d.ts +179 -0
- package/dist/Deployable/DeployableTargetWithRBAC.d.ts.map +1 -0
- package/dist/Deployable/DeployableTargetWithRBAC.js +222 -0
- package/dist/Deployable/DeployableTargetWithRBAC.js.map +1 -0
- package/dist/EventAction-BZt5cjbe.cjs +2 -0
- package/dist/EventAction-BZt5cjbe.cjs.map +1 -0
- package/dist/EventAction-C_-hJXWm.js +1541 -0
- package/dist/EventAction-C_-hJXWm.js.map +1 -0
- package/dist/Incentive-BhHaK3PZ.cjs +2 -0
- package/dist/Incentive-BhHaK3PZ.cjs.map +1 -0
- package/dist/Incentive-Cqg1w6wD.js +312 -0
- package/dist/Incentive-Cqg1w6wD.js.map +1 -0
- package/dist/Incentives/AllowListIncentive.cjs +1 -1
- package/dist/Incentives/AllowListIncentive.cjs.map +1 -1
- package/dist/Incentives/AllowListIncentive.d.ts +38 -16
- package/dist/Incentives/AllowListIncentive.d.ts.map +1 -1
- package/dist/Incentives/AllowListIncentive.js +42 -29
- 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 +234 -21
- package/dist/Incentives/CGDAIncentive.d.ts.map +1 -1
- package/dist/Incentives/CGDAIncentive.js +45 -32
- package/dist/Incentives/CGDAIncentive.js.map +1 -1
- package/dist/Incentives/ERC1155Incentive.d.ts +224 -37
- 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 +230 -29
- package/dist/Incentives/ERC20Incentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20Incentive.js +56 -43
- package/dist/Incentives/ERC20Incentive.js.map +1 -1
- package/dist/{Budgets/SimpleBudget.d.ts → Incentives/ERC20VariableCriteriaIncentive.d.ts} +335 -440
- package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts.map +1 -0
- package/dist/Incentives/ERC20VariableIncentive.d.ts +231 -29
- package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -1
- package/dist/Incentives/Incentive.cjs +1 -1
- package/dist/Incentives/Incentive.cjs.map +1 -1
- package/dist/Incentives/Incentive.d.ts +4 -4
- package/dist/Incentives/Incentive.d.ts.map +1 -1
- package/dist/Incentives/Incentive.js +16 -296
- package/dist/Incentives/Incentive.js.map +1 -1
- package/dist/Incentives/PointsIncentive.cjs +1 -1
- package/dist/Incentives/PointsIncentive.cjs.map +1 -1
- package/dist/Incentives/PointsIncentive.d.ts +40 -18
- package/dist/Incentives/PointsIncentive.d.ts.map +1 -1
- package/dist/Incentives/PointsIncentive.js +37 -24
- package/dist/Incentives/PointsIncentive.js.map +1 -1
- package/dist/SimpleDenyList-BUR17Tt1.cjs +2 -0
- package/dist/SimpleDenyList-BUR17Tt1.cjs.map +1 -0
- package/dist/SimpleDenyList-CGaWjuld.js +132 -0
- package/dist/SimpleDenyList-CGaWjuld.js.map +1 -0
- package/dist/Validators/SignerValidator.cjs +1 -1
- package/dist/Validators/SignerValidator.cjs.map +1 -1
- package/dist/Validators/SignerValidator.d.ts +16 -16
- package/dist/Validators/SignerValidator.d.ts.map +1 -1
- package/dist/Validators/SignerValidator.js +30 -27
- package/dist/Validators/SignerValidator.js.map +1 -1
- package/dist/Validators/Validator.cjs +1 -1
- package/dist/Validators/Validator.cjs.map +1 -1
- package/dist/Validators/Validator.d.ts +1 -1
- package/dist/Validators/Validator.js +2 -2
- package/dist/Validators/Validator.js.map +1 -1
- package/dist/claiming.cjs.map +1 -1
- package/dist/claiming.d.ts +1 -1
- package/dist/claiming.js.map +1 -1
- package/dist/componentInterfaces-BBCFkrZv.js +14 -0
- package/dist/componentInterfaces-BBCFkrZv.js.map +1 -0
- package/dist/componentInterfaces-DRI_dQ-P.cjs +2 -0
- package/dist/componentInterfaces-DRI_dQ-P.cjs.map +1 -0
- package/dist/deployments-DVXioW2i.cjs +2 -0
- package/dist/deployments-DVXioW2i.cjs.map +1 -0
- package/dist/deployments-oykLv3_Z.js +43 -0
- package/dist/deployments-oykLv3_Z.js.map +1 -0
- package/dist/deployments.json +44 -0
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +256 -20
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +183 -26
- package/dist/errors.js.map +1 -1
- package/dist/{generated-57_Kffpz.js → generated-CKt2yCQd.js} +3613 -1869
- package/dist/generated-CKt2yCQd.js.map +1 -0
- package/dist/generated-CyTNlOwM.cjs +3 -0
- package/dist/generated-CyTNlOwM.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +142 -108
- package/dist/index.js.map +1 -1
- package/dist/transfers.cjs.map +1 -1
- package/dist/transfers.d.ts +1 -1
- package/dist/transfers.js.map +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +26 -12
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +38 -23
- package/dist/utils.js.map +1 -1
- package/package.json +20 -10
- package/src/Actions/Action.test.ts +14 -13
- package/src/Actions/ContractAction.test.ts +10 -10
- package/src/Actions/ContractAction.ts +11 -12
- package/src/Actions/ERC721MintAction.test.ts +6 -6
- package/src/Actions/ERC721MintAction.ts +14 -15
- package/src/Actions/EventAction.test.ts +729 -109
- package/src/Actions/EventAction.ts +542 -84
- package/src/AllowLists/AllowList.test.ts +7 -7
- package/src/AllowLists/AllowList.ts +5 -3
- package/src/AllowLists/OpenAllowList.test.ts +40 -0
- package/src/AllowLists/OpenAllowList.ts +45 -0
- package/src/AllowLists/SimpleAllowList.test.ts +4 -4
- package/src/AllowLists/SimpleAllowList.ts +39 -61
- package/src/AllowLists/SimpleDenyList.test.ts +4 -4
- package/src/AllowLists/SimpleDenyList.ts +40 -17
- package/src/Auth/PassthroughAuth.test.ts +1 -1
- package/src/Boost.ts +21 -24
- package/src/BoostCore.test.ts +323 -268
- package/src/BoostCore.ts +396 -219
- package/src/BoostRegistry.test.ts +53 -0
- package/src/BoostRegistry.ts +161 -40
- package/src/Budgets/Budget.test.ts +2 -2
- package/src/Budgets/Budget.ts +1 -2
- package/src/Budgets/ManagedBudget.test.ts +82 -19
- package/src/Budgets/ManagedBudget.ts +48 -310
- package/src/Budgets/VestingBudget.test.ts +7 -7
- package/src/Budgets/VestingBudget.ts +34 -106
- package/src/Deployable/Contract.ts +4 -5
- package/src/Deployable/Deployable.ts +1 -1
- package/src/Deployable/DeployableTarget.ts +30 -19
- package/src/Deployable/DeployableTargetWithRBAC.ts +323 -0
- package/src/Incentives/AllowListIncentive.test.ts +5 -5
- package/src/Incentives/AllowListIncentive.ts +29 -15
- package/src/Incentives/CGDAIncentive.test.ts +9 -6
- package/src/Incentives/CGDAIncentive.ts +38 -18
- package/src/Incentives/ERC1155Incentive.test.ts +3 -3
- package/src/Incentives/ERC1155Incentive.ts +28 -29
- package/src/Incentives/ERC20Incentive.test.ts +9 -6
- package/src/Incentives/ERC20Incentive.ts +46 -26
- package/src/Incentives/ERC20VariableCriteriaIncentive.test.ts +184 -0
- package/src/Incentives/ERC20VariableCriteriaIncentive.ts +324 -0
- package/src/Incentives/ERC20VariableIncentive.test.ts +8 -11
- package/src/Incentives/ERC20VariableIncentive.ts +49 -26
- package/src/Incentives/Incentive.test.ts +4 -1
- package/src/Incentives/Incentive.ts +7 -6
- package/src/Incentives/PointsIncentive.test.ts +24 -25
- package/src/Incentives/PointsIncentive.ts +31 -17
- package/src/Validators/SignerValidator.test.ts +6 -6
- package/src/Validators/SignerValidator.ts +19 -17
- package/src/Validators/Validator.test.ts +2 -2
- package/src/Validators/Validator.ts +1 -1
- package/src/claiming.ts +1 -1
- package/src/errors.ts +345 -21
- package/src/index.test.ts +118 -36
- package/src/index.ts +5 -0
- package/src/transfers.ts +1 -1
- package/src/utils.test.ts +2 -2
- package/src/utils.ts +61 -12
- package/dist/Budgets/SimpleBudget.d.ts.map +0 -1
- package/dist/componentInterfaces-CKCBwG16.cjs +0 -2
- package/dist/componentInterfaces-CKCBwG16.cjs.map +0 -1
- package/dist/componentInterfaces-DYkaxBda.js +0 -13
- package/dist/componentInterfaces-DYkaxBda.js.map +0 -1
- package/dist/generated-57_Kffpz.js.map +0 -1
- package/dist/generated-wKBNvm48.cjs +0 -3
- package/dist/generated-wKBNvm48.cjs.map +0 -1
- package/src/Budgets/SimpleBudget.test.ts +0 -152
- package/src/Budgets/SimpleBudget.ts +0 -564
|
@@ -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} [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} [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} [params]
|
|
123
|
+
* @returns {Promise<void>}
|
|
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} [params]
|
|
145
|
+
* @returns {Promise<{ hash: `0x${string}`; result: void; }>}
|
|
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} [params]
|
|
179
|
+
* @returns {Promise<void>}
|
|
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} [params]
|
|
202
|
+
* @returns {Promise<{ hash: `0x${string}`; result: void; }>}
|
|
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} [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} [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} [params]
|
|
287
|
+
* @returns {Promise<boolean>}
|
|
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} [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
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
|
|
2
2
|
import { isAddress, pad, parseEther, zeroAddress } from 'viem';
|
|
3
3
|
import { beforeAll, describe, expect, test } from 'vitest';
|
|
4
|
-
import { accounts } from '
|
|
4
|
+
import { accounts } from '@boostxyz/test/accounts';
|
|
5
5
|
import {
|
|
6
6
|
type Fixtures,
|
|
7
7
|
defaultOptions,
|
|
8
8
|
deployFixtures,
|
|
9
9
|
freshBoost,
|
|
10
|
-
} from '
|
|
10
|
+
} from '@boostxyz/test/helpers';
|
|
11
11
|
import { LIST_MANAGER_ROLE } from '../AllowLists/SimpleAllowList';
|
|
12
12
|
import { PointsIncentive } from './PointsIncentive';
|
|
13
13
|
|
|
@@ -15,9 +15,9 @@ let fixtures: Fixtures;
|
|
|
15
15
|
|
|
16
16
|
function freshAllowList(fixtures: Fixtures) {
|
|
17
17
|
return function freshAllowList() {
|
|
18
|
-
return fixtures.registry.
|
|
18
|
+
return fixtures.registry.initialize(
|
|
19
19
|
crypto.randomUUID(),
|
|
20
|
-
|
|
20
|
+
fixtures.core.SimpleAllowList({
|
|
21
21
|
owner: defaultOptions.account.address,
|
|
22
22
|
allowed: [],
|
|
23
23
|
}),
|
|
@@ -27,7 +27,7 @@ function freshAllowList(fixtures: Fixtures) {
|
|
|
27
27
|
|
|
28
28
|
describe('AllowListIncentive', () => {
|
|
29
29
|
beforeAll(async () => {
|
|
30
|
-
fixtures = await loadFixture(deployFixtures);
|
|
30
|
+
fixtures = await loadFixture(deployFixtures(defaultOptions));
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
test('can successfully be deployed', async () => {
|
|
@@ -16,7 +16,9 @@ import {
|
|
|
16
16
|
type ContractEventName,
|
|
17
17
|
type Hex,
|
|
18
18
|
encodeAbiParameters,
|
|
19
|
+
zeroHash,
|
|
19
20
|
} from 'viem';
|
|
21
|
+
import { AllowListIncentive as AllowListIncentiveBases } from '../../dist/deployments.json';
|
|
20
22
|
import { SimpleAllowList } from '../AllowLists/AllowList';
|
|
21
23
|
import type {
|
|
22
24
|
DeployableOptions,
|
|
@@ -92,10 +94,11 @@ export class AllowListIncentive extends DeployableTarget<
|
|
|
92
94
|
*
|
|
93
95
|
* @public
|
|
94
96
|
* @static
|
|
95
|
-
* @type {Address}
|
|
97
|
+
* @type {Record<number, Address>}
|
|
96
98
|
*/
|
|
97
|
-
public static override
|
|
98
|
-
|
|
99
|
+
public static override bases: Record<number, Address> = {
|
|
100
|
+
...(AllowListIncentiveBases as Record<number, Address>),
|
|
101
|
+
};
|
|
99
102
|
/**
|
|
100
103
|
* @inheritdoc
|
|
101
104
|
*
|
|
@@ -110,8 +113,8 @@ export class AllowListIncentive extends DeployableTarget<
|
|
|
110
113
|
*
|
|
111
114
|
* @public
|
|
112
115
|
* @async
|
|
113
|
-
* @param {?ReadParams
|
|
114
|
-
* @returns {
|
|
116
|
+
* @param {?ReadParams} [params]
|
|
117
|
+
* @returns {Promise<Address>}
|
|
115
118
|
*/
|
|
116
119
|
public async owner(
|
|
117
120
|
params?: ReadParams<typeof allowListIncentiveAbi, 'owner'>,
|
|
@@ -129,7 +132,7 @@ export class AllowListIncentive extends DeployableTarget<
|
|
|
129
132
|
*
|
|
130
133
|
* @public
|
|
131
134
|
* @async
|
|
132
|
-
* @param {?ReadParams
|
|
135
|
+
* @param {?ReadParams} [params]
|
|
133
136
|
* @returns {Promise<bigint>}
|
|
134
137
|
*/
|
|
135
138
|
public async claims(
|
|
@@ -148,7 +151,7 @@ export class AllowListIncentive extends DeployableTarget<
|
|
|
148
151
|
*
|
|
149
152
|
* @public
|
|
150
153
|
* @async
|
|
151
|
-
* @param {?ReadParams
|
|
154
|
+
* @param {?ReadParams} [params]
|
|
152
155
|
* @returns {Promise<bigint>}
|
|
153
156
|
*/
|
|
154
157
|
public async reward(
|
|
@@ -168,7 +171,7 @@ export class AllowListIncentive extends DeployableTarget<
|
|
|
168
171
|
* @public
|
|
169
172
|
* @async
|
|
170
173
|
* @param {Address} address
|
|
171
|
-
* @param {?ReadParams
|
|
174
|
+
* @param {?ReadParams} [params]
|
|
172
175
|
* @returns {Promise<boolean>}
|
|
173
176
|
*/
|
|
174
177
|
public async claimed(
|
|
@@ -188,7 +191,7 @@ export class AllowListIncentive extends DeployableTarget<
|
|
|
188
191
|
*
|
|
189
192
|
* @public
|
|
190
193
|
* @async
|
|
191
|
-
* @param {?ReadParams
|
|
194
|
+
* @param {?ReadParams} [params]
|
|
192
195
|
* @returns {Promise<SimpleAllowList>}
|
|
193
196
|
*/
|
|
194
197
|
public async allowList(
|
|
@@ -210,8 +213,8 @@ export class AllowListIncentive extends DeployableTarget<
|
|
|
210
213
|
*
|
|
211
214
|
* @public
|
|
212
215
|
* @async
|
|
213
|
-
* @param {?ReadParams
|
|
214
|
-
* @returns {
|
|
216
|
+
* @param {?ReadParams} [params]
|
|
217
|
+
* @returns {Promise<bigint>}
|
|
215
218
|
*/
|
|
216
219
|
public async limit(
|
|
217
220
|
params?: ReadParams<typeof allowListIncentiveAbi, 'limit'>,
|
|
@@ -229,7 +232,7 @@ export class AllowListIncentive extends DeployableTarget<
|
|
|
229
232
|
* @public
|
|
230
233
|
* @async
|
|
231
234
|
* @param {Pick<ClaimPayload, 'target'>} payload
|
|
232
|
-
* @param {?WriteParams
|
|
235
|
+
* @param {?WriteParams} [params]
|
|
233
236
|
* @returns {Promise<true>} - return true if successful, otherwise revert
|
|
234
237
|
*/
|
|
235
238
|
protected async claim(
|
|
@@ -245,8 +248,8 @@ export class AllowListIncentive extends DeployableTarget<
|
|
|
245
248
|
* @public
|
|
246
249
|
* @async
|
|
247
250
|
* @param {Pick<ClaimPayload, 'target'>} payload
|
|
248
|
-
* @param {?WriteParams
|
|
249
|
-
* @returns {Promise<
|
|
251
|
+
* @param {?WriteParams} [params]
|
|
252
|
+
* @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - return true if successful, otherwise revert
|
|
250
253
|
*/
|
|
251
254
|
protected async claimRaw(
|
|
252
255
|
payload: Pick<ClaimPayload, 'target'>,
|
|
@@ -272,7 +275,7 @@ export class AllowListIncentive extends DeployableTarget<
|
|
|
272
275
|
* @public
|
|
273
276
|
* @async
|
|
274
277
|
* @param {Pick<ClaimPayload, 'target'>} payload
|
|
275
|
-
* @param {?ReadParams
|
|
278
|
+
* @param {?ReadParams} [params]
|
|
276
279
|
* @returns {Promise<boolean>} - True if the incentive is claimable based on the data payload
|
|
277
280
|
*/
|
|
278
281
|
public async isClaimable(
|
|
@@ -310,6 +313,17 @@ export class AllowListIncentive extends DeployableTarget<
|
|
|
310
313
|
...this.optionallyAttachAccount(options.account),
|
|
311
314
|
};
|
|
312
315
|
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Builds the claim data for the AllowListIncentive.
|
|
319
|
+
*
|
|
320
|
+
* @public
|
|
321
|
+
* @returns {Hash} A `zeroHash`, as AllowListIncentive doesn't require specific claim data.
|
|
322
|
+
* @description This function returns `zeroHash` because AllowListIncentive doesn't use any specific claim data.
|
|
323
|
+
*/
|
|
324
|
+
public buildClaimData() {
|
|
325
|
+
return zeroHash;
|
|
326
|
+
}
|
|
313
327
|
}
|
|
314
328
|
|
|
315
329
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { readMockErc20BalanceOf } from '@boostxyz/evm';
|
|
2
2
|
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
|
|
3
|
-
import { isAddress, pad, parseEther } from 'viem';
|
|
3
|
+
import { isAddress, pad, parseEther, zeroAddress } from 'viem';
|
|
4
4
|
import { beforeAll, beforeEach, describe, expect, test } from 'vitest';
|
|
5
|
-
import { accounts } from '
|
|
5
|
+
import { accounts } from '@boostxyz/test/accounts';
|
|
6
6
|
import {
|
|
7
7
|
type BudgetFixtures,
|
|
8
8
|
type Fixtures,
|
|
@@ -10,14 +10,14 @@ import {
|
|
|
10
10
|
deployFixtures,
|
|
11
11
|
freshBoost,
|
|
12
12
|
fundBudget,
|
|
13
|
-
} from '
|
|
13
|
+
} from '@boostxyz/test/helpers';
|
|
14
14
|
import { CGDAIncentive } from './CGDAIncentive';
|
|
15
15
|
|
|
16
16
|
let fixtures: Fixtures, budgets: BudgetFixtures;
|
|
17
17
|
|
|
18
18
|
describe('CGDAIncentive', () => {
|
|
19
19
|
beforeAll(async () => {
|
|
20
|
-
fixtures = await loadFixture(deployFixtures);
|
|
20
|
+
fixtures = await loadFixture(deployFixtures(defaultOptions));
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
beforeEach(async () => {
|
|
@@ -31,6 +31,7 @@ describe('CGDAIncentive', () => {
|
|
|
31
31
|
totalBudget: 10n,
|
|
32
32
|
rewardBoost: 1n,
|
|
33
33
|
rewardDecay: 1n,
|
|
34
|
+
manager: budgets.budget.address || zeroAddress
|
|
34
35
|
});
|
|
35
36
|
await action.deploy();
|
|
36
37
|
expect(isAddress(action.assertValidAddress())).toBe(true);
|
|
@@ -41,12 +42,13 @@ describe('CGDAIncentive', () => {
|
|
|
41
42
|
const referrer = accounts.at(1)!.account!;
|
|
42
43
|
// biome-ignore lint/style/noNonNullAssertion: we know this is defined
|
|
43
44
|
const trustedSigner = accounts.at(0)!;
|
|
44
|
-
const erc20Incentive =
|
|
45
|
+
const erc20Incentive = fixtures.core.CGDAIncentive({
|
|
45
46
|
asset: budgets.erc20.assertValidAddress(),
|
|
46
47
|
initialReward: 1n,
|
|
47
48
|
totalBudget: 10n,
|
|
48
49
|
rewardBoost: 1n,
|
|
49
50
|
rewardDecay: 1n,
|
|
51
|
+
manager: budgets.budget.assertValidAddress(),
|
|
50
52
|
});
|
|
51
53
|
const boost = await freshBoost(fixtures, {
|
|
52
54
|
budget: budgets.budget,
|
|
@@ -86,12 +88,13 @@ describe('CGDAIncentive', () => {
|
|
|
86
88
|
const referrer = accounts.at(1)!.account!;
|
|
87
89
|
// biome-ignore lint/style/noNonNullAssertion: we know this is defined
|
|
88
90
|
const trustedSigner = accounts.at(0)!;
|
|
89
|
-
const erc20Incentive =
|
|
91
|
+
const erc20Incentive = fixtures.core.CGDAIncentive({
|
|
90
92
|
asset: budgets.erc20.assertValidAddress(),
|
|
91
93
|
initialReward: 1n,
|
|
92
94
|
totalBudget: 10n,
|
|
93
95
|
rewardBoost: 1n,
|
|
94
96
|
rewardDecay: 1n,
|
|
97
|
+
manager: budgets.budget.address || zeroAddress
|
|
95
98
|
});
|
|
96
99
|
const boost = await freshBoost(fixtures, {
|
|
97
100
|
budget: budgets.budget,
|