@boostxyz/sdk 0.0.0-alpha.10
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/LICENSE +674 -0
- package/README.md +7 -0
- package/dist/Actions/Action.cjs +2 -0
- package/dist/Actions/Action.cjs.map +1 -0
- package/dist/Actions/Action.d.ts +31 -0
- package/dist/Actions/Action.d.ts.map +1 -0
- package/dist/Actions/Action.js +29 -0
- package/dist/Actions/Action.js.map +1 -0
- package/dist/Actions/ContractAction.d.ts +370 -0
- package/dist/Actions/ContractAction.d.ts.map +1 -0
- package/dist/Actions/ERC721MintAction.d.ts +513 -0
- package/dist/Actions/ERC721MintAction.d.ts.map +1 -0
- package/dist/Actions/EventAction.cjs +2 -0
- package/dist/Actions/EventAction.cjs.map +1 -0
- package/dist/Actions/EventAction.d.ts +694 -0
- package/dist/Actions/EventAction.d.ts.map +1 -0
- package/dist/Actions/EventAction.js +491 -0
- package/dist/Actions/EventAction.js.map +1 -0
- package/dist/AllowLists/AllowList.cjs +2 -0
- package/dist/AllowLists/AllowList.cjs.map +1 -0
- package/dist/AllowLists/AllowList.d.ts +32 -0
- package/dist/AllowLists/AllowList.d.ts.map +1 -0
- package/dist/AllowLists/AllowList.js +30 -0
- package/dist/AllowLists/AllowList.js.map +1 -0
- package/dist/AllowLists/SimpleAllowList.cjs +2 -0
- package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
- package/dist/AllowLists/SimpleAllowList.d.ts +481 -0
- package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -0
- package/dist/AllowLists/SimpleAllowList.js +154 -0
- package/dist/AllowLists/SimpleAllowList.js.map +1 -0
- package/dist/AllowLists/SimpleDenyList.cjs +2 -0
- package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
- package/dist/AllowLists/SimpleDenyList.d.ts +335 -0
- package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -0
- package/dist/AllowLists/SimpleDenyList.js +115 -0
- package/dist/AllowLists/SimpleDenyList.js.map +1 -0
- package/dist/Auth/Auth.cjs +2 -0
- package/dist/Auth/Auth.cjs.map +1 -0
- package/dist/Auth/Auth.d.ts +10 -0
- package/dist/Auth/Auth.d.ts.map +1 -0
- package/dist/Auth/Auth.js +5 -0
- package/dist/Auth/Auth.js.map +1 -0
- package/dist/Auth/PassthroughAuth.cjs +2 -0
- package/dist/Auth/PassthroughAuth.cjs.map +1 -0
- package/dist/Auth/PassthroughAuth.d.ts +51 -0
- package/dist/Auth/PassthroughAuth.d.ts.map +1 -0
- package/dist/Auth/PassthroughAuth.js +39 -0
- package/dist/Auth/PassthroughAuth.js.map +1 -0
- package/dist/Boost.cjs +2 -0
- package/dist/Boost.cjs.map +1 -0
- package/dist/Boost.d.ts +234 -0
- package/dist/Boost.d.ts.map +1 -0
- package/dist/Boost.js +162 -0
- package/dist/Boost.js.map +1 -0
- package/dist/BoostCore.cjs +3 -0
- package/dist/BoostCore.cjs.map +1 -0
- package/dist/BoostCore.d.ts +498 -0
- package/dist/BoostCore.d.ts.map +1 -0
- package/dist/BoostCore.js +1153 -0
- package/dist/BoostCore.js.map +1 -0
- package/dist/BoostRegistry.cjs +2 -0
- package/dist/BoostRegistry.cjs.map +1 -0
- package/dist/BoostRegistry.d.ts +243 -0
- package/dist/BoostRegistry.d.ts.map +1 -0
- package/dist/BoostRegistry.js +262 -0
- package/dist/BoostRegistry.js.map +1 -0
- package/dist/Budgets/Budget.cjs +2 -0
- package/dist/Budgets/Budget.cjs.map +1 -0
- package/dist/Budgets/Budget.d.ts +31 -0
- package/dist/Budgets/Budget.d.ts.map +1 -0
- package/dist/Budgets/Budget.js +29 -0
- package/dist/Budgets/Budget.js.map +1 -0
- package/dist/Budgets/ManagedBudget.cjs +2 -0
- package/dist/Budgets/ManagedBudget.cjs.map +1 -0
- package/dist/Budgets/ManagedBudget.d.ts +1103 -0
- package/dist/Budgets/ManagedBudget.d.ts.map +1 -0
- package/dist/Budgets/ManagedBudget.js +516 -0
- package/dist/Budgets/ManagedBudget.js.map +1 -0
- package/dist/Budgets/SimpleBudget.d.ts +824 -0
- package/dist/Budgets/SimpleBudget.d.ts.map +1 -0
- package/dist/Budgets/VestingBudget.d.ts +778 -0
- package/dist/Budgets/VestingBudget.d.ts.map +1 -0
- package/dist/Deployable/Contract.cjs +2 -0
- package/dist/Deployable/Contract.cjs.map +1 -0
- package/dist/Deployable/Contract.d.ts +125 -0
- package/dist/Deployable/Contract.d.ts.map +1 -0
- package/dist/Deployable/Contract.js +150 -0
- package/dist/Deployable/Contract.js.map +1 -0
- package/dist/Deployable/Deployable.cjs +2 -0
- package/dist/Deployable/Deployable.cjs.map +1 -0
- package/dist/Deployable/Deployable.d.ts +161 -0
- package/dist/Deployable/Deployable.d.ts.map +1 -0
- package/dist/Deployable/Deployable.js +131 -0
- package/dist/Deployable/Deployable.js.map +1 -0
- package/dist/Deployable/DeployableTarget.cjs +2 -0
- package/dist/Deployable/DeployableTarget.cjs.map +1 -0
- package/dist/Deployable/DeployableTarget.d.ts +116 -0
- package/dist/Deployable/DeployableTarget.d.ts.map +1 -0
- package/dist/Deployable/DeployableTarget.js +132 -0
- package/dist/Deployable/DeployableTarget.js.map +1 -0
- package/dist/Incentives/AllowListIncentive.cjs +2 -0
- package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
- package/dist/Incentives/AllowListIncentive.d.ts +513 -0
- package/dist/Incentives/AllowListIncentive.d.ts.map +1 -0
- package/dist/Incentives/AllowListIncentive.js +201 -0
- package/dist/Incentives/AllowListIncentive.js.map +1 -0
- package/dist/Incentives/CGDAIncentive.cjs +2 -0
- package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
- package/dist/Incentives/CGDAIncentive.d.ts +644 -0
- package/dist/Incentives/CGDAIncentive.d.ts.map +1 -0
- package/dist/Incentives/CGDAIncentive.js +271 -0
- package/dist/Incentives/CGDAIncentive.js.map +1 -0
- package/dist/Incentives/ERC1155Incentive.d.ts +713 -0
- package/dist/Incentives/ERC1155Incentive.d.ts.map +1 -0
- package/dist/Incentives/ERC20Incentive.cjs +2 -0
- package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
- package/dist/Incentives/ERC20Incentive.d.ts +666 -0
- package/dist/Incentives/ERC20Incentive.d.ts.map +1 -0
- package/dist/Incentives/ERC20Incentive.js +312 -0
- package/dist/Incentives/ERC20Incentive.js.map +1 -0
- package/dist/Incentives/ERC20VariableIncentive.d.ts +582 -0
- package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -0
- package/dist/Incentives/Incentive.cjs +2 -0
- package/dist/Incentives/Incentive.cjs.map +1 -0
- package/dist/Incentives/Incentive.d.ts +36 -0
- package/dist/Incentives/Incentive.d.ts.map +1 -0
- package/dist/Incentives/Incentive.js +299 -0
- package/dist/Incentives/Incentive.js.map +1 -0
- package/dist/Incentives/PointsIncentive.cjs +2 -0
- package/dist/Incentives/PointsIncentive.cjs.map +1 -0
- package/dist/Incentives/PointsIncentive.d.ts +659 -0
- package/dist/Incentives/PointsIncentive.d.ts.map +1 -0
- package/dist/Incentives/PointsIncentive.js +215 -0
- package/dist/Incentives/PointsIncentive.js.map +1 -0
- package/dist/Validators/SignerValidator.cjs +2 -0
- package/dist/Validators/SignerValidator.cjs.map +1 -0
- package/dist/Validators/SignerValidator.d.ts +745 -0
- package/dist/Validators/SignerValidator.d.ts.map +1 -0
- package/dist/Validators/SignerValidator.js +293 -0
- package/dist/Validators/SignerValidator.js.map +1 -0
- package/dist/Validators/Validator.cjs +2 -0
- package/dist/Validators/Validator.cjs.map +1 -0
- package/dist/Validators/Validator.d.ts +31 -0
- package/dist/Validators/Validator.d.ts.map +1 -0
- package/dist/Validators/Validator.js +27 -0
- 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-CKCBwG16.cjs +2 -0
- package/dist/componentInterfaces-CKCBwG16.cjs.map +1 -0
- package/dist/componentInterfaces-DYkaxBda.js +13 -0
- package/dist/componentInterfaces-DYkaxBda.js.map +1 -0
- package/dist/errors.cjs +2 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +441 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +262 -0
- package/dist/errors.js.map +1 -0
- package/dist/generated-BDeDiaCK.js +4625 -0
- package/dist/generated-BDeDiaCK.js.map +1 -0
- package/dist/generated-wKBNvm48.cjs +3 -0
- package/dist/generated-wKBNvm48.cjs.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +113 -0
- 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 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.ts +116 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +30 -0
- package/dist/utils.js.map +1 -0
- package/package.json +211 -0
- package/src/Actions/Action.test.ts +75 -0
- package/src/Actions/Action.ts +61 -0
- package/src/Actions/ContractAction.test.ts +197 -0
- package/src/Actions/ContractAction.ts +301 -0
- package/src/Actions/ERC721MintAction.test.ts +112 -0
- package/src/Actions/ERC721MintAction.ts +292 -0
- package/src/Actions/EventAction.test.ts +205 -0
- package/src/Actions/EventAction.ts +811 -0
- package/src/AllowLists/AllowList.test.ts +64 -0
- package/src/AllowLists/AllowList.ts +60 -0
- package/src/AllowLists/SimpleAllowList.test.ts +52 -0
- package/src/AllowLists/SimpleAllowList.ts +284 -0
- package/src/AllowLists/SimpleDenyList.test.ts +52 -0
- package/src/AllowLists/SimpleDenyList.ts +227 -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 +290 -0
- package/src/BoostCore.test.ts +773 -0
- package/src/BoostCore.ts +1261 -0
- package/src/BoostRegistry.ts +467 -0
- package/src/Budgets/Budget.test.ts +27 -0
- package/src/Budgets/Budget.ts +61 -0
- package/src/Budgets/ManagedBudget.test.ts +154 -0
- package/src/Budgets/ManagedBudget.ts +796 -0
- package/src/Budgets/SimpleBudget.test.ts +152 -0
- package/src/Budgets/SimpleBudget.ts +564 -0
- package/src/Budgets/VestingBudget.test.ts +123 -0
- package/src/Budgets/VestingBudget.ts +602 -0
- package/src/Deployable/Contract.ts +229 -0
- package/src/Deployable/Deployable.ts +250 -0
- package/src/Deployable/DeployableTarget.ts +223 -0
- package/src/Incentives/AllowListIncentive.test.ts +143 -0
- package/src/Incentives/AllowListIncentive.ts +334 -0
- package/src/Incentives/CGDAIncentive.test.ts +132 -0
- package/src/Incentives/CGDAIncentive.ts +468 -0
- package/src/Incentives/ERC1155Incentive.test.ts +87 -0
- package/src/Incentives/ERC1155Incentive.ts +466 -0
- package/src/Incentives/ERC20Incentive.test.ts +130 -0
- package/src/Incentives/ERC20Incentive.ts +482 -0
- package/src/Incentives/ERC20VariableIncentive.test.ts +136 -0
- package/src/Incentives/ERC20VariableIncentive.ts +420 -0
- package/src/Incentives/Incentive.test.ts +92 -0
- package/src/Incentives/Incentive.ts +85 -0
- package/src/Incentives/PointsIncentive.test.ts +139 -0
- package/src/Incentives/PointsIncentive.ts +365 -0
- package/src/Validators/SignerValidator.test.ts +159 -0
- package/src/Validators/SignerValidator.ts +681 -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 +542 -0
- package/src/index.test.ts +40 -0
- package/src/index.ts +53 -0
- package/src/transfers.ts +284 -0
- package/src/utils.test.ts +44 -0
- package/src/utils.ts +198 -0
|
@@ -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 '../../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);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function freshAllowList(fixtures: Fixtures) {
|
|
21
|
+
return function freshAllowList() {
|
|
22
|
+
return fixtures.registry.clone(
|
|
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.clone(
|
|
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 SimpleAllowList 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,60 @@
|
|
|
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 { SimpleAllowList } from './SimpleAllowList';
|
|
11
|
+
import { SimpleDenyList } from './SimpleDenyList';
|
|
12
|
+
|
|
13
|
+
export { SimpleAllowList, SimpleDenyList };
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A union type representing all valid protocol AllowList implementations
|
|
17
|
+
*
|
|
18
|
+
* @export
|
|
19
|
+
* @typedef {AllowList}
|
|
20
|
+
*/
|
|
21
|
+
export type AllowList = SimpleAllowList | SimpleDenyList;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A map of AllowList component interfaces to their constructors.
|
|
25
|
+
*
|
|
26
|
+
* @type {{ "0x2bc9016b": SimpleAllowList; "0x9d585f63": SimpleDenyList; }}
|
|
27
|
+
*/
|
|
28
|
+
export const AllowListByComponentInterface = {
|
|
29
|
+
[ASimpleAllowList as Hex]: SimpleAllowList,
|
|
30
|
+
[ASimpleDenyList as Hex]: SimpleDenyList,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A function that will read a contract's component interface using `getComponentInterface` and return the correct instantiated instance.
|
|
35
|
+
*
|
|
36
|
+
* @export
|
|
37
|
+
* @async
|
|
38
|
+
* @param {DeployableOptions} options
|
|
39
|
+
* @param {Address} address
|
|
40
|
+
* @returns {Promise<SimpleAllowList | SimpleDenyList>}
|
|
41
|
+
* @throws {@link InvalidComponentInterfaceError}
|
|
42
|
+
*/
|
|
43
|
+
export async function allowListFromAddress(
|
|
44
|
+
options: DeployableOptions,
|
|
45
|
+
address: Address,
|
|
46
|
+
) {
|
|
47
|
+
const interfaceId = (await readContract(options.config, {
|
|
48
|
+
abi: aAllowListAbi,
|
|
49
|
+
functionName: 'getComponentInterface',
|
|
50
|
+
address,
|
|
51
|
+
})) as keyof typeof AllowListByComponentInterface;
|
|
52
|
+
const Ctor = AllowListByComponentInterface[interfaceId];
|
|
53
|
+
if (!Ctor) {
|
|
54
|
+
throw new InvalidComponentInterfaceError(
|
|
55
|
+
Object.keys(AllowListByComponentInterface) as Hex[],
|
|
56
|
+
interfaceId as Hex,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return new Ctor(options, address);
|
|
60
|
+
}
|
|
@@ -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 '../../test/helpers';
|
|
9
|
+
import { SimpleAllowList } from './SimpleAllowList';
|
|
10
|
+
|
|
11
|
+
let fixtures: Fixtures;
|
|
12
|
+
|
|
13
|
+
beforeAll(async () => {
|
|
14
|
+
fixtures = await loadFixture(deployFixtures);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
function freshAllowList(fixtures: Fixtures) {
|
|
18
|
+
return function freshAllowList() {
|
|
19
|
+
return fixtures.registry.clone(
|
|
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,284 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readSimpleAllowListIsAllowed,
|
|
3
|
+
simpleAllowListAbi,
|
|
4
|
+
simulateSimpleAllowListGrantRoles,
|
|
5
|
+
simulateSimpleAllowListSetAllowed,
|
|
6
|
+
writeSimpleAllowListGrantRoles,
|
|
7
|
+
writeSimpleAllowListSetAllowed,
|
|
8
|
+
} from '@boostxyz/evm';
|
|
9
|
+
import { bytecode } from '@boostxyz/evm/artifacts/contracts/allowlists/SimpleAllowList.sol/SimpleAllowList.json';
|
|
10
|
+
import { getAccount } from '@wagmi/core';
|
|
11
|
+
import {
|
|
12
|
+
type Address,
|
|
13
|
+
type ContractEventName,
|
|
14
|
+
type Hex,
|
|
15
|
+
encodeAbiParameters,
|
|
16
|
+
zeroAddress,
|
|
17
|
+
zeroHash,
|
|
18
|
+
} from 'viem';
|
|
19
|
+
import type {
|
|
20
|
+
DeployableOptions,
|
|
21
|
+
GenericDeployableParams,
|
|
22
|
+
} from '../Deployable/Deployable';
|
|
23
|
+
import { DeployableTarget } from '../Deployable/DeployableTarget';
|
|
24
|
+
import { DeployableUnknownOwnerProvidedError } from '../errors';
|
|
25
|
+
import {
|
|
26
|
+
type GenericLog,
|
|
27
|
+
type ReadParams,
|
|
28
|
+
RegistryType,
|
|
29
|
+
type WriteParams,
|
|
30
|
+
} from '../utils';
|
|
31
|
+
|
|
32
|
+
export { simpleAllowListAbi };
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Object representation of a {@link SimpleAllowList} initialization payload.
|
|
36
|
+
*
|
|
37
|
+
* @export
|
|
38
|
+
* @interface SimpleAllowListPayload
|
|
39
|
+
* @typedef {SimpleAllowListPayload}
|
|
40
|
+
*/
|
|
41
|
+
export interface SimpleAllowListPayload {
|
|
42
|
+
/**
|
|
43
|
+
* The allow list's owner, given the {@link LIST_MANAGER_ROLE} role.
|
|
44
|
+
*
|
|
45
|
+
* @type {Address}
|
|
46
|
+
*/
|
|
47
|
+
owner: Address;
|
|
48
|
+
/**
|
|
49
|
+
* List of allowed addresses.
|
|
50
|
+
*
|
|
51
|
+
* @type {Address[]}
|
|
52
|
+
*/
|
|
53
|
+
allowed: Address[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A generic `viem.Log` event with support for `SimpleAllowList` event types.
|
|
58
|
+
*
|
|
59
|
+
* @export
|
|
60
|
+
* @typedef {SimpleAllowListLog}
|
|
61
|
+
* @template {ContractEventName<
|
|
62
|
+
* typeof simpleAllowListAbi
|
|
63
|
+
* >} [event=ContractEventName<typeof simpleAllowListAbi>]
|
|
64
|
+
*/
|
|
65
|
+
export type SimpleAllowListLog<
|
|
66
|
+
event extends ContractEventName<
|
|
67
|
+
typeof simpleAllowListAbi
|
|
68
|
+
> = ContractEventName<typeof simpleAllowListAbi>,
|
|
69
|
+
> = GenericLog<typeof simpleAllowListAbi, event>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A constant representing the list manager's role
|
|
73
|
+
*
|
|
74
|
+
* @type {2n}
|
|
75
|
+
*/
|
|
76
|
+
export const LIST_MANAGER_ROLE = 2n;
|
|
77
|
+
/**
|
|
78
|
+
* A simple implementation of an AllowList that checks if a user is authorized based on a list of allowed addresses
|
|
79
|
+
*
|
|
80
|
+
* @export
|
|
81
|
+
* @class SimpleAllowList
|
|
82
|
+
* @typedef {SimpleAllowList}
|
|
83
|
+
* @extends {DeployableTarget<SimpleAllowListPayload>}
|
|
84
|
+
*/
|
|
85
|
+
export class SimpleAllowList extends DeployableTarget<
|
|
86
|
+
SimpleAllowListPayload,
|
|
87
|
+
typeof simpleAllowListAbi
|
|
88
|
+
> {
|
|
89
|
+
public override readonly abi = simpleAllowListAbi;
|
|
90
|
+
/**
|
|
91
|
+
* @inheritdoc
|
|
92
|
+
*
|
|
93
|
+
* @public
|
|
94
|
+
* @static
|
|
95
|
+
* @type {Address}
|
|
96
|
+
*/
|
|
97
|
+
public static override base: Address = import.meta.env
|
|
98
|
+
.VITE_SIMPLE_ALLOWLIST_BASE;
|
|
99
|
+
/**
|
|
100
|
+
* @inheritdoc
|
|
101
|
+
*
|
|
102
|
+
* @public
|
|
103
|
+
* @static
|
|
104
|
+
* @type {RegistryType}
|
|
105
|
+
*/
|
|
106
|
+
public static override registryType: RegistryType = RegistryType.ALLOW_LIST;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Check if a user is authorized.
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
* @async
|
|
113
|
+
* @param {Address} address - The address of the user
|
|
114
|
+
* @param {?ReadParams<typeof simpleAllowListAbi, 'setAllowed'>} [params]
|
|
115
|
+
* @returns {Promise<boolean>} - True if the user is authorized
|
|
116
|
+
*/
|
|
117
|
+
public async isAllowed(
|
|
118
|
+
address: Address,
|
|
119
|
+
params?: ReadParams<typeof simpleAllowListAbi, 'setAllowed'>,
|
|
120
|
+
): Promise<boolean> {
|
|
121
|
+
return await readSimpleAllowListIsAllowed(this._config, {
|
|
122
|
+
address: this.assertValidAddress(),
|
|
123
|
+
args: [address, zeroHash],
|
|
124
|
+
...this.optionallyAttachAccount(),
|
|
125
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
126
|
+
...(params as any),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Set the allowed status of a user. The length of the `users_` and `allowed_` arrays must be the same.
|
|
132
|
+
* This function can only be called by the owner
|
|
133
|
+
*
|
|
134
|
+
* @public
|
|
135
|
+
* @async
|
|
136
|
+
* @param {Address[]} addresses - The list of users to update
|
|
137
|
+
* @param {boolean[]} allowed - The allowed status of each user
|
|
138
|
+
* @param {?ReadParams<typeof simpleAllowListAbi, 'setAllowed'>} [params]
|
|
139
|
+
* @returns {Promise<void>}
|
|
140
|
+
*/
|
|
141
|
+
public async setAllowed(
|
|
142
|
+
addresses: Address[],
|
|
143
|
+
allowed: boolean[],
|
|
144
|
+
params?: WriteParams<typeof simpleAllowListAbi, 'setAllowed'>,
|
|
145
|
+
) {
|
|
146
|
+
return await this.awaitResult(
|
|
147
|
+
this.setAllowedRaw(addresses, allowed, params),
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Set the allowed status of a user. The length of the `users_` and `allowed_` arrays must be the same.
|
|
153
|
+
* This function can only be called by the owner
|
|
154
|
+
*
|
|
155
|
+
* @public
|
|
156
|
+
* @async
|
|
157
|
+
* @param {Address[]} addresses - The list of users to update
|
|
158
|
+
* @param {boolean[]} allowed - The allowed status of each user
|
|
159
|
+
* @param {?ReadParams<typeof simpleAllowListAbi, 'setAllowed'>} [params]
|
|
160
|
+
* @returns {Promise<void>}
|
|
161
|
+
*/
|
|
162
|
+
public async setAllowedRaw(
|
|
163
|
+
addresses: Address[],
|
|
164
|
+
allowed: boolean[],
|
|
165
|
+
params?: ReadParams<typeof simpleAllowListAbi, 'setAllowed'>,
|
|
166
|
+
) {
|
|
167
|
+
const { request, result } = await simulateSimpleAllowListSetAllowed(
|
|
168
|
+
this._config,
|
|
169
|
+
{
|
|
170
|
+
address: this.assertValidAddress(),
|
|
171
|
+
args: [addresses, allowed],
|
|
172
|
+
...this.optionallyAttachAccount(),
|
|
173
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
174
|
+
...(params as any),
|
|
175
|
+
},
|
|
176
|
+
);
|
|
177
|
+
const hash = await writeSimpleAllowListSetAllowed(this._config, request);
|
|
178
|
+
return { hash, result };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Allows the owner to grant `user` `roles`.
|
|
183
|
+
*
|
|
184
|
+
* @public
|
|
185
|
+
* @async
|
|
186
|
+
* @param {Address} address
|
|
187
|
+
* @param {bigint} role
|
|
188
|
+
* @param {?ReadParams<typeof simpleAllowListAbi, 'grantRoles'>} [params]
|
|
189
|
+
* @returns {Promise<void>}
|
|
190
|
+
*/
|
|
191
|
+
public async grantRoles(
|
|
192
|
+
address: Address,
|
|
193
|
+
role: bigint,
|
|
194
|
+
params?: WriteParams<typeof simpleAllowListAbi, 'grantRoles'>,
|
|
195
|
+
) {
|
|
196
|
+
return await this.awaitResult(this.grantRolesRaw(address, role, params));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Allows the owner to grant `user` `roles`.
|
|
201
|
+
*
|
|
202
|
+
* @public
|
|
203
|
+
* @async
|
|
204
|
+
* @param {Address} address
|
|
205
|
+
* @param {bigint} role
|
|
206
|
+
* @param {?ReadParams<typeof simpleAllowListAbi, 'grantRoles'>} [params]
|
|
207
|
+
* @returns {Promise<void>}
|
|
208
|
+
*/
|
|
209
|
+
public async grantRolesRaw(
|
|
210
|
+
address: Address,
|
|
211
|
+
role: bigint,
|
|
212
|
+
params?: ReadParams<typeof simpleAllowListAbi, 'grantRoles'>,
|
|
213
|
+
) {
|
|
214
|
+
const { request, result } = await simulateSimpleAllowListGrantRoles(
|
|
215
|
+
this._config,
|
|
216
|
+
{
|
|
217
|
+
address: this.assertValidAddress(),
|
|
218
|
+
args: [address, role],
|
|
219
|
+
...this.optionallyAttachAccount(),
|
|
220
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
221
|
+
...(params as any),
|
|
222
|
+
},
|
|
223
|
+
);
|
|
224
|
+
const hash = await writeSimpleAllowListGrantRoles(this._config, request);
|
|
225
|
+
return { hash, result };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* @inheritdoc
|
|
230
|
+
*
|
|
231
|
+
* @public
|
|
232
|
+
* @param {?SimpleAllowListPayload} [_payload]
|
|
233
|
+
* @param {?DeployableOptions} [_options]
|
|
234
|
+
* @returns {GenericDeployableParams}
|
|
235
|
+
*/
|
|
236
|
+
public override buildParameters(
|
|
237
|
+
_payload?: SimpleAllowListPayload,
|
|
238
|
+
_options?: DeployableOptions,
|
|
239
|
+
): GenericDeployableParams {
|
|
240
|
+
const [payload, options] = this.validateDeploymentConfig(
|
|
241
|
+
_payload,
|
|
242
|
+
_options,
|
|
243
|
+
);
|
|
244
|
+
if (!payload.owner || payload.owner === zeroAddress) {
|
|
245
|
+
const owner = options.account
|
|
246
|
+
? options.account.address
|
|
247
|
+
: options.config
|
|
248
|
+
? getAccount(options.config).address
|
|
249
|
+
: this._account?.address;
|
|
250
|
+
if (owner) {
|
|
251
|
+
payload.owner = owner;
|
|
252
|
+
} else {
|
|
253
|
+
throw new DeployableUnknownOwnerProvidedError();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
abi: simpleAllowListAbi,
|
|
258
|
+
bytecode: bytecode as Hex,
|
|
259
|
+
args: [prepareSimpleAllowListPayload(payload)],
|
|
260
|
+
...this.optionallyAttachAccount(options.account),
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Given a {@link SimpleAllowListPayload}, properly encode the initialization payload.
|
|
267
|
+
*
|
|
268
|
+
* @param {SimpleAllowListPayload} param0
|
|
269
|
+
* @param {Address} param0.owner - The allow list's owner, given the {@link LIST_MANAGER_ROLE} role.
|
|
270
|
+
* @param {Address[]} param0.allowed - List of allowed addresses.
|
|
271
|
+
* @returns {Hex}
|
|
272
|
+
*/
|
|
273
|
+
export function prepareSimpleAllowListPayload({
|
|
274
|
+
owner,
|
|
275
|
+
allowed,
|
|
276
|
+
}: SimpleAllowListPayload) {
|
|
277
|
+
return encodeAbiParameters(
|
|
278
|
+
[
|
|
279
|
+
{ type: 'address', name: 'owner' },
|
|
280
|
+
{ type: 'address[]', name: 'allowed' },
|
|
281
|
+
],
|
|
282
|
+
[owner, allowed],
|
|
283
|
+
);
|
|
284
|
+
}
|
|
@@ -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 '../../test/helpers';
|
|
9
|
+
import { SimpleDenyList } from './SimpleDenyList';
|
|
10
|
+
|
|
11
|
+
let fixtures: Fixtures;
|
|
12
|
+
|
|
13
|
+
beforeAll(async () => {
|
|
14
|
+
fixtures = await loadFixture(deployFixtures);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
function freshDenyList(fixtures: Fixtures) {
|
|
18
|
+
return function freshDenyList() {
|
|
19
|
+
return fixtures.registry.clone(
|
|
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
|
+
});
|