@boostxyz/sdk 0.0.0-alpha.5 → 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 (164) hide show
  1. package/dist/Actions/Action.cjs +1 -0
  2. package/dist/Actions/Action.cjs.map +1 -0
  3. package/dist/Actions/Action.js +1 -0
  4. package/dist/Actions/Action.js.map +1 -0
  5. package/dist/Actions/EventAction.cjs +1 -0
  6. package/dist/Actions/EventAction.cjs.map +1 -0
  7. package/dist/Actions/EventAction.js +1 -0
  8. package/dist/Actions/EventAction.js.map +1 -0
  9. package/dist/AllowLists/AllowList.cjs +1 -0
  10. package/dist/AllowLists/AllowList.cjs.map +1 -0
  11. package/dist/AllowLists/AllowList.js +1 -0
  12. package/dist/AllowLists/AllowList.js.map +1 -0
  13. package/dist/AllowLists/SimpleAllowList.cjs +1 -0
  14. package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
  15. package/dist/AllowLists/SimpleAllowList.js +1 -0
  16. package/dist/AllowLists/SimpleAllowList.js.map +1 -0
  17. package/dist/AllowLists/SimpleDenyList.cjs +1 -0
  18. package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
  19. package/dist/AllowLists/SimpleDenyList.js +1 -0
  20. package/dist/AllowLists/SimpleDenyList.js.map +1 -0
  21. package/dist/Auth/Auth.cjs +1 -0
  22. package/dist/Auth/Auth.cjs.map +1 -0
  23. package/dist/Auth/Auth.js +1 -0
  24. package/dist/Auth/Auth.js.map +1 -0
  25. package/dist/Auth/PassthroughAuth.cjs +1 -0
  26. package/dist/Auth/PassthroughAuth.cjs.map +1 -0
  27. package/dist/Auth/PassthroughAuth.js +1 -0
  28. package/dist/Auth/PassthroughAuth.js.map +1 -0
  29. package/dist/Boost.cjs +1 -0
  30. package/dist/Boost.cjs.map +1 -0
  31. package/dist/Boost.js +1 -0
  32. package/dist/Boost.js.map +1 -0
  33. package/dist/BoostCore.cjs +1 -0
  34. package/dist/BoostCore.cjs.map +1 -0
  35. package/dist/BoostCore.js +1 -0
  36. package/dist/BoostCore.js.map +1 -0
  37. package/dist/BoostRegistry.cjs +1 -0
  38. package/dist/BoostRegistry.cjs.map +1 -0
  39. package/dist/BoostRegistry.js +1 -0
  40. package/dist/BoostRegistry.js.map +1 -0
  41. package/dist/Budgets/Budget.cjs +1 -0
  42. package/dist/Budgets/Budget.cjs.map +1 -0
  43. package/dist/Budgets/Budget.js +1 -0
  44. package/dist/Budgets/Budget.js.map +1 -0
  45. package/dist/Budgets/ManagedBudget.cjs +1 -0
  46. package/dist/Budgets/ManagedBudget.cjs.map +1 -0
  47. package/dist/Budgets/ManagedBudget.js +1 -0
  48. package/dist/Budgets/ManagedBudget.js.map +1 -0
  49. package/dist/Deployable/Contract.cjs +1 -0
  50. package/dist/Deployable/Contract.cjs.map +1 -0
  51. package/dist/Deployable/Contract.js +1 -0
  52. package/dist/Deployable/Contract.js.map +1 -0
  53. package/dist/Deployable/Deployable.cjs +1 -0
  54. package/dist/Deployable/Deployable.cjs.map +1 -0
  55. package/dist/Deployable/Deployable.js +1 -0
  56. package/dist/Deployable/Deployable.js.map +1 -0
  57. package/dist/Deployable/DeployableTarget.cjs +1 -0
  58. package/dist/Deployable/DeployableTarget.cjs.map +1 -0
  59. package/dist/Deployable/DeployableTarget.js +1 -0
  60. package/dist/Deployable/DeployableTarget.js.map +1 -0
  61. package/dist/Incentives/AllowListIncentive.cjs +1 -0
  62. package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
  63. package/dist/Incentives/AllowListIncentive.js +1 -0
  64. package/dist/Incentives/AllowListIncentive.js.map +1 -0
  65. package/dist/Incentives/CGDAIncentive.cjs +1 -0
  66. package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
  67. package/dist/Incentives/CGDAIncentive.js +1 -0
  68. package/dist/Incentives/CGDAIncentive.js.map +1 -0
  69. package/dist/Incentives/ERC20Incentive.cjs +1 -0
  70. package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
  71. package/dist/Incentives/ERC20Incentive.js +1 -0
  72. package/dist/Incentives/ERC20Incentive.js.map +1 -0
  73. package/dist/Incentives/Incentive.cjs +1 -0
  74. package/dist/Incentives/Incentive.cjs.map +1 -0
  75. package/dist/Incentives/Incentive.js +1 -0
  76. package/dist/Incentives/Incentive.js.map +1 -0
  77. package/dist/Incentives/PointsIncentive.cjs +1 -0
  78. package/dist/Incentives/PointsIncentive.cjs.map +1 -0
  79. package/dist/Incentives/PointsIncentive.js +1 -0
  80. package/dist/Incentives/PointsIncentive.js.map +1 -0
  81. package/dist/Validators/SignerValidator.cjs +1 -0
  82. package/dist/Validators/SignerValidator.cjs.map +1 -0
  83. package/dist/Validators/SignerValidator.js +1 -0
  84. package/dist/Validators/SignerValidator.js.map +1 -0
  85. package/dist/Validators/Validator.cjs +1 -0
  86. package/dist/Validators/Validator.cjs.map +1 -0
  87. package/dist/Validators/Validator.js +1 -0
  88. package/dist/Validators/Validator.js.map +1 -0
  89. package/dist/componentInterfaces-CKCBwG16.cjs +1 -0
  90. package/dist/componentInterfaces-CKCBwG16.cjs.map +1 -0
  91. package/dist/componentInterfaces-DYkaxBda.js +1 -0
  92. package/dist/componentInterfaces-DYkaxBda.js.map +1 -0
  93. package/dist/errors.cjs +1 -0
  94. package/dist/errors.cjs.map +1 -0
  95. package/dist/errors.js +1 -0
  96. package/dist/errors.js.map +1 -0
  97. package/dist/generated-Cd-Fe7W7.cjs +1 -0
  98. package/dist/generated-Cd-Fe7W7.cjs.map +1 -0
  99. package/dist/generated-DGpIVcv5.js +1 -0
  100. package/dist/generated-DGpIVcv5.js.map +1 -0
  101. package/dist/index.cjs +1 -0
  102. package/dist/index.cjs.map +1 -0
  103. package/dist/index.js +1 -0
  104. package/dist/index.js.map +1 -0
  105. package/dist/utils.cjs +1 -0
  106. package/dist/utils.cjs.map +1 -0
  107. package/dist/utils.js +1 -0
  108. package/dist/utils.js.map +1 -0
  109. package/package.json +3 -2
  110. package/src/Actions/Action.test.ts +77 -0
  111. package/src/Actions/Action.ts +61 -0
  112. package/src/Actions/ContractAction.test.ts +199 -0
  113. package/src/Actions/ContractAction.ts +238 -0
  114. package/src/Actions/ERC721MintAction.test.ts +112 -0
  115. package/src/Actions/ERC721MintAction.ts +238 -0
  116. package/src/Actions/EventAction.test.ts +182 -0
  117. package/src/Actions/EventAction.ts +382 -0
  118. package/src/AllowLists/AllowList.test.ts +64 -0
  119. package/src/AllowLists/AllowList.ts +60 -0
  120. package/src/AllowLists/SimpleAllowList.test.ts +52 -0
  121. package/src/AllowLists/SimpleAllowList.ts +240 -0
  122. package/src/AllowLists/SimpleDenyList.test.ts +52 -0
  123. package/src/AllowLists/SimpleDenyList.ts +289 -0
  124. package/src/Auth/Auth.ts +11 -0
  125. package/src/Auth/PassthroughAuth.test.ts +12 -0
  126. package/src/Auth/PassthroughAuth.ts +80 -0
  127. package/src/Boost.ts +155 -0
  128. package/src/BoostCore.test.ts +846 -0
  129. package/src/BoostCore.ts +1192 -0
  130. package/src/BoostRegistry.ts +449 -0
  131. package/src/Budgets/Budget.test.ts +27 -0
  132. package/src/Budgets/Budget.ts +61 -0
  133. package/src/Budgets/ManagedBudget.test.ts +154 -0
  134. package/src/Budgets/ManagedBudget.ts +743 -0
  135. package/src/Budgets/SimpleBudget.test.ts +152 -0
  136. package/src/Budgets/SimpleBudget.ts +521 -0
  137. package/src/Budgets/VestingBudget.test.ts +123 -0
  138. package/src/Budgets/VestingBudget.ts +532 -0
  139. package/src/Deployable/Contract.ts +229 -0
  140. package/src/Deployable/Deployable.ts +244 -0
  141. package/src/Deployable/DeployableTarget.ts +210 -0
  142. package/src/Incentives/AllowListIncentive.test.ts +146 -0
  143. package/src/Incentives/AllowListIncentive.ts +290 -0
  144. package/src/Incentives/CGDAIncentive.test.ts +136 -0
  145. package/src/Incentives/CGDAIncentive.ts +364 -0
  146. package/src/Incentives/ERC1155Incentive.test.ts +98 -0
  147. package/src/Incentives/ERC1155Incentive.ts +384 -0
  148. package/src/Incentives/ERC20Incentive.test.ts +141 -0
  149. package/src/Incentives/ERC20Incentive.ts +417 -0
  150. package/src/Incentives/ERC20VariableIncentive.test.ts +156 -0
  151. package/src/Incentives/ERC20VariableIncentive.ts +368 -0
  152. package/src/Incentives/Incentive.test.ts +92 -0
  153. package/src/Incentives/Incentive.ts +85 -0
  154. package/src/Incentives/PointsIncentive.test.ts +142 -0
  155. package/src/Incentives/PointsIncentive.ts +303 -0
  156. package/src/Validators/SignerValidator.test.ts +163 -0
  157. package/src/Validators/SignerValidator.ts +272 -0
  158. package/src/Validators/Validator.test.ts +21 -0
  159. package/src/Validators/Validator.ts +55 -0
  160. package/src/errors.ts +524 -0
  161. package/src/index.test.ts +40 -0
  162. package/src/index.ts +50 -0
  163. package/src/utils.test.ts +44 -0
  164. package/src/utils.ts +2247 -0
@@ -0,0 +1,272 @@
1
+ import {
2
+ readSignerValidatorHashSignerData,
3
+ readSignerValidatorSigners,
4
+ signerValidatorAbi,
5
+ simulateSignerValidatorSetAuthorized,
6
+ simulateSignerValidatorSetValidatorCaller,
7
+ simulateSignerValidatorValidate,
8
+ writeSignerValidatorSetAuthorized,
9
+ writeSignerValidatorSetValidatorCaller,
10
+ writeSignerValidatorValidate,
11
+ } from '@boostxyz/evm';
12
+ import { bytecode } from '@boostxyz/evm/artifacts/contracts/validators/SignerValidator.sol/SignerValidator.json';
13
+ import type { Address, ContractEventName, Hex } from 'viem';
14
+ import type {
15
+ DeployableOptions,
16
+ GenericDeployableParams,
17
+ } from '../Deployable/Deployable';
18
+ import { DeployableTarget } from '../Deployable/DeployableTarget';
19
+ import {
20
+ type GenericLog,
21
+ type ReadParams,
22
+ RegistryType,
23
+ type SignerValidatorPayload,
24
+ type SignerValidatorSignaturePayload,
25
+ type SignerValidatorValidatePayload,
26
+ type WriteParams,
27
+ prepareSignerValidatorPayload,
28
+ } from '../utils';
29
+
30
+ export { signerValidatorAbi };
31
+ export type { SignerValidatorPayload };
32
+
33
+ /**
34
+ * A generic `viem.Log` event with support for `BoostCore` event types.
35
+ *
36
+ * @export
37
+ * @typedef {SignerValidatorLog}
38
+ * @template {ContractEventName<
39
+ * typeof signerValidatorAbi
40
+ * >} [event=ContractEventName<typeof signerValidatorAbi>]
41
+ */
42
+ export type SignerValidatorLog<
43
+ event extends ContractEventName<
44
+ typeof signerValidatorAbi
45
+ > = ContractEventName<typeof signerValidatorAbi>,
46
+ > = GenericLog<typeof signerValidatorAbi, event>;
47
+
48
+ /**
49
+ * A simple implementation of a Validator that verifies a given signature and checks the recovered address against a set of authorized signers
50
+ *
51
+ * @export
52
+ * @class SignerValidator
53
+ * @typedef {SignerValidator}
54
+ * @extends {DeployableTarget<SignerValidatorPayload>}
55
+ */
56
+ export class SignerValidator extends DeployableTarget<
57
+ SignerValidatorPayload,
58
+ typeof signerValidatorAbi
59
+ > {
60
+ public override readonly abi = signerValidatorAbi;
61
+ /**
62
+ * @inheritdoc
63
+ *
64
+ * @public
65
+ * @static
66
+ * @type {Address}
67
+ */
68
+ public static override base: Address = import.meta.env
69
+ .VITE_SIGNER_VALIDATOR_BASE;
70
+ /**
71
+ * @inheritdoc
72
+ *
73
+ * @public
74
+ * @static
75
+ * @type {RegistryType}
76
+ */
77
+ public static override registryType: RegistryType = RegistryType.VALIDATOR;
78
+
79
+ /**
80
+ * The set of authorized signers
81
+ *
82
+ * @public
83
+ * @async
84
+ * @param {Address} address
85
+ * @param {?ReadParams<typeof signerValidatorAbi, 'signers'>} [params]
86
+ * @returns {unknown}
87
+ */
88
+ public async signers(
89
+ address: Address,
90
+ params?: ReadParams<typeof signerValidatorAbi, 'signers'>,
91
+ ) {
92
+ return readSignerValidatorSigners(this._config, {
93
+ address: this.assertValidAddress(),
94
+ args: [address],
95
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
96
+ ...(params as any),
97
+ });
98
+ }
99
+
100
+ /**
101
+ * Retrieve the hash and signer data for a given hash
102
+ *
103
+ * @public
104
+ * @async
105
+ * @param {SignerValidatorSignaturePayload} payload
106
+ * @param {?ReadParams<typeof signerValidatorAbi, 'hashSignerData'>} [params]
107
+ * @returns {unknown}
108
+ */
109
+ public async hashSignerData(
110
+ payload: SignerValidatorSignaturePayload,
111
+ params?: ReadParams<typeof signerValidatorAbi, 'hashSignerData'>,
112
+ ) {
113
+ return readSignerValidatorHashSignerData(this._config, {
114
+ address: this.assertValidAddress(),
115
+ args: [
116
+ payload.boostId,
117
+ payload.incentiveQuantity,
118
+ payload.claimant,
119
+ payload.incentiveData,
120
+ ],
121
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
122
+ ...(params as any),
123
+ });
124
+ }
125
+
126
+ /**
127
+ * Validate that the action has been completed successfully. The data payload is expected to be a tuple of (address signer, bytes32 hash, bytes signature). The signature is expected to be a valid ECDSA or EIP-1271 signature of a unique hash by an authorized signer.
128
+ *
129
+ * @public
130
+ * @async
131
+ * @param {SignerValidatorValidatePayload} payload
132
+ * @param {?WriteParams<typeof signerValidatorAbi, 'validate'>} [params]
133
+ * @returns {Promise<boolean>} - True if the action has been validated based on the data payload
134
+ */
135
+ public async validate(
136
+ payload: SignerValidatorValidatePayload,
137
+ params?: WriteParams<typeof signerValidatorAbi, 'validate'>,
138
+ ) {
139
+ return this.awaitResult(this.validateRaw(payload, params));
140
+ }
141
+
142
+ /**
143
+ * Validate that the action has been completed successfully. The data payload is expected to be a tuple of (address signer, bytes32 hash, bytes signature). The signature is expected to be a valid ECDSA or EIP-1271 signature of a unique hash by an authorized signer.
144
+ *
145
+ * @public
146
+ * @async
147
+ * @param {SignerValidatorValidatePayload} payload
148
+ * @param {?WriteParams<typeof signerValidatorAbi, 'validate'>} [params]
149
+ * @returns {Promise<boolean>} - True if the action has been validated based on the data payload
150
+ */
151
+ public async validateRaw(
152
+ payload: SignerValidatorValidatePayload,
153
+ params?: ReadParams<typeof signerValidatorAbi, 'validate'>,
154
+ ) {
155
+ const { request, result } = await simulateSignerValidatorValidate(
156
+ this._config,
157
+ {
158
+ address: this.assertValidAddress(),
159
+ args: [
160
+ payload.boostId,
161
+ payload.incentiveId,
162
+ payload.claimant,
163
+ payload.claimData,
164
+ ],
165
+ ...this.optionallyAttachAccount(),
166
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
167
+ ...(params as any),
168
+ },
169
+ );
170
+ const hash = await writeSignerValidatorValidate(this._config, request);
171
+ return { hash, result };
172
+ }
173
+
174
+ /**
175
+ * Set the authorized status of a signer
176
+ *
177
+ * @public
178
+ * @async
179
+ * @param {Address[]} addresses - The list of signers to update
180
+ * @param {boolean[]} allowed - The authorized status of each signer
181
+ * @param {?WriteParams<typeof signerValidatorAbi, 'setAuthorized'>} [params]
182
+ * @returns {unknown}
183
+ */
184
+ public async setAuthorized(
185
+ addresses: Address[],
186
+ allowed: boolean[],
187
+ params?: WriteParams<typeof signerValidatorAbi, 'setAuthorized'>,
188
+ ) {
189
+ return this.awaitResult(this.setAuthorizedRaw(addresses, allowed, params));
190
+ }
191
+
192
+ /**
193
+ * Set the authorized status of a signer
194
+ *
195
+ * @public
196
+ * @async
197
+ * @param {Address[]} addresses - The list of signers to update
198
+ * @param {boolean[]} allowed - The authorized status of each signer
199
+ * @param {?WriteParams<typeof signerValidatorAbi, 'setAuthorized'>} [params]
200
+ * @returns {unknown}
201
+ */
202
+ public async setAuthorizedRaw(
203
+ addresses: Address[],
204
+ allowed: boolean[],
205
+ params?: WriteParams<typeof signerValidatorAbi, 'setAuthorized'>,
206
+ ) {
207
+ const { request, result } = await simulateSignerValidatorSetAuthorized(
208
+ this._config,
209
+ {
210
+ address: this.assertValidAddress(),
211
+ args: [addresses, allowed],
212
+ ...this.optionallyAttachAccount(),
213
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
214
+ ...(params as any),
215
+ },
216
+ );
217
+ const hash = await writeSignerValidatorSetAuthorized(this._config, request);
218
+ return { hash, result };
219
+ }
220
+
221
+ public async setValidatorCallerRaw(
222
+ address: Address,
223
+ params?: WriteParams<typeof signerValidatorAbi, 'setValidatorCaller'>,
224
+ ) {
225
+ const { request, result } = await simulateSignerValidatorSetValidatorCaller(
226
+ this._config,
227
+ {
228
+ address: this.assertValidAddress(),
229
+ args: [address],
230
+ ...this.optionallyAttachAccount(),
231
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
232
+ ...(params as any),
233
+ },
234
+ );
235
+ const hash = await writeSignerValidatorSetValidatorCaller(
236
+ this._config,
237
+ request,
238
+ );
239
+ return { hash, result };
240
+ }
241
+
242
+ public async setValidatorCaller(
243
+ address: Address,
244
+ params?: WriteParams<typeof signerValidatorAbi, 'setValidatorCaller'>,
245
+ ) {
246
+ return this.awaitResult(this.setValidatorCallerRaw(address, params));
247
+ }
248
+
249
+ /**
250
+ * @inheritdoc
251
+ *
252
+ * @public
253
+ * @param {?SignerValidatorPayload} [_payload]
254
+ * @param {?DeployableOptions} [_options]
255
+ * @returns {GenericDeployableParams}
256
+ */
257
+ public override buildParameters(
258
+ _payload?: SignerValidatorPayload,
259
+ _options?: DeployableOptions,
260
+ ): GenericDeployableParams {
261
+ const [payload, options] = this.validateDeploymentConfig(
262
+ _payload,
263
+ _options,
264
+ );
265
+ return {
266
+ abi: signerValidatorAbi,
267
+ bytecode: bytecode as Hex,
268
+ args: [prepareSignerValidatorPayload(payload)],
269
+ ...this.optionallyAttachAccount(options.account),
270
+ };
271
+ }
272
+ }
@@ -0,0 +1,21 @@
1
+ import { describe, expect, test } from 'vitest';
2
+ import { defaultOptions } from '../../test/helpers';
3
+ import { testAccount } from '../../test/viem';
4
+ import { SignerValidator } from './SignerValidator';
5
+ import { validatorFromAddress } from './Validator';
6
+
7
+ describe('Validator', () => {
8
+ test('can automatically instantiate SignerValidator given an address', async () => {
9
+ const validator = new SignerValidator(defaultOptions, {
10
+ signers: [testAccount.address],
11
+ validatorCaller: testAccount.address,
12
+ });
13
+ await validator.deploy();
14
+ expect(
15
+ await validatorFromAddress(
16
+ defaultOptions,
17
+ validator.assertValidAddress(),
18
+ ),
19
+ ).toBeInstanceOf(SignerValidator);
20
+ });
21
+ });
@@ -0,0 +1,55 @@
1
+ import { aValidatorAbi } from '@boostxyz/evm';
2
+ import { ASignerValidator } from '@boostxyz/evm/deploys/componentInterfaces.json';
3
+ import { readContract } from '@wagmi/core';
4
+ import type { Address, Hex } from 'viem';
5
+ import type { DeployableOptions } from '../Deployable/Deployable';
6
+ import { InvalidComponentInterfaceError } from '../errors';
7
+ import { SignerValidator } from './SignerValidator';
8
+
9
+ export { SignerValidator };
10
+
11
+ /**
12
+ * A union type representing all valid protocol Validator implementations
13
+ *
14
+ * @export
15
+ * @typedef {Validator}
16
+ */
17
+ export type Validator = SignerValidator;
18
+
19
+ /**
20
+ * A map of Validator component interfaces to their constructors.
21
+ *
22
+ * @type {{ "0xd8725ea2": typeof SignerValidator; }}
23
+ */
24
+ export const ValidatorByComponentInterface = {
25
+ [ASignerValidator as Hex]: SignerValidator,
26
+ };
27
+
28
+ /**
29
+ * A function that will read a contract's component interface using `getComponentInterface` and return the correct instantiated instance.
30
+ *
31
+ * @export
32
+ * @async
33
+ * @param {DeployableOptions} options
34
+ * @param {Address} address
35
+ * @returns {unknown}
36
+ * @throws {@link InvalidComponentInterfaceError}
37
+ */
38
+ export async function validatorFromAddress(
39
+ options: DeployableOptions,
40
+ address: Address,
41
+ ) {
42
+ const interfaceId = (await readContract(options.config, {
43
+ abi: aValidatorAbi,
44
+ functionName: 'getComponentInterface',
45
+ address,
46
+ })) as keyof typeof ValidatorByComponentInterface;
47
+ const Ctor = ValidatorByComponentInterface[interfaceId];
48
+ if (!Ctor) {
49
+ throw new InvalidComponentInterfaceError(
50
+ Object.keys(ValidatorByComponentInterface) as Hex[],
51
+ interfaceId as Hex,
52
+ );
53
+ }
54
+ return new Ctor(options, address);
55
+ }