@boostxyz/sdk 1.1.0-alpha.23 → 2.0.0-alpha.25

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 (134) hide show
  1. package/dist/Actions/Action.cjs +1 -1
  2. package/dist/Actions/Action.js +7 -7
  3. package/dist/Actions/EventAction.cjs +1 -1
  4. package/dist/Actions/EventAction.cjs.map +1 -1
  5. package/dist/Actions/EventAction.d.ts +32 -5
  6. package/dist/Actions/EventAction.d.ts.map +1 -1
  7. package/dist/Actions/EventAction.js +164 -137
  8. package/dist/Actions/EventAction.js.map +1 -1
  9. package/dist/AllowLists/AllowList.cjs +1 -1
  10. package/dist/AllowLists/AllowList.js +10 -10
  11. package/dist/AllowLists/SimpleAllowList.cjs +1 -1
  12. package/dist/AllowLists/SimpleAllowList.js +10 -10
  13. package/dist/AllowLists/SimpleDenyList.cjs +1 -1
  14. package/dist/AllowLists/SimpleDenyList.js +3 -3
  15. package/dist/Auth/PassthroughAuth.cjs +1 -1
  16. package/dist/Auth/PassthroughAuth.js +1 -1
  17. package/dist/BoostCore.cjs +2 -1
  18. package/dist/BoostCore.cjs.map +1 -1
  19. package/dist/BoostCore.d.ts +564 -1
  20. package/dist/BoostCore.d.ts.map +1 -1
  21. package/dist/BoostCore.js +1322 -29
  22. package/dist/BoostCore.js.map +1 -1
  23. package/dist/BoostRegistry.cjs +1 -1
  24. package/dist/BoostRegistry.js +27 -27
  25. package/dist/Budgets/Budget.cjs +1 -1
  26. package/dist/Budgets/Budget.js +2 -2
  27. package/dist/Budgets/ManagedBudget.cjs +1 -1
  28. package/dist/Budgets/ManagedBudget.js +23 -23
  29. package/dist/Deployable/DeployableTarget.cjs +1 -1
  30. package/dist/Deployable/DeployableTarget.js +1 -1
  31. package/dist/Deployable/DeployableTargetWithRBAC.cjs +1 -1
  32. package/dist/Deployable/DeployableTargetWithRBAC.js +23 -23
  33. package/dist/Incentives/AllowListIncentive.cjs +1 -1
  34. package/dist/Incentives/AllowListIncentive.js +8 -8
  35. package/dist/Incentives/CGDAIncentive.cjs +1 -1
  36. package/dist/Incentives/CGDAIncentive.js +12 -12
  37. package/dist/Incentives/ERC20Incentive.cjs +1 -1
  38. package/dist/Incentives/ERC20Incentive.js +16 -16
  39. package/dist/Incentives/ERC20VariableCriteriaIncentive.cjs +2 -0
  40. package/dist/Incentives/ERC20VariableCriteriaIncentive.cjs.map +1 -0
  41. package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts +42 -15
  42. package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts.map +1 -1
  43. package/dist/Incentives/ERC20VariableCriteriaIncentive.js +188 -0
  44. package/dist/Incentives/ERC20VariableCriteriaIncentive.js.map +1 -0
  45. package/dist/Incentives/ERC20VariableIncentive.cjs +2 -0
  46. package/dist/Incentives/ERC20VariableIncentive.cjs.map +1 -0
  47. package/dist/Incentives/ERC20VariableIncentive.d.ts +7 -5
  48. package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -1
  49. package/dist/{Incentive-rM5nKznp.js → Incentives/ERC20VariableIncentive.js} +42 -67
  50. package/dist/Incentives/ERC20VariableIncentive.js.map +1 -0
  51. package/dist/Incentives/Incentive.cjs +1 -1
  52. package/dist/Incentives/Incentive.cjs.map +1 -1
  53. package/dist/Incentives/Incentive.d.ts +552 -3
  54. package/dist/Incentives/Incentive.d.ts.map +1 -1
  55. package/dist/Incentives/Incentive.js +40 -16
  56. package/dist/Incentives/Incentive.js.map +1 -1
  57. package/dist/Incentives/PointsIncentive.cjs +1 -1
  58. package/dist/Incentives/PointsIncentive.js +8 -8
  59. package/dist/{SimpleDenyList-DNj5qDWM.cjs → SimpleDenyList-BdlpZdDz.cjs} +2 -2
  60. package/dist/{SimpleDenyList-DNj5qDWM.cjs.map → SimpleDenyList-BdlpZdDz.cjs.map} +1 -1
  61. package/dist/{SimpleDenyList-BDXpY74P.js → SimpleDenyList-D0cyVUVv.js} +16 -16
  62. package/dist/{SimpleDenyList-BDXpY74P.js.map → SimpleDenyList-D0cyVUVv.js.map} +1 -1
  63. package/dist/Validators/LimitedSignerValidator.cjs +2 -0
  64. package/dist/Validators/LimitedSignerValidator.cjs.map +1 -0
  65. package/dist/Validators/LimitedSignerValidator.d.ts +806 -0
  66. package/dist/Validators/LimitedSignerValidator.d.ts.map +1 -0
  67. package/dist/Validators/LimitedSignerValidator.js +299 -0
  68. package/dist/Validators/LimitedSignerValidator.js.map +1 -0
  69. package/dist/Validators/SignerValidator.cjs +1 -1
  70. package/dist/Validators/SignerValidator.cjs.map +1 -1
  71. package/dist/Validators/SignerValidator.d.ts +2 -2
  72. package/dist/Validators/SignerValidator.js +5 -5
  73. package/dist/Validators/SignerValidator.js.map +1 -1
  74. package/dist/Validators/Validator.cjs +1 -1
  75. package/dist/Validators/Validator.cjs.map +1 -1
  76. package/dist/Validators/Validator.d.ts +22 -2
  77. package/dist/Validators/Validator.d.ts.map +1 -1
  78. package/dist/Validators/Validator.js +26 -17
  79. package/dist/Validators/Validator.js.map +1 -1
  80. package/dist/{componentInterfaces-BBCFkrZv.js → componentInterfaces-bIVo8eyA.js} +9 -9
  81. package/dist/componentInterfaces-bIVo8eyA.js.map +1 -0
  82. package/dist/{deployments-fJsWblwS.js → deployments-Ccx1MtoK.js} +5 -5
  83. package/dist/deployments-Ccx1MtoK.js.map +1 -0
  84. package/dist/{generated-CsNyWPKA.js → generated-BAKNSOjJ.js} +661 -381
  85. package/dist/generated-BAKNSOjJ.js.map +1 -0
  86. package/dist/generated-Cqn4wS01.cjs +3 -0
  87. package/dist/generated-Cqn4wS01.cjs.map +1 -0
  88. package/dist/index.cjs +1 -1
  89. package/dist/index.d.ts +1 -0
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +145 -132
  92. package/dist/index.js.map +1 -1
  93. package/dist/utils.cjs +1 -1
  94. package/dist/utils.cjs.map +1 -1
  95. package/dist/utils.d.ts +10 -0
  96. package/dist/utils.d.ts.map +1 -1
  97. package/dist/utils.js +27 -26
  98. package/dist/utils.js.map +1 -1
  99. package/package.json +21 -5
  100. package/src/Actions/EventAction.test.ts +381 -122
  101. package/src/Actions/EventAction.ts +85 -23
  102. package/src/BoostCore.test.ts +3 -3
  103. package/src/BoostCore.ts +51 -5
  104. package/src/Incentives/AllowListIncentive.test.ts +19 -21
  105. package/src/Incentives/CGDAIncentive.test.ts +20 -22
  106. package/src/Incentives/ERC1155Incentive.test.ts +14 -15
  107. package/src/Incentives/ERC20Incentive.test.ts +17 -19
  108. package/src/Incentives/ERC20VariableCriteriaIncentive.test.ts +62 -10
  109. package/src/Incentives/ERC20VariableCriteriaIncentive.ts +79 -37
  110. package/src/Incentives/ERC20VariableIncentive.test.ts +16 -18
  111. package/src/Incentives/ERC20VariableIncentive.ts +16 -8
  112. package/src/Incentives/Incentive.ts +4 -1
  113. package/src/Incentives/PointsIncentive.test.ts +3 -5
  114. package/src/Validators/LimitedSignerValidator.test.ts +223 -0
  115. package/src/Validators/LimitedSignerValidator.ts +707 -0
  116. package/src/Validators/SignerValidator.test.ts +21 -22
  117. package/src/Validators/SignerValidator.ts +2 -2
  118. package/src/Validators/Validator.test.ts +7 -1
  119. package/src/Validators/Validator.ts +30 -3
  120. package/src/index.test.ts +2 -0
  121. package/src/index.ts +1 -0
  122. package/src/utils.ts +11 -0
  123. package/dist/BoostCore-Btl5BdAs.cjs +0 -3
  124. package/dist/BoostCore-Btl5BdAs.cjs.map +0 -1
  125. package/dist/BoostCore-CD56zbYX.js +0 -2641
  126. package/dist/BoostCore-CD56zbYX.js.map +0 -1
  127. package/dist/Incentive-CcnOIc8L.cjs +0 -2
  128. package/dist/Incentive-CcnOIc8L.cjs.map +0 -1
  129. package/dist/Incentive-rM5nKznp.js.map +0 -1
  130. package/dist/componentInterfaces-BBCFkrZv.js.map +0 -1
  131. package/dist/deployments-fJsWblwS.js.map +0 -1
  132. package/dist/generated-CsNyWPKA.js.map +0 -1
  133. package/dist/generated-DHerxf1y.cjs +0 -3
  134. package/dist/generated-DHerxf1y.cjs.map +0 -1
@@ -0,0 +1,223 @@
1
+ import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
2
+ import { isAddress, pad, ContractFunctionRevertedError } 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 { testAccount } from '@boostxyz/test/viem';
11
+ import { LimitedSignerValidator } from './LimitedSignerValidator';
12
+
13
+ let fixtures: Fixtures;
14
+
15
+ function freshValidator(fixtures: Fixtures) {
16
+ return function freshValidator() {
17
+ // biome-ignore lint/style/noNonNullAssertion: this will never be undefined
18
+ const account = accounts.at(1)!.account;
19
+ return fixtures.registry.initialize(
20
+ crypto.randomUUID(),
21
+ fixtures.core.LimitedSignerValidator({
22
+ signers: [defaultOptions.account.address, account],
23
+ validatorCaller: testAccount.address,
24
+ maxClaimCount: 1,
25
+ }),
26
+ );
27
+ };
28
+ }
29
+
30
+ describe('LimitedSignerValidator', () => {
31
+ beforeAll(async () => {
32
+ fixtures = await loadFixture(deployFixtures(defaultOptions));
33
+ });
34
+
35
+ test('can successfully be deployed', async () => {
36
+ expect.assertions(1);
37
+ const action = new LimitedSignerValidator(defaultOptions, {
38
+ signers: [testAccount.address],
39
+ validatorCaller: testAccount.address,
40
+ maxClaimCount: 0,
41
+ });
42
+ await action.deploy();
43
+ expect(isAddress(action.assertValidAddress())).toBe(true);
44
+ });
45
+
46
+ test('initializes successfully', async () => {
47
+ expect.assertions(3);
48
+ const validator = await loadFixture(freshValidator(fixtures));
49
+ expect(await validator.signers(defaultOptions.account.address)).toBe(true);
50
+ // biome-ignore lint/style/noNonNullAssertion: this will never be undefined
51
+ expect(await validator.signers(accounts.at(1)!.account)).toBe(true);
52
+ // biome-ignore lint/style/noNonNullAssertion: this will never be undefined
53
+ expect(await validator.signers(accounts.at(2)!.account)).toBe(false);
54
+ });
55
+
56
+ test('can validate hashes', async () => {
57
+ const validator = await loadFixture(freshValidator(fixtures));
58
+
59
+ // Define the input data
60
+ const boostId = 5n;
61
+ const incentiveQuantity = 1;
62
+ const incentiveId = 0n;
63
+ const claimant = '0x24582544C98a86eE59687c4D5B55D78f4FffA666';
64
+ const incentiveData = pad('0xdef456232173821931823712381232131391321934');
65
+
66
+ // biome-ignore lint/style/noNonNullAssertion: this will never be undefined
67
+ const trustedSigner = accounts.at(0)!;
68
+ // biome-ignore lint/style/noNonNullAssertion: this will never be undefined
69
+ const untrustedSigner = accounts.at(2)!;
70
+
71
+ const claimDataPayload = await validator.encodeClaimData({
72
+ signer: trustedSigner,
73
+ incentiveData,
74
+ chainId: defaultOptions.config.chains[0].id,
75
+ incentiveQuantity,
76
+ claimant,
77
+ boostId: boostId,
78
+ });
79
+
80
+ const badClaimDataPayload = await validator.encodeClaimData({
81
+ signer: untrustedSigner,
82
+ incentiveData,
83
+ chainId: defaultOptions.config.chains[0].id,
84
+ incentiveQuantity,
85
+ claimant,
86
+ boostId: boostId,
87
+ });
88
+
89
+ // Validation using trusted signer
90
+ expect(
91
+ await validator.validate({
92
+ boostId: boostId,
93
+ incentiveId: incentiveId,
94
+ claimData: claimDataPayload,
95
+ claimant: claimant,
96
+ }),
97
+ ).toBe(true);
98
+
99
+ // Validation using untrusted signer should throw an error
100
+ try {
101
+ await validator.validate({
102
+ boostId: boostId,
103
+ incentiveId: incentiveId,
104
+ claimData: badClaimDataPayload,
105
+ claimant: claimant,
106
+ });
107
+ } catch (e) {
108
+ expect(e).toBeInstanceOf(Error);
109
+ }
110
+ expect.assertions(2);
111
+ });
112
+
113
+ test('will not accept more than `maxClaims` valid claims', async () =>{
114
+ // in this case maxClaims is 1, configured above as a state variable
115
+ const validator = await loadFixture(freshValidator(fixtures));
116
+
117
+ // Define the input data
118
+ const boostId = 5n;
119
+ const incentiveQuantity = 1;
120
+ const incentiveId = 0n;
121
+ const claimant = '0x24582544C98a86eE59687c4D5B55D78f4FffA666';
122
+ const incentiveData = pad('0xdef456232173821931823712381232131391321934');
123
+
124
+ // biome-ignore lint/style/noNonNullAssertion: this will never be undefined
125
+ const trustedSigner = accounts[0];
126
+
127
+ const claimDataPayload = await validator.encodeClaimData({
128
+ signer: trustedSigner,
129
+ incentiveData,
130
+ chainId: defaultOptions.config.chains[0].id,
131
+ incentiveQuantity,
132
+ claimant,
133
+ boostId: boostId,
134
+ });
135
+
136
+ // Validation using trusted signer
137
+ expect(
138
+ await validator.validate({
139
+ boostId: boostId,
140
+ incentiveId: incentiveId,
141
+ claimData: claimDataPayload,
142
+ claimant: claimant,
143
+ }),
144
+ ).toBe(true);
145
+
146
+ const newClaimDataPayload = await validator.encodeClaimData({
147
+ signer: trustedSigner,
148
+ incentiveData: pad('0xdef45623217382193182371238123213139132193456'),
149
+ chainId: defaultOptions.config.chains[0].id,
150
+ incentiveQuantity,
151
+ claimant,
152
+ boostId: boostId,
153
+ });
154
+
155
+ try {
156
+ await validator.validate({
157
+ boostId: boostId,
158
+ incentiveId: incentiveId,
159
+ claimData: newClaimDataPayload,
160
+ claimant: claimant,
161
+ })
162
+ } catch(e) {
163
+ if (e instanceof Object)
164
+ expect((e).toString()).toContain('MaximumClaimed')
165
+ }
166
+ expect.assertions(2);
167
+ })
168
+
169
+ test('will not revalidate the same hash', async () => {
170
+ const validator = await loadFixture(freshValidator(fixtures));
171
+
172
+ // Define the input data
173
+ const boostId = 5n;
174
+ const incentiveQuantity = 1;
175
+ const incentiveId = 0n;
176
+ const claimant = '0x24582544C98a86eE59687c4D5B55D78f4FffA666';
177
+ const incentiveData = pad('0xdef456232173821931823712381232131391321934');
178
+
179
+ // biome-ignore lint/style/noNonNullAssertion: this will never be undefined
180
+ const trustedSigner = accounts.at(0)!;
181
+
182
+ const claimDataPayload = await validator.encodeClaimData({
183
+ signer: trustedSigner,
184
+ incentiveData,
185
+ chainId: defaultOptions.config.chains[0].id,
186
+ incentiveQuantity,
187
+ claimant,
188
+ boostId: boostId,
189
+ });
190
+
191
+ expect(
192
+ await validator.validate({
193
+ boostId,
194
+ incentiveId,
195
+ claimant,
196
+ claimData: claimDataPayload,
197
+ }),
198
+ ).toBe(true);
199
+
200
+ // Attempt to validate the same hash again (should throw an error)
201
+ try {
202
+ await validator.validate({
203
+ boostId,
204
+ incentiveId,
205
+ claimData: claimDataPayload,
206
+ claimant,
207
+ });
208
+ } catch (e) {
209
+ expect(e).toBeInstanceOf(Error);
210
+ }
211
+ expect.assertions(2);
212
+ });
213
+
214
+ test('can set authorized', async () => {
215
+ const validator = await loadFixture(freshValidator(fixtures));
216
+ // biome-ignore lint/style/noNonNullAssertion: this will never be undefined
217
+ const newSigner = accounts.at(2)!.account;
218
+ expect(await validator.signers(newSigner)).toBe(false);
219
+ await validator.setAuthorized([newSigner], [true]);
220
+ expect(await validator.signers(newSigner)).toBe(true);
221
+ expect.assertions(2);
222
+ });
223
+ });