@boostxyz/sdk 0.0.0-alpha.3 → 0.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/dist/Actions/Action.cjs +2 -1
  2. package/dist/Actions/Action.cjs.map +1 -0
  3. package/dist/Actions/Action.d.ts +1 -1
  4. package/dist/Actions/Action.d.ts.map +1 -1
  5. package/dist/Actions/Action.js +15 -13
  6. package/dist/Actions/Action.js.map +1 -0
  7. package/dist/Actions/EventAction.cjs +1 -0
  8. package/dist/Actions/EventAction.cjs.map +1 -0
  9. package/dist/Actions/EventAction.js +1 -0
  10. package/dist/Actions/EventAction.js.map +1 -0
  11. package/dist/AllowLists/AllowList.cjs +2 -1
  12. package/dist/AllowLists/AllowList.cjs.map +1 -0
  13. package/dist/AllowLists/AllowList.d.ts +1 -2
  14. package/dist/AllowLists/AllowList.d.ts.map +1 -1
  15. package/dist/AllowLists/AllowList.js +16 -14
  16. package/dist/AllowLists/AllowList.js.map +1 -0
  17. package/dist/AllowLists/SimpleAllowList.cjs +1 -0
  18. package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
  19. package/dist/AllowLists/SimpleAllowList.js +1 -0
  20. package/dist/AllowLists/SimpleAllowList.js.map +1 -0
  21. package/dist/AllowLists/SimpleDenyList.cjs +1 -0
  22. package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
  23. package/dist/AllowLists/SimpleDenyList.js +1 -0
  24. package/dist/AllowLists/SimpleDenyList.js.map +1 -0
  25. package/dist/Auth/Auth.cjs +1 -0
  26. package/dist/Auth/Auth.cjs.map +1 -0
  27. package/dist/Auth/Auth.js +1 -0
  28. package/dist/Auth/Auth.js.map +1 -0
  29. package/dist/Auth/PassthroughAuth.cjs +1 -0
  30. package/dist/Auth/PassthroughAuth.cjs.map +1 -0
  31. package/dist/Auth/PassthroughAuth.js +1 -0
  32. package/dist/Auth/PassthroughAuth.js.map +1 -0
  33. package/dist/Boost.cjs +1 -0
  34. package/dist/Boost.cjs.map +1 -0
  35. package/dist/Boost.js +1 -0
  36. package/dist/Boost.js.map +1 -0
  37. package/dist/BoostCore.cjs +1 -0
  38. package/dist/BoostCore.cjs.map +1 -0
  39. package/dist/BoostCore.js +1 -0
  40. package/dist/BoostCore.js.map +1 -0
  41. package/dist/BoostRegistry.cjs +1 -0
  42. package/dist/BoostRegistry.cjs.map +1 -0
  43. package/dist/BoostRegistry.js +1 -0
  44. package/dist/BoostRegistry.js.map +1 -0
  45. package/dist/Budgets/Budget.cjs +2 -1
  46. package/dist/Budgets/Budget.cjs.map +1 -0
  47. package/dist/Budgets/Budget.d.ts +1 -1
  48. package/dist/Budgets/Budget.d.ts.map +1 -1
  49. package/dist/Budgets/Budget.js +14 -12
  50. package/dist/Budgets/Budget.js.map +1 -0
  51. package/dist/Budgets/ManagedBudget.cjs +1 -0
  52. package/dist/Budgets/ManagedBudget.cjs.map +1 -0
  53. package/dist/Budgets/ManagedBudget.js +1 -0
  54. package/dist/Budgets/ManagedBudget.js.map +1 -0
  55. package/dist/Deployable/Contract.cjs +1 -0
  56. package/dist/Deployable/Contract.cjs.map +1 -0
  57. package/dist/Deployable/Contract.js +1 -0
  58. package/dist/Deployable/Contract.js.map +1 -0
  59. package/dist/Deployable/Deployable.cjs +1 -0
  60. package/dist/Deployable/Deployable.cjs.map +1 -0
  61. package/dist/Deployable/Deployable.js +1 -0
  62. package/dist/Deployable/Deployable.js.map +1 -0
  63. package/dist/Deployable/DeployableTarget.cjs +1 -0
  64. package/dist/Deployable/DeployableTarget.cjs.map +1 -0
  65. package/dist/Deployable/DeployableTarget.js +1 -0
  66. package/dist/Deployable/DeployableTarget.js.map +1 -0
  67. package/dist/Incentives/AllowListIncentive.cjs +1 -0
  68. package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
  69. package/dist/Incentives/AllowListIncentive.js +1 -0
  70. package/dist/Incentives/AllowListIncentive.js.map +1 -0
  71. package/dist/Incentives/CGDAIncentive.cjs +1 -0
  72. package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
  73. package/dist/Incentives/CGDAIncentive.js +1 -0
  74. package/dist/Incentives/CGDAIncentive.js.map +1 -0
  75. package/dist/Incentives/ERC20Incentive.cjs +1 -0
  76. package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
  77. package/dist/Incentives/ERC20Incentive.js +1 -0
  78. package/dist/Incentives/ERC20Incentive.js.map +1 -0
  79. package/dist/Incentives/Incentive.cjs +2 -1
  80. package/dist/Incentives/Incentive.cjs.map +1 -0
  81. package/dist/Incentives/Incentive.d.ts +1 -4
  82. package/dist/Incentives/Incentive.d.ts.map +1 -1
  83. package/dist/Incentives/Incentive.js +39 -36
  84. package/dist/Incentives/Incentive.js.map +1 -0
  85. package/dist/Incentives/PointsIncentive.cjs +1 -0
  86. package/dist/Incentives/PointsIncentive.cjs.map +1 -0
  87. package/dist/Incentives/PointsIncentive.js +1 -0
  88. package/dist/Incentives/PointsIncentive.js.map +1 -0
  89. package/dist/Validators/SignerValidator.cjs +1 -0
  90. package/dist/Validators/SignerValidator.cjs.map +1 -0
  91. package/dist/Validators/SignerValidator.js +1 -0
  92. package/dist/Validators/SignerValidator.js.map +1 -0
  93. package/dist/Validators/Validator.cjs +2 -1
  94. package/dist/Validators/Validator.cjs.map +1 -0
  95. package/dist/Validators/Validator.d.ts +1 -1
  96. package/dist/Validators/Validator.d.ts.map +1 -1
  97. package/dist/Validators/Validator.js +9 -7
  98. package/dist/Validators/Validator.js.map +1 -0
  99. package/dist/componentInterfaces-CKCBwG16.cjs +2 -0
  100. package/dist/componentInterfaces-CKCBwG16.cjs.map +1 -0
  101. package/dist/componentInterfaces-DYkaxBda.js +13 -0
  102. package/dist/componentInterfaces-DYkaxBda.js.map +1 -0
  103. package/dist/errors.cjs +1 -0
  104. package/dist/errors.cjs.map +1 -0
  105. package/dist/errors.js +1 -0
  106. package/dist/errors.js.map +1 -0
  107. package/dist/generated-Cd-Fe7W7.cjs +1 -0
  108. package/dist/generated-Cd-Fe7W7.cjs.map +1 -0
  109. package/dist/generated-DGpIVcv5.js +1 -0
  110. package/dist/generated-DGpIVcv5.js.map +1 -0
  111. package/dist/index.cjs +1 -0
  112. package/dist/index.cjs.map +1 -0
  113. package/dist/index.js +1 -0
  114. package/dist/index.js.map +1 -0
  115. package/dist/utils.cjs +1 -0
  116. package/dist/utils.cjs.map +1 -0
  117. package/dist/utils.d.ts +1 -1
  118. package/dist/utils.d.ts.map +1 -1
  119. package/dist/utils.js +1 -0
  120. package/dist/utils.js.map +1 -0
  121. package/package.json +5 -3
  122. package/src/Actions/Action.test.ts +77 -0
  123. package/src/Actions/Action.ts +61 -0
  124. package/src/Actions/ContractAction.test.ts +199 -0
  125. package/src/Actions/ContractAction.ts +238 -0
  126. package/src/Actions/ERC721MintAction.test.ts +112 -0
  127. package/src/Actions/ERC721MintAction.ts +238 -0
  128. package/src/Actions/EventAction.test.ts +182 -0
  129. package/src/Actions/EventAction.ts +382 -0
  130. package/src/AllowLists/AllowList.test.ts +64 -0
  131. package/src/AllowLists/AllowList.ts +60 -0
  132. package/src/AllowLists/SimpleAllowList.test.ts +52 -0
  133. package/src/AllowLists/SimpleAllowList.ts +240 -0
  134. package/src/AllowLists/SimpleDenyList.test.ts +52 -0
  135. package/src/AllowLists/SimpleDenyList.ts +289 -0
  136. package/src/Auth/Auth.ts +11 -0
  137. package/src/Auth/PassthroughAuth.test.ts +12 -0
  138. package/src/Auth/PassthroughAuth.ts +80 -0
  139. package/src/Boost.ts +155 -0
  140. package/src/BoostCore.test.ts +846 -0
  141. package/src/BoostCore.ts +1192 -0
  142. package/src/BoostRegistry.ts +449 -0
  143. package/src/Budgets/Budget.test.ts +27 -0
  144. package/src/Budgets/Budget.ts +61 -0
  145. package/src/Budgets/ManagedBudget.test.ts +154 -0
  146. package/src/Budgets/ManagedBudget.ts +743 -0
  147. package/src/Budgets/SimpleBudget.test.ts +152 -0
  148. package/src/Budgets/SimpleBudget.ts +521 -0
  149. package/src/Budgets/VestingBudget.test.ts +123 -0
  150. package/src/Budgets/VestingBudget.ts +532 -0
  151. package/src/Deployable/Contract.ts +229 -0
  152. package/src/Deployable/Deployable.ts +244 -0
  153. package/src/Deployable/DeployableTarget.ts +210 -0
  154. package/src/Incentives/AllowListIncentive.test.ts +146 -0
  155. package/src/Incentives/AllowListIncentive.ts +290 -0
  156. package/src/Incentives/CGDAIncentive.test.ts +136 -0
  157. package/src/Incentives/CGDAIncentive.ts +364 -0
  158. package/src/Incentives/ERC1155Incentive.test.ts +98 -0
  159. package/src/Incentives/ERC1155Incentive.ts +384 -0
  160. package/src/Incentives/ERC20Incentive.test.ts +141 -0
  161. package/src/Incentives/ERC20Incentive.ts +417 -0
  162. package/src/Incentives/ERC20VariableIncentive.test.ts +156 -0
  163. package/src/Incentives/ERC20VariableIncentive.ts +368 -0
  164. package/src/Incentives/Incentive.test.ts +92 -0
  165. package/src/Incentives/Incentive.ts +85 -0
  166. package/src/Incentives/PointsIncentive.test.ts +142 -0
  167. package/src/Incentives/PointsIncentive.ts +303 -0
  168. package/src/Validators/SignerValidator.test.ts +163 -0
  169. package/src/Validators/SignerValidator.ts +272 -0
  170. package/src/Validators/Validator.test.ts +21 -0
  171. package/src/Validators/Validator.ts +55 -0
  172. package/src/errors.ts +524 -0
  173. package/src/index.test.ts +40 -0
  174. package/src/index.ts +50 -0
  175. package/src/utils.test.ts +44 -0
  176. package/src/utils.ts +2247 -0
@@ -0,0 +1,240 @@
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
+ zeroAddress,
16
+ zeroHash,
17
+ } from 'viem';
18
+ import type {
19
+ DeployableOptions,
20
+ GenericDeployableParams,
21
+ } from '../Deployable/Deployable';
22
+ import { DeployableTarget } from '../Deployable/DeployableTarget';
23
+ import { DeployableUnknownOwnerProvidedError } from '../errors';
24
+ import {
25
+ type GenericLog,
26
+ type ReadParams,
27
+ RegistryType,
28
+ type SimpleAllowListPayload,
29
+ prepareSimpleAllowListPayload,
30
+ } from '../utils';
31
+
32
+ export { simpleAllowListAbi };
33
+ export type { SimpleAllowListPayload };
34
+
35
+ /**
36
+ * A generic `viem.Log` event with support for `SimpleAllowList` event types.
37
+ *
38
+ * @export
39
+ * @typedef {SimpleAllowListLog}
40
+ * @template {ContractEventName<
41
+ * typeof simpleAllowListAbi
42
+ * >} [event=ContractEventName<typeof simpleAllowListAbi>]
43
+ */
44
+ export type SimpleAllowListLog<
45
+ event extends ContractEventName<
46
+ typeof simpleAllowListAbi
47
+ > = ContractEventName<typeof simpleAllowListAbi>,
48
+ > = GenericLog<typeof simpleAllowListAbi, event>;
49
+
50
+ /**
51
+ * A constant representing the list manager's role
52
+ *
53
+ * @type {2n}
54
+ */
55
+ export const LIST_MANAGER_ROLE = 2n;
56
+ /**
57
+ * A simple implementation of an AllowList that checks if a user is authorized based on a list of allowed addresses
58
+ *
59
+ * @export
60
+ * @class SimpleAllowList
61
+ * @typedef {SimpleAllowList}
62
+ * @extends {DeployableTarget<SimpleAllowListPayload>}
63
+ */
64
+ export class SimpleAllowList extends DeployableTarget<
65
+ SimpleAllowListPayload,
66
+ typeof simpleAllowListAbi
67
+ > {
68
+ public override readonly abi = simpleAllowListAbi;
69
+ /**
70
+ * @inheritdoc
71
+ *
72
+ * @public
73
+ * @static
74
+ * @type {Address}
75
+ */
76
+ public static override base: Address = import.meta.env
77
+ .VITE_SIMPLE_ALLOWLIST_BASE;
78
+ /**
79
+ * @inheritdoc
80
+ *
81
+ * @public
82
+ * @static
83
+ * @type {RegistryType}
84
+ */
85
+ public static override registryType: RegistryType = RegistryType.ALLOW_LIST;
86
+
87
+ /**
88
+ * Check if a user is authorized.
89
+ *
90
+ * @public
91
+ * @async
92
+ * @param {Address} address - The address of the user
93
+ * @param {?ReadParams<typeof simpleAllowListAbi, 'setAllowed'>} [params]
94
+ * @returns {Promise<boolean>} - True if the user is authorized
95
+ */
96
+ public async isAllowed(
97
+ address: Address,
98
+ params?: ReadParams<typeof simpleAllowListAbi, 'setAllowed'>,
99
+ ): Promise<boolean> {
100
+ return await readSimpleAllowListIsAllowed(this._config, {
101
+ address: this.assertValidAddress(),
102
+ args: [address, zeroHash],
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
+ }
108
+
109
+ /**
110
+ * Set the allowed status of a user. The length of the `users_` and `allowed_` arrays must be the same.
111
+ * This function can only be called by the owner
112
+ *
113
+ * @public
114
+ * @async
115
+ * @param {Address[]} addresses - The list of users to update
116
+ * @param {boolean[]} allowed - The allowed status of each user
117
+ * @param {?ReadParams<typeof simpleAllowListAbi, 'setAllowed'>} [params]
118
+ * @returns {Promise<void>}
119
+ */
120
+ public async setAllowed(
121
+ addresses: Address[],
122
+ allowed: boolean[],
123
+ params?: ReadParams<typeof simpleAllowListAbi, 'setAllowed'>,
124
+ ) {
125
+ return this.awaitResult(this.setAllowedRaw(addresses, allowed, params));
126
+ }
127
+
128
+ /**
129
+ * Set the allowed status of a user. The length of the `users_` and `allowed_` arrays must be the same.
130
+ * This function can only be called by the owner
131
+ *
132
+ * @public
133
+ * @async
134
+ * @param {Address[]} addresses - The list of users to update
135
+ * @param {boolean[]} allowed - The allowed status of each user
136
+ * @param {?ReadParams<typeof simpleAllowListAbi, 'setAllowed'>} [params]
137
+ * @returns {Promise<void>}
138
+ */
139
+ public async setAllowedRaw(
140
+ addresses: Address[],
141
+ allowed: boolean[],
142
+ params?: ReadParams<typeof simpleAllowListAbi, 'setAllowed'>,
143
+ ) {
144
+ const { request, result } = await simulateSimpleAllowListSetAllowed(
145
+ this._config,
146
+ {
147
+ address: this.assertValidAddress(),
148
+ args: [addresses, allowed],
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
+ const hash = await writeSimpleAllowListSetAllowed(this._config, request);
155
+ return { hash, result };
156
+ }
157
+
158
+ /**
159
+ * Allows the owner to grant `user` `roles`.
160
+ *
161
+ * @public
162
+ * @async
163
+ * @param {Address} address
164
+ * @param {bigint} role
165
+ * @param {?ReadParams<typeof simpleAllowListAbi, 'grantRoles'>} [params]
166
+ * @returns {Promise<void>}
167
+ */
168
+ public async grantRoles(
169
+ address: Address,
170
+ role: bigint,
171
+ params?: ReadParams<typeof simpleAllowListAbi, 'grantRoles'>,
172
+ ) {
173
+ return this.awaitResult(this.grantRolesRaw(address, role, params));
174
+ }
175
+
176
+ /**
177
+ * Allows the owner to grant `user` `roles`.
178
+ *
179
+ * @public
180
+ * @async
181
+ * @param {Address} address
182
+ * @param {bigint} role
183
+ * @param {?ReadParams<typeof simpleAllowListAbi, 'grantRoles'>} [params]
184
+ * @returns {Promise<void>}
185
+ */
186
+ public async grantRolesRaw(
187
+ address: Address,
188
+ role: bigint,
189
+ params?: ReadParams<typeof simpleAllowListAbi, 'grantRoles'>,
190
+ ) {
191
+ const { request, result } = await simulateSimpleAllowListGrantRoles(
192
+ this._config,
193
+ {
194
+ address: this.assertValidAddress(),
195
+ args: [address, role],
196
+ ...this.optionallyAttachAccount(),
197
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
198
+ ...(params as any),
199
+ },
200
+ );
201
+ const hash = await writeSimpleAllowListGrantRoles(this._config, request);
202
+ return { hash, result };
203
+ }
204
+
205
+ /**
206
+ * @inheritdoc
207
+ *
208
+ * @public
209
+ * @param {?SimpleAllowListPayload} [_payload]
210
+ * @param {?DeployableOptions} [_options]
211
+ * @returns {GenericDeployableParams}
212
+ */
213
+ public override buildParameters(
214
+ _payload?: SimpleAllowListPayload,
215
+ _options?: DeployableOptions,
216
+ ): GenericDeployableParams {
217
+ const [payload, options] = this.validateDeploymentConfig(
218
+ _payload,
219
+ _options,
220
+ );
221
+ if (!payload.owner || payload.owner === zeroAddress) {
222
+ const owner = options.account
223
+ ? options.account.address
224
+ : options.config
225
+ ? getAccount(options.config).address
226
+ : this._account?.address;
227
+ if (owner) {
228
+ payload.owner = owner;
229
+ } else {
230
+ throw new DeployableUnknownOwnerProvidedError();
231
+ }
232
+ }
233
+ return {
234
+ abi: simpleAllowListAbi,
235
+ bytecode: bytecode as Hex,
236
+ args: [prepareSimpleAllowListPayload(payload)],
237
+ ...this.optionallyAttachAccount(options.account),
238
+ };
239
+ }
240
+ }
@@ -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
+ new fixtures.bases.SimpleDenyList(defaultOptions, {
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
+ });
@@ -0,0 +1,289 @@
1
+ import {
2
+ readSimpleDenyListIsAllowed,
3
+ simpleDenyListAbi,
4
+ simulateSimpleDenyListSetDenied,
5
+ writeSimpleDenyListSetDenied,
6
+ } from '@boostxyz/evm';
7
+ import { bytecode } from '@boostxyz/evm/artifacts/contracts/allowlists/SimpleDenyList.sol/SimpleDenyList.json';
8
+ import { getAccount } from '@wagmi/core';
9
+ import {
10
+ type Address,
11
+ type ContractEventName,
12
+ type Hex,
13
+ zeroAddress,
14
+ zeroHash,
15
+ } from 'viem';
16
+ import type {
17
+ DeployableOptions,
18
+ GenericDeployableParams,
19
+ } from '../Deployable/Deployable';
20
+ import { DeployableTarget } from '../Deployable/DeployableTarget';
21
+ import { DeployableUnknownOwnerProvidedError } from '../errors';
22
+ import {
23
+ type GenericLog,
24
+ type ReadParams,
25
+ RegistryType,
26
+ type SimpleDenyListPayload,
27
+ type WriteParams,
28
+ prepareSimpleDenyListPayload,
29
+ } from '../utils';
30
+
31
+ export { simpleDenyListAbi };
32
+ export type { SimpleDenyListPayload };
33
+
34
+ /**
35
+ * A generic `viem.Log` event with support for `SimpleDenyList` event types.
36
+ *
37
+ * @export
38
+ * @typedef {SimpleDenyListLog}
39
+ * @template {ContractEventName<typeof simpleDenyListAbi>} [event=ContractEventName<
40
+ * typeof simpleDenyListAbi
41
+ * >]
42
+ */
43
+ export type SimpleDenyListLog<
44
+ event extends ContractEventName<typeof simpleDenyListAbi> = ContractEventName<
45
+ typeof simpleDenyListAbi
46
+ >,
47
+ > = GenericLog<typeof simpleDenyListAbi, event>;
48
+
49
+ /**
50
+ * A simple implementation of an AllowList that implicitly allows all addresses except those explicitly added to the deny list
51
+ *
52
+ * @export
53
+ * @class SimpleDenyList
54
+ * @typedef {SimpleDenyList}
55
+ * @extends {DeployableTarget<SimpleDenyListPayload>}
56
+ */
57
+ export class SimpleDenyList extends DeployableTarget<
58
+ SimpleDenyListPayload,
59
+ typeof simpleDenyListAbi
60
+ > {
61
+ public override readonly abi = simpleDenyListAbi;
62
+ /**
63
+ * @inheritdoc
64
+ *
65
+ * @public
66
+ * @static
67
+ * @type {Address}
68
+ */
69
+ public static override base: Address = import.meta.env
70
+ .VITE_SIMPLE_DENYLIST_BASE;
71
+ /**
72
+ * @inheritdoc
73
+ *
74
+ * @public
75
+ * @static
76
+ * @type {RegistryType}
77
+ */
78
+ public static override registryType: RegistryType = RegistryType.ALLOW_LIST;
79
+
80
+ /**
81
+ * Check if a user is authorized (i.e. not denied)
82
+ *
83
+ * @public
84
+ * @async
85
+ * @param {Address} address - The address of the user
86
+ * @param {?ReadParams<typeof simpleDenyListAbi, 'isAllowed'>} [params]
87
+ * @returns {Promise<boolean>} - True if the user is authorized
88
+ */
89
+ public async isAllowed(
90
+ address: Address,
91
+ params?: ReadParams<typeof simpleDenyListAbi, 'isAllowed'>,
92
+ ): Promise<boolean> {
93
+ return await readSimpleDenyListIsAllowed(this._config, {
94
+ address: this.assertValidAddress(),
95
+ args: [address, zeroHash],
96
+ ...this.optionallyAttachAccount(),
97
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
98
+ ...(params as any),
99
+ });
100
+ }
101
+
102
+ /**
103
+ * Set the denied status of a user. The length of the `users_` and `denied_` arrays must be the same. This function can only be called by the owner
104
+ *
105
+ * @public
106
+ * @async
107
+ * @param {Address[]} addresses - The list of users to update
108
+ * @param {boolean[]} allowed - The denied status of each user
109
+ * @param {?WriteParams<typeof simpleDenyListAbi, 'setDenied'>} [params]
110
+ * @returns {unknown}
111
+ */
112
+ public async setDenied(
113
+ addresses: Address[],
114
+ allowed: boolean[],
115
+ params?: WriteParams<typeof simpleDenyListAbi, 'setDenied'>,
116
+ ) {
117
+ return this.awaitResult(this.setDeniedRaw(addresses, allowed, params));
118
+ }
119
+
120
+ /**
121
+ * Set the denied status of a user. The length of the `users_` and `denied_` arrays must be the same. This function can only be called by the owner
122
+ *
123
+ * @public
124
+ * @async
125
+ * @param {Address[]} addresses - The list of users to update
126
+ * @param {boolean[]} allowed - The denied status of each user
127
+ * @param {?WriteParams<typeof simpleDenyListAbi, 'setDenied'>} [params]
128
+ * @returns {unknown}
129
+ */
130
+ public async setDeniedRaw(
131
+ addresses: Address[],
132
+ allowed: boolean[],
133
+ params?: WriteParams<typeof simpleDenyListAbi, 'setDenied'>,
134
+ ) {
135
+ const { request, result } = await simulateSimpleDenyListSetDenied(
136
+ this._config,
137
+ {
138
+ address: this.assertValidAddress(),
139
+ args: [addresses, allowed],
140
+ ...this.optionallyAttachAccount(),
141
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
142
+ ...(params as any),
143
+ },
144
+ );
145
+ const hash = await writeSimpleDenyListSetDenied(this._config, request);
146
+ return { hash, result };
147
+ }
148
+
149
+ // /**
150
+ // * A typed wrapper for (viem.getLogs)[https://viem.sh/docs/actions/public/getLogs#getlogs].
151
+ // * Accepts `eventName` and `eventNames` as optional parameters to narrow the returned log types.
152
+ // * @example
153
+ // * ```ts
154
+ // * const logs = contract.getLogs({ eventName: 'EventName' })
155
+ // * const logs = contract.getLogs({ eventNames: ['EventName'] })
156
+ // * ```
157
+ // * @public
158
+ // * @async
159
+ // * @template {ContractEventName<typeof simpleDenyListAbi>} event
160
+ // * @template {ExtractAbiEvent<
161
+ // * typeof simpleDenyListAbi,
162
+ // * event
163
+ // * >} [abiEvent=ExtractAbiEvent<typeof simpleDenyListAbi, event>]
164
+ // * @param {?Omit<
165
+ // * GetLogsParams<typeof simpleDenyListAbi, event, abiEvent, abiEvent[]>,
166
+ // * 'event' | 'events'
167
+ // * > & {
168
+ // * eventName?: event;
169
+ // * eventNames?: event[];
170
+ // * }} [params]
171
+ // * @returns {Promise<GetLogsReturnType<abiEvent, abiEvent[]>>}
172
+ // */
173
+ // public async getLogs<
174
+ // event extends ContractEventName<typeof simpleDenyListAbi>,
175
+ // const abiEvent extends ExtractAbiEvent<
176
+ // typeof simpleDenyListAbi,
177
+ // event
178
+ // > = ExtractAbiEvent<typeof simpleDenyListAbi, event>,
179
+ // >(
180
+ // params?: Omit<
181
+ // GetLogsParams<typeof simpleDenyListAbi, event, abiEvent, abiEvent[]>,
182
+ // 'event' | 'events'
183
+ // > & {
184
+ // eventName?: event;
185
+ // eventNames?: event[];
186
+ // },
187
+ // ): Promise<GetLogsReturnType<abiEvent, abiEvent[]>> {
188
+ // return getLogs(this._config.getClient({ chainId: params?.chainId }), {
189
+ // // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wag
190
+ // ...(params as any),
191
+ // ...(params?.eventName
192
+ // ? {
193
+ // event: getAbiItem({
194
+ // abi: simpleDenyListAbi,
195
+ // name: params.eventName,
196
+ // // biome-ignore lint/suspicious/noExplicitAny: awkward abi intersection issue
197
+ // } as any),
198
+ // }
199
+ // : {}),
200
+ // ...(params?.eventNames
201
+ // ? {
202
+ // events: params.eventNames.map((name) =>
203
+ // getAbiItem({
204
+ // abi: simpleDenyListAbi,
205
+ // name,
206
+ // // biome-ignore lint/suspicious/noExplicitAny: awkward abi intersection issue
207
+ // } as any),
208
+ // ),
209
+ // }
210
+ // : {}),
211
+ // address: this.assertValidAddress(),
212
+ // });
213
+ // }
214
+
215
+ // /**
216
+ // * A typed wrapper for `wagmi.watchContractEvent`
217
+ // *
218
+ // * @public
219
+ // * @async
220
+ // * @template {ContractEventName<typeof simpleDenyListAbi>} event
221
+ // * @param {(log: SimpleDenyListLog<event>) => unknown} cb
222
+ // * @param {?WatchParams<typeof simpleDenyListAbi, event> & {
223
+ // * eventName?: event;
224
+ // * }} [params]
225
+ // * @returns {unknown, params?: any) => unknown} Unsubscribe function
226
+ // */
227
+ // public async subscribe<
228
+ // event extends ContractEventName<typeof simpleDenyListAbi>,
229
+ // >(
230
+ // cb: (log: SimpleDenyListLog<event>) => unknown,
231
+ // params?: WatchParams<typeof simpleDenyListAbi, event> & {
232
+ // eventName?: event;
233
+ // },
234
+ // ) {
235
+ // return watchContractEvent<
236
+ // typeof this._config,
237
+ // (typeof this._config)['chains'][number]['id'],
238
+ // typeof simpleDenyListAbi,
239
+ // event
240
+ // >(this._config, {
241
+ // // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
242
+ // ...(params as any),
243
+ // eventName: params?.eventName,
244
+ // abi: simpleDenyListAbi,
245
+ // address: this.assertValidAddress(),
246
+ // onLogs: (logs) => {
247
+ // for (let l of logs) {
248
+ // cb(l as unknown as SimpleDenyListLog<event>);
249
+ // }
250
+ // },
251
+ // });
252
+ // }
253
+
254
+ /**
255
+ * @inheritdoc
256
+ *
257
+ * @public
258
+ * @param {?SimpleDenyListPayload} [_payload]
259
+ * @param {?DeployableOptions} [_options]
260
+ * @returns {GenericDeployableParams}
261
+ */
262
+ public override buildParameters(
263
+ _payload?: SimpleDenyListPayload,
264
+ _options?: DeployableOptions,
265
+ ): GenericDeployableParams {
266
+ const [payload, options] = this.validateDeploymentConfig(
267
+ _payload,
268
+ _options,
269
+ );
270
+ if (!payload.owner || payload.owner === zeroAddress) {
271
+ const owner = options.account
272
+ ? options.account.address
273
+ : options.config
274
+ ? getAccount(options.config).address
275
+ : this._account?.address;
276
+ if (owner) {
277
+ payload.owner = owner;
278
+ } else {
279
+ throw new DeployableUnknownOwnerProvidedError();
280
+ }
281
+ }
282
+ return {
283
+ abi: simpleDenyListAbi,
284
+ bytecode: bytecode as Hex,
285
+ args: [prepareSimpleDenyListPayload(payload)],
286
+ ...this.optionallyAttachAccount(options.account),
287
+ };
288
+ }
289
+ }
@@ -0,0 +1,11 @@
1
+ import { PassthroughAuth } from './PassthroughAuth';
2
+
3
+ export { PassthroughAuth };
4
+
5
+ /**
6
+ * A union type representing all valid protocol Auth implementations
7
+ *
8
+ * @export
9
+ * @typedef {Auth}
10
+ */
11
+ export type Auth = PassthroughAuth;
@@ -0,0 +1,12 @@
1
+ import { zeroAddress } from 'viem';
2
+ import { describe, expect, test } from 'vitest';
3
+ import { defaultOptions } from '../../test/helpers';
4
+ import { PassthroughAuth } from './PassthroughAuth';
5
+
6
+ describe('PassthroughAuth', () => {
7
+ test('can successfully be deployed', async () => {
8
+ const auth = new PassthroughAuth(defaultOptions);
9
+ await auth.deploy();
10
+ expect(await auth.isAuthorized(zeroAddress)).toBe(true);
11
+ });
12
+ });
@@ -0,0 +1,80 @@
1
+ import {
2
+ passthroughAuthAbi,
3
+ readPassthroughAuthIsAuthorized,
4
+ } from '@boostxyz/evm';
5
+ import { bytecode } from '@boostxyz/evm/artifacts/contracts/auth/PassthroughAuth.sol/PassthroughAuth.json';
6
+ import type { Address, ContractEventName, Hex } from 'viem';
7
+ import {
8
+ Deployable,
9
+ type DeployableOptions,
10
+ type GenericDeployableParams,
11
+ } from '../Deployable/Deployable';
12
+ import { DeployableTarget } from '../Deployable/DeployableTarget';
13
+ import type { GenericLog, ReadParams } from '../utils';
14
+
15
+ export { passthroughAuthAbi };
16
+
17
+ /**
18
+ * A generic `viem.Log` event with support for `PassthroughAuth` event types.
19
+ *
20
+ * @export
21
+ * @typedef {PassthroughAuthLog}
22
+ * @template {ContractEventName<
23
+ * typeof passthroughAuthAbi
24
+ * >} [event=ContractEventName<typeof passthroughAuthAbi>]
25
+ */
26
+ export type PassthroughAuthLog<
27
+ event extends ContractEventName<
28
+ typeof passthroughAuthAbi
29
+ > = ContractEventName<typeof passthroughAuthAbi>,
30
+ > = GenericLog<typeof passthroughAuthAbi, event>;
31
+
32
+ /**
33
+ * A simple implementation of a Validator that verifies a given signature and checks the recovered address against a set of authorized signers
34
+ *
35
+ * @export
36
+ * @class PassthroughAuth
37
+ * @typedef {PassthroughAuth}
38
+ * @extends {DeployableTarget<PassthroughAuthPayload>}
39
+ */
40
+ export class PassthroughAuth extends Deployable<
41
+ // biome-ignore lint/suspicious/noExplicitAny: takes no parameters
42
+ any,
43
+ typeof passthroughAuthAbi
44
+ > {
45
+ public override readonly abi = passthroughAuthAbi;
46
+
47
+ public async isAuthorized(
48
+ address: Address,
49
+ params?: ReadParams<typeof passthroughAuthAbi, 'isAuthorized'>,
50
+ ) {
51
+ return readPassthroughAuthIsAuthorized(this._config, {
52
+ address: this.assertValidAddress(),
53
+ args: [address],
54
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
55
+ ...(params as any),
56
+ });
57
+ }
58
+
59
+ /**
60
+ * @inheritdoc
61
+ *
62
+ * @public
63
+ * @param {?PassthroughAuthPayload} [_payload]
64
+ * @param {?DeployableOptions} [_options]
65
+ * @returns {GenericDeployableParams}
66
+ */
67
+ public override buildParameters(
68
+ _payload?: never,
69
+ _options?: DeployableOptions,
70
+ ): GenericDeployableParams {
71
+ const [_, options] = this.validateDeploymentConfig({}, _options);
72
+ return {
73
+ abi: passthroughAuthAbi,
74
+ bytecode: bytecode as Hex,
75
+ // biome-ignore lint/suspicious/noExplicitAny: <takes no payload>
76
+ args: [] as any,
77
+ ...this.optionallyAttachAccount(options.account),
78
+ };
79
+ }
80
+ }