@boostxyz/sdk 0.0.0-alpha.2 → 0.0.0-alpha.21
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 +2 -1
- package/dist/Actions/Action.cjs.map +1 -0
- package/dist/Actions/Action.d.ts +1 -1
- package/dist/Actions/Action.d.ts.map +1 -1
- package/dist/Actions/Action.js +14 -12
- package/dist/Actions/Action.js.map +1 -0
- package/dist/Actions/ContractAction.d.ts +57 -14
- package/dist/Actions/ContractAction.d.ts.map +1 -1
- package/dist/Actions/ERC721MintAction.d.ts +50 -23
- package/dist/Actions/ERC721MintAction.d.ts.map +1 -1
- package/dist/Actions/EventAction.cjs +2 -1
- package/dist/Actions/EventAction.cjs.map +1 -0
- package/dist/Actions/EventAction.d.ts +405 -36
- package/dist/Actions/EventAction.d.ts.map +1 -1
- package/dist/Actions/EventAction.js +15 -209
- package/dist/Actions/EventAction.js.map +1 -0
- package/dist/AllowLists/AllowList.cjs +2 -1
- package/dist/AllowLists/AllowList.cjs.map +1 -0
- package/dist/AllowLists/AllowList.d.ts +6 -5
- package/dist/AllowLists/AllowList.d.ts.map +1 -1
- package/dist/AllowLists/AllowList.js +46 -22
- package/dist/AllowLists/AllowList.js.map +1 -0
- package/dist/AllowLists/OpenAllowList.d.ts +423 -0
- package/dist/AllowLists/OpenAllowList.d.ts.map +1 -0
- package/dist/AllowLists/SimpleAllowList.cjs +2 -1
- package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
- package/dist/AllowLists/SimpleAllowList.d.ts +124 -40
- package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -1
- package/dist/AllowLists/SimpleAllowList.js +76 -76
- package/dist/AllowLists/SimpleAllowList.js.map +1 -0
- package/dist/AllowLists/SimpleDenyList.cjs +2 -1
- package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
- package/dist/AllowLists/SimpleDenyList.d.ts +234 -13
- package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -1
- package/dist/AllowLists/SimpleDenyList.js +12 -200
- package/dist/AllowLists/SimpleDenyList.js.map +1 -0
- package/dist/Auth/Auth.cjs +1 -0
- package/dist/Auth/Auth.cjs.map +1 -0
- package/dist/Auth/Auth.js +1 -0
- package/dist/Auth/Auth.js.map +1 -0
- package/dist/Auth/PassthroughAuth.cjs +2 -1
- package/dist/Auth/PassthroughAuth.cjs.map +1 -0
- package/dist/Auth/PassthroughAuth.js +5 -4
- package/dist/Auth/PassthroughAuth.js.map +1 -0
- package/dist/Boost.cjs +2 -1
- package/dist/Boost.cjs.map +1 -0
- package/dist/Boost.d.ts +105 -14
- package/dist/Boost.d.ts.map +1 -1
- package/dist/Boost.js +138 -5
- package/dist/Boost.js.map +1 -0
- package/dist/BoostCore-DolmDuXW.cjs +3 -0
- package/dist/BoostCore-DolmDuXW.cjs.map +1 -0
- package/dist/BoostCore-Z97KVu4V.js +1448 -0
- package/dist/BoostCore-Z97KVu4V.js.map +1 -0
- package/dist/BoostCore.cjs +2 -2
- package/dist/BoostCore.cjs.map +1 -0
- package/dist/BoostCore.d.ts +788 -79
- package/dist/BoostCore.d.ts.map +1 -1
- package/dist/BoostCore.js +30 -1103
- package/dist/BoostCore.js.map +1 -0
- package/dist/BoostRegistry.cjs +2 -1
- package/dist/BoostRegistry.cjs.map +1 -0
- package/dist/BoostRegistry.d.ts +95 -26
- package/dist/BoostRegistry.d.ts.map +1 -1
- package/dist/BoostRegistry.js +183 -89
- package/dist/BoostRegistry.js.map +1 -0
- package/dist/Budgets/Budget.cjs +2 -1
- package/dist/Budgets/Budget.cjs.map +1 -0
- package/dist/Budgets/Budget.d.ts +1 -1
- package/dist/Budgets/Budget.d.ts.map +1 -1
- package/dist/Budgets/Budget.js +15 -13
- package/dist/Budgets/Budget.js.map +1 -0
- package/dist/Budgets/ManagedBudget.cjs +2 -1
- package/dist/Budgets/ManagedBudget.cjs.map +1 -0
- package/dist/Budgets/ManagedBudget.d.ts +112 -192
- package/dist/Budgets/ManagedBudget.d.ts.map +1 -1
- package/dist/Budgets/ManagedBudget.js +91 -291
- package/dist/Budgets/ManagedBudget.js.map +1 -0
- package/dist/Budgets/VestingBudget.d.ts +277 -91
- package/dist/Budgets/VestingBudget.d.ts.map +1 -1
- package/dist/Deployable/Contract.cjs +2 -1
- package/dist/Deployable/Contract.cjs.map +1 -0
- package/dist/Deployable/Contract.d.ts +4 -5
- package/dist/Deployable/Contract.d.ts.map +1 -1
- package/dist/Deployable/Contract.js +7 -8
- package/dist/Deployable/Contract.js.map +1 -0
- package/dist/Deployable/Deployable.cjs +1 -0
- package/dist/Deployable/Deployable.cjs.map +1 -0
- package/dist/Deployable/Deployable.d.ts +9 -3
- package/dist/Deployable/Deployable.d.ts.map +1 -1
- package/dist/Deployable/Deployable.js +10 -5
- package/dist/Deployable/Deployable.js.map +1 -0
- package/dist/Deployable/DeployableTarget.cjs +2 -1
- package/dist/Deployable/DeployableTarget.cjs.map +1 -0
- package/dist/Deployable/DeployableTarget.d.ts +16 -15
- package/dist/Deployable/DeployableTarget.d.ts.map +1 -1
- package/dist/Deployable/DeployableTarget.js +49 -42
- package/dist/Deployable/DeployableTarget.js.map +1 -0
- 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-CBKzuNoN.cjs +2 -0
- package/dist/EventAction-CBKzuNoN.cjs.map +1 -0
- package/dist/EventAction-DWuuc_Qy.js +1528 -0
- package/dist/EventAction-DWuuc_Qy.js.map +1 -0
- package/dist/Incentive-BxzEtN26.js +298 -0
- package/dist/Incentive-BxzEtN26.js.map +1 -0
- package/dist/Incentive-CrF3-ayL.cjs +2 -0
- package/dist/Incentive-CrF3-ayL.cjs.map +1 -0
- package/dist/Incentives/AllowListIncentive.cjs +2 -1
- package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
- package/dist/Incentives/AllowListIncentive.d.ts +65 -21
- package/dist/Incentives/AllowListIncentive.d.ts.map +1 -1
- package/dist/Incentives/AllowListIncentive.js +52 -36
- package/dist/Incentives/AllowListIncentive.js.map +1 -0
- package/dist/Incentives/CGDAIncentive.cjs +2 -1
- package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
- package/dist/Incentives/CGDAIncentive.d.ts +315 -26
- package/dist/Incentives/CGDAIncentive.d.ts.map +1 -1
- package/dist/Incentives/CGDAIncentive.js +64 -39
- package/dist/Incentives/CGDAIncentive.js.map +1 -0
- package/dist/Incentives/ERC1155Incentive.d.ts +291 -43
- package/dist/Incentives/ERC1155Incentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20Incentive.cjs +2 -1
- package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
- package/dist/Incentives/ERC20Incentive.d.ts +270 -33
- package/dist/Incentives/ERC20Incentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20Incentive.js +69 -46
- package/dist/Incentives/ERC20Incentive.js.map +1 -0
- package/dist/{Budgets/SimpleBudget.d.ts → Incentives/ERC20VariableCriteriaIncentive.d.ts} +338 -421
- package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts.map +1 -0
- package/dist/Incentives/ERC20VariableIncentive.d.ts +262 -32
- package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -1
- package/dist/Incentives/Incentive.cjs +2 -1
- package/dist/Incentives/Incentive.cjs.map +1 -0
- package/dist/Incentives/Incentive.d.ts +5 -8
- package/dist/Incentives/Incentive.d.ts.map +1 -1
- package/dist/Incentives/Incentive.js +17 -278
- package/dist/Incentives/Incentive.js.map +1 -0
- package/dist/Incentives/PointsIncentive.cjs +2 -1
- package/dist/Incentives/PointsIncentive.cjs.map +1 -0
- package/dist/Incentives/PointsIncentive.d.ts +81 -23
- package/dist/Incentives/PointsIncentive.d.ts.map +1 -1
- package/dist/Incentives/PointsIncentive.js +57 -36
- package/dist/Incentives/PointsIncentive.js.map +1 -0
- 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 +2 -1
- package/dist/Validators/SignerValidator.cjs.map +1 -0
- package/dist/Validators/SignerValidator.d.ts +310 -17
- package/dist/Validators/SignerValidator.d.ts.map +1 -1
- package/dist/Validators/SignerValidator.js +165 -36
- package/dist/Validators/SignerValidator.js.map +1 -0
- package/dist/Validators/Validator.cjs +2 -1
- package/dist/Validators/Validator.cjs.map +1 -0
- package/dist/Validators/Validator.d.ts +2 -2
- package/dist/Validators/Validator.d.ts.map +1 -1
- package/dist/Validators/Validator.js +10 -8
- package/dist/Validators/Validator.js.map +1 -0
- package/dist/claiming.cjs +2 -0
- package/dist/claiming.cjs.map +1 -0
- package/dist/claiming.d.ts +43 -0
- package/dist/claiming.d.ts.map +1 -0
- package/dist/claiming.js +17 -0
- package/dist/claiming.js.map +1 -0
- 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 +2 -1
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +421 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +297 -39
- package/dist/errors.js.map +1 -0
- package/dist/{generated-x_abr3Yv.js → generated-CKt2yCQd.js} +3143 -3002
- 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 +2 -1
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +10 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +144 -1353
- package/dist/index.js.map +1 -0
- package/dist/transfers.cjs +2 -0
- package/dist/transfers.cjs.map +1 -0
- package/dist/transfers.d.ts +198 -0
- package/dist/transfers.d.ts.map +1 -0
- package/dist/transfers.js +84 -0
- package/dist/transfers.js.map +1 -0
- package/dist/utils.cjs +2 -1
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.ts +26 -1350
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +38 -636
- package/dist/utils.js.map +1 -0
- package/package.json +37 -11
- package/src/Actions/Action.test.ts +79 -0
- package/src/Actions/Action.ts +61 -0
- package/src/Actions/ContractAction.test.ts +197 -0
- package/src/Actions/ContractAction.ts +300 -0
- package/src/Actions/ERC721MintAction.test.ts +112 -0
- package/src/Actions/ERC721MintAction.ts +291 -0
- package/src/Actions/EventAction.test.ts +787 -0
- package/src/Actions/EventAction.ts +1218 -0
- package/src/AllowLists/AllowList.test.ts +64 -0
- package/src/AllowLists/AllowList.ts +62 -0
- package/src/AllowLists/OpenAllowList.test.ts +40 -0
- package/src/AllowLists/OpenAllowList.ts +45 -0
- package/src/AllowLists/SimpleAllowList.test.ts +52 -0
- package/src/AllowLists/SimpleAllowList.ts +262 -0
- package/src/AllowLists/SimpleDenyList.test.ts +52 -0
- package/src/AllowLists/SimpleDenyList.ts +250 -0
- package/src/Auth/Auth.ts +11 -0
- package/src/Auth/PassthroughAuth.test.ts +12 -0
- package/src/Auth/PassthroughAuth.ts +80 -0
- package/src/Boost.ts +287 -0
- package/src/BoostCore.test.ts +894 -0
- package/src/BoostCore.ts +1438 -0
- package/src/BoostRegistry.test.ts +53 -0
- package/src/BoostRegistry.ts +588 -0
- package/src/Budgets/Budget.test.ts +27 -0
- package/src/Budgets/Budget.ts +60 -0
- package/src/Budgets/ManagedBudget.test.ts +217 -0
- package/src/Budgets/ManagedBudget.ts +534 -0
- package/src/Budgets/VestingBudget.test.ts +123 -0
- package/src/Budgets/VestingBudget.ts +530 -0
- package/src/Deployable/Contract.ts +228 -0
- package/src/Deployable/Deployable.ts +250 -0
- package/src/Deployable/DeployableTarget.ts +234 -0
- package/src/Deployable/DeployableTargetWithRBAC.ts +323 -0
- package/src/Incentives/AllowListIncentive.test.ts +143 -0
- package/src/Incentives/AllowListIncentive.ts +336 -0
- package/src/Incentives/CGDAIncentive.test.ts +135 -0
- package/src/Incentives/CGDAIncentive.ts +476 -0
- package/src/Incentives/ERC1155Incentive.test.ts +87 -0
- package/src/Incentives/ERC1155Incentive.ts +465 -0
- package/src/Incentives/ERC20Incentive.test.ts +133 -0
- package/src/Incentives/ERC20Incentive.ts +490 -0
- package/src/Incentives/ERC20VariableCriteriaIncentive.test.ts +184 -0
- package/src/Incentives/ERC20VariableCriteriaIncentive.ts +309 -0
- package/src/Incentives/ERC20VariableIncentive.test.ts +139 -0
- package/src/Incentives/ERC20VariableIncentive.ts +428 -0
- package/src/Incentives/Incentive.test.ts +95 -0
- package/src/Incentives/Incentive.ts +86 -0
- package/src/Incentives/PointsIncentive.test.ts +138 -0
- package/src/Incentives/PointsIncentive.ts +367 -0
- package/src/Validators/SignerValidator.test.ts +159 -0
- package/src/Validators/SignerValidator.ts +683 -0
- package/src/Validators/Validator.test.ts +21 -0
- package/src/Validators/Validator.ts +55 -0
- package/src/claiming.ts +56 -0
- package/src/errors.ts +866 -0
- package/src/index.test.ts +122 -0
- package/src/index.ts +58 -0
- package/src/transfers.ts +284 -0
- package/src/utils.test.ts +44 -0
- package/src/utils.ts +247 -0
- package/dist/Budgets/SimpleBudget.d.ts.map +0 -1
- package/dist/generated-BaaleHW-.cjs +0 -2
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
|
|
2
|
+
import { beforeAll, describe, expect, test } from 'vitest';
|
|
3
|
+
import {
|
|
4
|
+
type Fixtures,
|
|
5
|
+
defaultOptions,
|
|
6
|
+
deployFixtures,
|
|
7
|
+
} from '@boostxyz/test/helpers';
|
|
8
|
+
import {
|
|
9
|
+
SimpleAllowList,
|
|
10
|
+
SimpleDenyList,
|
|
11
|
+
allowListFromAddress,
|
|
12
|
+
} from './AllowList';
|
|
13
|
+
|
|
14
|
+
let fixtures: Fixtures;
|
|
15
|
+
|
|
16
|
+
beforeAll(async () => {
|
|
17
|
+
fixtures = await loadFixture(deployFixtures(defaultOptions));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function freshAllowList(fixtures: Fixtures) {
|
|
21
|
+
return function freshAllowList() {
|
|
22
|
+
return fixtures.registry.initialize(
|
|
23
|
+
crypto.randomUUID(),
|
|
24
|
+
fixtures.core.SimpleAllowList({
|
|
25
|
+
owner: defaultOptions.account.address,
|
|
26
|
+
allowed: [defaultOptions.account.address],
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function freshDenyList(fixtures: Fixtures) {
|
|
33
|
+
return function freshDenyList() {
|
|
34
|
+
return fixtures.registry.initialize(
|
|
35
|
+
crypto.randomUUID(),
|
|
36
|
+
fixtures.core.SimpleDenyList({
|
|
37
|
+
owner: defaultOptions.account.address,
|
|
38
|
+
denied: [defaultOptions.account.address],
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('AllowList', () => {
|
|
45
|
+
test('can automatically instantiate SimpleAllowList given an address', async () => {
|
|
46
|
+
const _allowList = await loadFixture(freshAllowList(fixtures));
|
|
47
|
+
expect(
|
|
48
|
+
await allowListFromAddress(
|
|
49
|
+
defaultOptions,
|
|
50
|
+
_allowList.assertValidAddress(),
|
|
51
|
+
),
|
|
52
|
+
).toBeInstanceOf(SimpleAllowList);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('can automatically instantiate SimpleDenyList given an address', async () => {
|
|
56
|
+
const _allowList = await loadFixture(freshDenyList(fixtures));
|
|
57
|
+
expect(
|
|
58
|
+
await allowListFromAddress(
|
|
59
|
+
defaultOptions,
|
|
60
|
+
_allowList.assertValidAddress(),
|
|
61
|
+
),
|
|
62
|
+
).toBeInstanceOf(SimpleDenyList);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { aAllowListAbi } from '@boostxyz/evm';
|
|
2
|
+
import {
|
|
3
|
+
ASimpleAllowList,
|
|
4
|
+
ASimpleDenyList,
|
|
5
|
+
} from '@boostxyz/evm/deploys/componentInterfaces.json';
|
|
6
|
+
import { readContract } from '@wagmi/core';
|
|
7
|
+
import type { Address, Hex } from 'viem';
|
|
8
|
+
import type { DeployableOptions } from '../Deployable/Deployable';
|
|
9
|
+
import { InvalidComponentInterfaceError } from '../errors';
|
|
10
|
+
import { OpenAllowList } from './OpenAllowList';
|
|
11
|
+
import { SimpleAllowList } from './SimpleAllowList';
|
|
12
|
+
import { SimpleDenyList } from './SimpleDenyList';
|
|
13
|
+
|
|
14
|
+
export { OpenAllowList, SimpleAllowList, SimpleDenyList };
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A union type representing all valid protocol AllowList implementations
|
|
18
|
+
*
|
|
19
|
+
* @export
|
|
20
|
+
* @typedef {AllowList}
|
|
21
|
+
*/
|
|
22
|
+
export type AllowList = OpenAllowList | SimpleAllowList | SimpleDenyList;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A map of AllowList component interfaces to their constructors.
|
|
26
|
+
*
|
|
27
|
+
* @type {{ "0x2bc9016b": SimpleAllowList; "0x9d585f63": SimpleDenyList; }}
|
|
28
|
+
*/
|
|
29
|
+
export const AllowListByComponentInterface = {
|
|
30
|
+
[ASimpleAllowList as Hex]: SimpleAllowList,
|
|
31
|
+
[ASimpleDenyList as Hex]: SimpleDenyList,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A function that will read a contract's component interface using `getComponentInterface` and return the correct instantiated instance.
|
|
36
|
+
* This function will never return an instance of {@link OpenAllowList} because it has the same component interface as {@link SimpleDenyList}
|
|
37
|
+
*
|
|
38
|
+
* @export
|
|
39
|
+
* @async
|
|
40
|
+
* @param {DeployableOptions} options
|
|
41
|
+
* @param {Address} address
|
|
42
|
+
* @returns {Promise<SimpleAllowList | SimpleDenyList>}
|
|
43
|
+
* @throws {@link InvalidComponentInterfaceError}
|
|
44
|
+
*/
|
|
45
|
+
export async function allowListFromAddress(
|
|
46
|
+
options: DeployableOptions,
|
|
47
|
+
address: Address,
|
|
48
|
+
) {
|
|
49
|
+
const interfaceId = (await readContract(options.config, {
|
|
50
|
+
abi: aAllowListAbi,
|
|
51
|
+
functionName: 'getComponentInterface',
|
|
52
|
+
address,
|
|
53
|
+
})) as keyof typeof AllowListByComponentInterface;
|
|
54
|
+
const Ctor = AllowListByComponentInterface[interfaceId];
|
|
55
|
+
if (!Ctor) {
|
|
56
|
+
throw new InvalidComponentInterfaceError(
|
|
57
|
+
Object.keys(AllowListByComponentInterface) as Hex[],
|
|
58
|
+
interfaceId as Hex,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return new Ctor(options, address) as SimpleDenyList | SimpleAllowList;
|
|
62
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
|
|
2
|
+
import { isAddress, zeroAddress } from 'viem';
|
|
3
|
+
import { beforeAll, describe, expect, test } from 'vitest';
|
|
4
|
+
import { accounts } from '@boostxyz/test/accounts';
|
|
5
|
+
import {
|
|
6
|
+
type Fixtures,
|
|
7
|
+
defaultOptions,
|
|
8
|
+
deployFixtures,
|
|
9
|
+
} from '@boostxyz/test/helpers';
|
|
10
|
+
import { OpenAllowList } from './OpenAllowList';
|
|
11
|
+
|
|
12
|
+
let fixtures: Fixtures;
|
|
13
|
+
|
|
14
|
+
beforeAll(async () => {
|
|
15
|
+
fixtures = await loadFixture(deployFixtures(defaultOptions));
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
function freshOpenAllowList(fixtures: Fixtures) {
|
|
19
|
+
return function freshOpenAllowList() {
|
|
20
|
+
return fixtures.registry.initialize(
|
|
21
|
+
crypto.randomUUID(),
|
|
22
|
+
new fixtures.bases.OpenAllowList(defaultOptions),
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe('OpenAllowList', () => {
|
|
28
|
+
test('can successfully be deployed', async () => {
|
|
29
|
+
const denyList = new OpenAllowList(defaultOptions);
|
|
30
|
+
await denyList.deploy();
|
|
31
|
+
expect(isAddress(denyList.assertValidAddress())).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('allows anyone', async () => {
|
|
35
|
+
const denyList = await loadFixture(freshOpenAllowList(fixtures));
|
|
36
|
+
expect(await denyList.isAllowed(defaultOptions.account.address)).toBe(true);
|
|
37
|
+
expect(await denyList.isAllowed(zeroAddress)).toBe(true);
|
|
38
|
+
expect(await denyList.isAllowed(accounts.at(1)!.account)).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { simpleDenyListAbi } from '@boostxyz/evm';
|
|
2
|
+
import { bytecode } from '@boostxyz/evm/artifacts/contracts/allowlists/SimpleDenyList.sol/SimpleDenyList.json';
|
|
3
|
+
import { type Hex, zeroAddress } from 'viem';
|
|
4
|
+
import type {
|
|
5
|
+
DeployableOptions,
|
|
6
|
+
GenericDeployableParams,
|
|
7
|
+
} from '../Deployable/Deployable';
|
|
8
|
+
import {
|
|
9
|
+
SimpleDenyList,
|
|
10
|
+
type SimpleDenyListPayload,
|
|
11
|
+
prepareSimpleDenyListPayload,
|
|
12
|
+
} from './SimpleDenyList';
|
|
13
|
+
|
|
14
|
+
export const openAllowListAbi = simpleDenyListAbi;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A simple AllowList, extending {@link DenyList}, that is ownerless and allows anyone to claim.
|
|
18
|
+
*
|
|
19
|
+
* @export
|
|
20
|
+
* @class OpenAllowList
|
|
21
|
+
* @typedef {OpenAllowList}
|
|
22
|
+
* @extends {DeployableTarget<OpenAllowListPayload>}
|
|
23
|
+
*/
|
|
24
|
+
export class OpenAllowList extends SimpleDenyList<undefined> {
|
|
25
|
+
/**
|
|
26
|
+
* @inheritdoc
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
* @param {?SimpleDenyListPayload} [_payload]
|
|
30
|
+
* @param {?DeployableOptions} [_options]
|
|
31
|
+
* @returns {GenericDeployableParams}
|
|
32
|
+
*/
|
|
33
|
+
public override buildParameters(
|
|
34
|
+
_payload?: SimpleDenyListPayload,
|
|
35
|
+
_options?: DeployableOptions,
|
|
36
|
+
): GenericDeployableParams {
|
|
37
|
+
const [_, options] = this.validateDeploymentConfig({}, _options);
|
|
38
|
+
return {
|
|
39
|
+
abi: openAllowListAbi,
|
|
40
|
+
bytecode: bytecode as Hex,
|
|
41
|
+
args: [prepareSimpleDenyListPayload({ owner: zeroAddress, denied: [] })],
|
|
42
|
+
...this.optionallyAttachAccount(options.account),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
|
|
2
|
+
import { isAddress, zeroAddress } from 'viem';
|
|
3
|
+
import { beforeAll, describe, expect, test } from 'vitest';
|
|
4
|
+
import {
|
|
5
|
+
type Fixtures,
|
|
6
|
+
defaultOptions,
|
|
7
|
+
deployFixtures,
|
|
8
|
+
} from '@boostxyz/test/helpers';
|
|
9
|
+
import { SimpleAllowList } from './SimpleAllowList';
|
|
10
|
+
|
|
11
|
+
let fixtures: Fixtures;
|
|
12
|
+
|
|
13
|
+
beforeAll(async () => {
|
|
14
|
+
fixtures = await loadFixture(deployFixtures(defaultOptions));
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
function freshAllowList(fixtures: Fixtures) {
|
|
18
|
+
return function freshAllowList() {
|
|
19
|
+
return fixtures.registry.initialize(
|
|
20
|
+
crypto.randomUUID(),
|
|
21
|
+
fixtures.core.SimpleAllowList({
|
|
22
|
+
owner: defaultOptions.account.address,
|
|
23
|
+
allowed: [defaultOptions.account.address],
|
|
24
|
+
}),
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe('SimpleAllowList', () => {
|
|
30
|
+
test('can successfully be deployed', async () => {
|
|
31
|
+
const allowList = new SimpleAllowList(defaultOptions, {
|
|
32
|
+
owner: defaultOptions.account.address,
|
|
33
|
+
allowed: [],
|
|
34
|
+
});
|
|
35
|
+
await allowList.deploy();
|
|
36
|
+
expect(isAddress(allowList.assertValidAddress())).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('can check is allowed', async () => {
|
|
40
|
+
const allowList = await loadFixture(freshAllowList(fixtures));
|
|
41
|
+
expect(await allowList.isAllowed(defaultOptions.account.address)).toBe(
|
|
42
|
+
true,
|
|
43
|
+
);
|
|
44
|
+
expect(await allowList.isAllowed(zeroAddress)).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('can set allowed', async () => {
|
|
48
|
+
const allowList = await loadFixture(freshAllowList(fixtures));
|
|
49
|
+
await allowList.setAllowed([zeroAddress], [true]);
|
|
50
|
+
expect(await allowList.isAllowed(zeroAddress)).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readSimpleAllowListIsAllowed,
|
|
3
|
+
readSimpleAllowListOwner,
|
|
4
|
+
simpleAllowListAbi,
|
|
5
|
+
simulateSimpleAllowListSetAllowed,
|
|
6
|
+
writeSimpleAllowListSetAllowed,
|
|
7
|
+
} from '@boostxyz/evm';
|
|
8
|
+
import { bytecode } from '@boostxyz/evm/artifacts/contracts/allowlists/SimpleAllowList.sol/SimpleAllowList.json';
|
|
9
|
+
import { getAccount } from '@wagmi/core';
|
|
10
|
+
import {
|
|
11
|
+
type Address,
|
|
12
|
+
type ContractEventName,
|
|
13
|
+
type Hex,
|
|
14
|
+
encodeAbiParameters,
|
|
15
|
+
zeroAddress,
|
|
16
|
+
zeroHash,
|
|
17
|
+
} from 'viem';
|
|
18
|
+
import { SimpleAllowList as SimpleAllowListBases } from '../../dist/deployments.json';
|
|
19
|
+
import type {
|
|
20
|
+
DeployableOptions,
|
|
21
|
+
GenericDeployableParams,
|
|
22
|
+
} from '../Deployable/Deployable';
|
|
23
|
+
import {
|
|
24
|
+
DeployableTargetWithRBAC,
|
|
25
|
+
Roles,
|
|
26
|
+
} from '../Deployable/DeployableTargetWithRBAC';
|
|
27
|
+
import { DeployableUnknownOwnerProvidedError } from '../errors';
|
|
28
|
+
import {
|
|
29
|
+
type GenericLog,
|
|
30
|
+
type ReadParams,
|
|
31
|
+
RegistryType,
|
|
32
|
+
type WriteParams,
|
|
33
|
+
} from '../utils';
|
|
34
|
+
|
|
35
|
+
export { simpleAllowListAbi };
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Object representation of a {@link SimpleAllowList} initialization payload.
|
|
39
|
+
*
|
|
40
|
+
* @export
|
|
41
|
+
* @interface SimpleAllowListPayload
|
|
42
|
+
* @typedef {SimpleAllowListPayload}
|
|
43
|
+
*/
|
|
44
|
+
export interface SimpleAllowListPayload {
|
|
45
|
+
/**
|
|
46
|
+
* The allow list's owner, given the {@link LIST_MANAGER_ROLE} role.
|
|
47
|
+
*
|
|
48
|
+
* @type {Address}
|
|
49
|
+
*/
|
|
50
|
+
owner: Address;
|
|
51
|
+
/**
|
|
52
|
+
* List of allowed addresses.
|
|
53
|
+
*
|
|
54
|
+
* @type {Address[]}
|
|
55
|
+
*/
|
|
56
|
+
allowed: Address[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A generic `viem.Log` event with support for `SimpleAllowList` event types.
|
|
61
|
+
*
|
|
62
|
+
* @export
|
|
63
|
+
* @typedef {SimpleAllowListLog}
|
|
64
|
+
* @template {ContractEventName<
|
|
65
|
+
* typeof simpleAllowListAbi
|
|
66
|
+
* >} [event=ContractEventName<typeof simpleAllowListAbi>]
|
|
67
|
+
*/
|
|
68
|
+
export type SimpleAllowListLog<
|
|
69
|
+
event extends ContractEventName<
|
|
70
|
+
typeof simpleAllowListAbi
|
|
71
|
+
> = ContractEventName<typeof simpleAllowListAbi>,
|
|
72
|
+
> = GenericLog<typeof simpleAllowListAbi, event>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A constant representing the list manager's role
|
|
76
|
+
*
|
|
77
|
+
* @deprecated use {@link Roles} instead
|
|
78
|
+
* @type {1n}
|
|
79
|
+
*/
|
|
80
|
+
export const LIST_MANAGER_ROLE = Roles.MANAGER;
|
|
81
|
+
/**
|
|
82
|
+
* A simple implementation of an AllowList that checks if a user is authorized based on a list of allowed addresses
|
|
83
|
+
*
|
|
84
|
+
* @export
|
|
85
|
+
* @class SimpleAllowList
|
|
86
|
+
* @typedef {SimpleAllowList}
|
|
87
|
+
* @extends {DeployableTargetWithRBAC<SimpleAllowListPayload>}
|
|
88
|
+
*/
|
|
89
|
+
export class SimpleAllowList extends DeployableTargetWithRBAC<
|
|
90
|
+
SimpleAllowListPayload,
|
|
91
|
+
typeof simpleAllowListAbi
|
|
92
|
+
> {
|
|
93
|
+
public override readonly abi = simpleAllowListAbi;
|
|
94
|
+
/**
|
|
95
|
+
* @inheritdoc
|
|
96
|
+
*
|
|
97
|
+
* @public
|
|
98
|
+
* @static
|
|
99
|
+
* @type {Record<number, Address>}
|
|
100
|
+
*/
|
|
101
|
+
public static override bases: Record<number, Address> = {
|
|
102
|
+
...(SimpleAllowListBases as Record<number, Address>),
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* @inheritdoc
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
* @static
|
|
109
|
+
* @type {RegistryType}
|
|
110
|
+
*/
|
|
111
|
+
public static override registryType: RegistryType = RegistryType.ALLOW_LIST;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Retrieves the owner
|
|
115
|
+
*
|
|
116
|
+
* @public
|
|
117
|
+
* @async
|
|
118
|
+
* @param {?ReadParams} [params]
|
|
119
|
+
* @returns {Promise<Address>} - The address of the owner
|
|
120
|
+
*/
|
|
121
|
+
public async owner(
|
|
122
|
+
params?: ReadParams<typeof simpleAllowListAbi, 'owner'>,
|
|
123
|
+
): Promise<Address> {
|
|
124
|
+
return await readSimpleAllowListOwner(this._config, {
|
|
125
|
+
...this.optionallyAttachAccount(),
|
|
126
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
127
|
+
...(params as any),
|
|
128
|
+
address: this.assertValidAddress(),
|
|
129
|
+
args: [],
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Check if a user is authorized.
|
|
135
|
+
*
|
|
136
|
+
* @public
|
|
137
|
+
* @async
|
|
138
|
+
* @param {Address} address - The address of the user
|
|
139
|
+
* @param {?ReadParams} [params]
|
|
140
|
+
* @returns {Promise<boolean>} - True if the user is authorized
|
|
141
|
+
*/
|
|
142
|
+
public async isAllowed(
|
|
143
|
+
address: Address,
|
|
144
|
+
params?: ReadParams<typeof simpleAllowListAbi, 'setAllowed'>,
|
|
145
|
+
): Promise<boolean> {
|
|
146
|
+
return await readSimpleAllowListIsAllowed(this._config, {
|
|
147
|
+
address: this.assertValidAddress(),
|
|
148
|
+
args: [address, zeroHash],
|
|
149
|
+
...this.optionallyAttachAccount(),
|
|
150
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
151
|
+
...(params as any),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Set the allowed status of a user. The length of the `users_` and `allowed_` arrays must be the same.
|
|
157
|
+
* This function can only be called by the owner
|
|
158
|
+
*
|
|
159
|
+
* @public
|
|
160
|
+
* @async
|
|
161
|
+
* @param {Address[]} addresses - The list of users to update
|
|
162
|
+
* @param {boolean[]} allowed - The allowed status of each user
|
|
163
|
+
* @param {?ReadParams} [params]
|
|
164
|
+
* @returns {Promise<void>}
|
|
165
|
+
*/
|
|
166
|
+
public async setAllowed(
|
|
167
|
+
addresses: Address[],
|
|
168
|
+
allowed: boolean[],
|
|
169
|
+
params?: WriteParams<typeof simpleAllowListAbi, 'setAllowed'>,
|
|
170
|
+
) {
|
|
171
|
+
return await this.awaitResult(
|
|
172
|
+
this.setAllowedRaw(addresses, allowed, params),
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Set the allowed status of a user. The length of the `users_` and `allowed_` arrays must be the same.
|
|
178
|
+
* This function can only be called by the owner
|
|
179
|
+
*
|
|
180
|
+
* @public
|
|
181
|
+
* @async
|
|
182
|
+
* @param {Address[]} addresses - The list of users to update
|
|
183
|
+
* @param {boolean[]} allowed - The allowed status of each user
|
|
184
|
+
* @param {?ReadParams} [params]
|
|
185
|
+
* @returns {Promise<{ hash: `0x${string}`; result: void; }>}
|
|
186
|
+
*/
|
|
187
|
+
public async setAllowedRaw(
|
|
188
|
+
addresses: Address[],
|
|
189
|
+
allowed: boolean[],
|
|
190
|
+
params?: ReadParams<typeof simpleAllowListAbi, 'setAllowed'>,
|
|
191
|
+
) {
|
|
192
|
+
const { request, result } = await simulateSimpleAllowListSetAllowed(
|
|
193
|
+
this._config,
|
|
194
|
+
{
|
|
195
|
+
address: this.assertValidAddress(),
|
|
196
|
+
args: [addresses, allowed],
|
|
197
|
+
...this.optionallyAttachAccount(),
|
|
198
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
199
|
+
...(params as any),
|
|
200
|
+
},
|
|
201
|
+
);
|
|
202
|
+
const hash = await writeSimpleAllowListSetAllowed(this._config, request);
|
|
203
|
+
return { hash, result };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @inheritdoc
|
|
208
|
+
*
|
|
209
|
+
* @public
|
|
210
|
+
* @param {?SimpleAllowListPayload} [_payload]
|
|
211
|
+
* @param {?DeployableOptions} [_options]
|
|
212
|
+
* @returns {GenericDeployableParams}
|
|
213
|
+
*/
|
|
214
|
+
public override buildParameters(
|
|
215
|
+
_payload?: SimpleAllowListPayload,
|
|
216
|
+
_options?: DeployableOptions,
|
|
217
|
+
): GenericDeployableParams {
|
|
218
|
+
const [payload, options] = this.validateDeploymentConfig(
|
|
219
|
+
_payload,
|
|
220
|
+
_options,
|
|
221
|
+
);
|
|
222
|
+
if (!payload.owner || payload.owner === zeroAddress) {
|
|
223
|
+
const owner = options.account
|
|
224
|
+
? options.account.address
|
|
225
|
+
: options.config
|
|
226
|
+
? getAccount(options.config).address
|
|
227
|
+
: this._account?.address;
|
|
228
|
+
if (owner) {
|
|
229
|
+
payload.owner = owner;
|
|
230
|
+
} else {
|
|
231
|
+
throw new DeployableUnknownOwnerProvidedError();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
abi: simpleAllowListAbi,
|
|
236
|
+
bytecode: bytecode as Hex,
|
|
237
|
+
args: [prepareSimpleAllowListPayload(payload)],
|
|
238
|
+
...this.optionallyAttachAccount(options.account),
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Given a {@link SimpleAllowListPayload}, properly encode the initialization payload.
|
|
245
|
+
*
|
|
246
|
+
* @param {SimpleAllowListPayload} param0
|
|
247
|
+
* @param {Address} param0.owner - The allow list's owner, given the {@link LIST_MANAGER_ROLE} role.
|
|
248
|
+
* @param {Address[]} param0.allowed - List of allowed addresses.
|
|
249
|
+
* @returns {Hex}
|
|
250
|
+
*/
|
|
251
|
+
export function prepareSimpleAllowListPayload({
|
|
252
|
+
owner,
|
|
253
|
+
allowed,
|
|
254
|
+
}: SimpleAllowListPayload) {
|
|
255
|
+
return encodeAbiParameters(
|
|
256
|
+
[
|
|
257
|
+
{ type: 'address', name: 'owner' },
|
|
258
|
+
{ type: 'address[]', name: 'allowed' },
|
|
259
|
+
],
|
|
260
|
+
[owner, allowed],
|
|
261
|
+
);
|
|
262
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
|
|
2
|
+
import { isAddress, zeroAddress } from 'viem';
|
|
3
|
+
import { beforeAll, describe, expect, test } from 'vitest';
|
|
4
|
+
import {
|
|
5
|
+
type Fixtures,
|
|
6
|
+
defaultOptions,
|
|
7
|
+
deployFixtures,
|
|
8
|
+
} from '@boostxyz/test/helpers';
|
|
9
|
+
import { SimpleDenyList } from './SimpleDenyList';
|
|
10
|
+
|
|
11
|
+
let fixtures: Fixtures;
|
|
12
|
+
|
|
13
|
+
beforeAll(async () => {
|
|
14
|
+
fixtures = await loadFixture(deployFixtures(defaultOptions));
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
function freshDenyList(fixtures: Fixtures) {
|
|
18
|
+
return function freshDenyList() {
|
|
19
|
+
return fixtures.registry.initialize(
|
|
20
|
+
crypto.randomUUID(),
|
|
21
|
+
fixtures.core.SimpleDenyList({
|
|
22
|
+
owner: defaultOptions.account.address,
|
|
23
|
+
denied: [defaultOptions.account.address],
|
|
24
|
+
}),
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe('SimpleDenyList', () => {
|
|
30
|
+
test('can successfully be deployed', async () => {
|
|
31
|
+
const denyList = new SimpleDenyList(defaultOptions, {
|
|
32
|
+
owner: defaultOptions.account.address,
|
|
33
|
+
denied: [],
|
|
34
|
+
});
|
|
35
|
+
await denyList.deploy();
|
|
36
|
+
expect(isAddress(denyList.assertValidAddress())).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('can check is denied', async () => {
|
|
40
|
+
const denyList = await loadFixture(freshDenyList(fixtures));
|
|
41
|
+
expect(await denyList.isAllowed(defaultOptions.account.address)).toBe(
|
|
42
|
+
false,
|
|
43
|
+
);
|
|
44
|
+
expect(await denyList.isAllowed(zeroAddress)).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('can set denied', async () => {
|
|
48
|
+
const denyList = await loadFixture(freshDenyList(fixtures));
|
|
49
|
+
await denyList.setDenied([zeroAddress], [true]);
|
|
50
|
+
expect(await denyList.isAllowed(zeroAddress)).toBe(false);
|
|
51
|
+
});
|
|
52
|
+
});
|