@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.
- package/dist/Actions/Action.cjs +1 -1
- package/dist/Actions/Action.js +7 -7
- package/dist/Actions/EventAction.cjs +1 -1
- package/dist/Actions/EventAction.cjs.map +1 -1
- package/dist/Actions/EventAction.d.ts +32 -5
- package/dist/Actions/EventAction.d.ts.map +1 -1
- package/dist/Actions/EventAction.js +164 -137
- package/dist/Actions/EventAction.js.map +1 -1
- package/dist/AllowLists/AllowList.cjs +1 -1
- package/dist/AllowLists/AllowList.js +10 -10
- package/dist/AllowLists/SimpleAllowList.cjs +1 -1
- package/dist/AllowLists/SimpleAllowList.js +10 -10
- package/dist/AllowLists/SimpleDenyList.cjs +1 -1
- package/dist/AllowLists/SimpleDenyList.js +3 -3
- package/dist/Auth/PassthroughAuth.cjs +1 -1
- package/dist/Auth/PassthroughAuth.js +1 -1
- package/dist/BoostCore.cjs +2 -1
- package/dist/BoostCore.cjs.map +1 -1
- package/dist/BoostCore.d.ts +564 -1
- package/dist/BoostCore.d.ts.map +1 -1
- package/dist/BoostCore.js +1322 -29
- package/dist/BoostCore.js.map +1 -1
- package/dist/BoostRegistry.cjs +1 -1
- package/dist/BoostRegistry.js +27 -27
- package/dist/Budgets/Budget.cjs +1 -1
- package/dist/Budgets/Budget.js +2 -2
- package/dist/Budgets/ManagedBudget.cjs +1 -1
- package/dist/Budgets/ManagedBudget.js +23 -23
- package/dist/Deployable/DeployableTarget.cjs +1 -1
- package/dist/Deployable/DeployableTarget.js +1 -1
- package/dist/Deployable/DeployableTargetWithRBAC.cjs +1 -1
- package/dist/Deployable/DeployableTargetWithRBAC.js +23 -23
- package/dist/Incentives/AllowListIncentive.cjs +1 -1
- package/dist/Incentives/AllowListIncentive.js +8 -8
- package/dist/Incentives/CGDAIncentive.cjs +1 -1
- package/dist/Incentives/CGDAIncentive.js +12 -12
- package/dist/Incentives/ERC20Incentive.cjs +1 -1
- package/dist/Incentives/ERC20Incentive.js +16 -16
- package/dist/Incentives/ERC20VariableCriteriaIncentive.cjs +2 -0
- package/dist/Incentives/ERC20VariableCriteriaIncentive.cjs.map +1 -0
- package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts +42 -15
- package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20VariableCriteriaIncentive.js +188 -0
- package/dist/Incentives/ERC20VariableCriteriaIncentive.js.map +1 -0
- package/dist/Incentives/ERC20VariableIncentive.cjs +2 -0
- package/dist/Incentives/ERC20VariableIncentive.cjs.map +1 -0
- package/dist/Incentives/ERC20VariableIncentive.d.ts +7 -5
- package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -1
- package/dist/{Incentive-rM5nKznp.js → Incentives/ERC20VariableIncentive.js} +42 -67
- package/dist/Incentives/ERC20VariableIncentive.js.map +1 -0
- package/dist/Incentives/Incentive.cjs +1 -1
- package/dist/Incentives/Incentive.cjs.map +1 -1
- package/dist/Incentives/Incentive.d.ts +552 -3
- package/dist/Incentives/Incentive.d.ts.map +1 -1
- package/dist/Incentives/Incentive.js +40 -16
- package/dist/Incentives/Incentive.js.map +1 -1
- package/dist/Incentives/PointsIncentive.cjs +1 -1
- package/dist/Incentives/PointsIncentive.js +8 -8
- package/dist/{SimpleDenyList-DNj5qDWM.cjs → SimpleDenyList-BdlpZdDz.cjs} +2 -2
- package/dist/{SimpleDenyList-DNj5qDWM.cjs.map → SimpleDenyList-BdlpZdDz.cjs.map} +1 -1
- package/dist/{SimpleDenyList-BDXpY74P.js → SimpleDenyList-D0cyVUVv.js} +16 -16
- package/dist/{SimpleDenyList-BDXpY74P.js.map → SimpleDenyList-D0cyVUVv.js.map} +1 -1
- package/dist/Validators/LimitedSignerValidator.cjs +2 -0
- package/dist/Validators/LimitedSignerValidator.cjs.map +1 -0
- package/dist/Validators/LimitedSignerValidator.d.ts +806 -0
- package/dist/Validators/LimitedSignerValidator.d.ts.map +1 -0
- package/dist/Validators/LimitedSignerValidator.js +299 -0
- package/dist/Validators/LimitedSignerValidator.js.map +1 -0
- package/dist/Validators/SignerValidator.cjs +1 -1
- package/dist/Validators/SignerValidator.cjs.map +1 -1
- package/dist/Validators/SignerValidator.d.ts +2 -2
- package/dist/Validators/SignerValidator.js +5 -5
- package/dist/Validators/SignerValidator.js.map +1 -1
- package/dist/Validators/Validator.cjs +1 -1
- package/dist/Validators/Validator.cjs.map +1 -1
- package/dist/Validators/Validator.d.ts +22 -2
- package/dist/Validators/Validator.d.ts.map +1 -1
- package/dist/Validators/Validator.js +26 -17
- package/dist/Validators/Validator.js.map +1 -1
- package/dist/{componentInterfaces-BBCFkrZv.js → componentInterfaces-bIVo8eyA.js} +9 -9
- package/dist/componentInterfaces-bIVo8eyA.js.map +1 -0
- package/dist/{deployments-fJsWblwS.js → deployments-Ccx1MtoK.js} +5 -5
- package/dist/deployments-Ccx1MtoK.js.map +1 -0
- package/dist/{generated-CsNyWPKA.js → generated-BAKNSOjJ.js} +661 -381
- package/dist/generated-BAKNSOjJ.js.map +1 -0
- package/dist/generated-Cqn4wS01.cjs +3 -0
- package/dist/generated-Cqn4wS01.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +145 -132
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +27 -26
- package/dist/utils.js.map +1 -1
- package/package.json +21 -5
- package/src/Actions/EventAction.test.ts +381 -122
- package/src/Actions/EventAction.ts +85 -23
- package/src/BoostCore.test.ts +3 -3
- package/src/BoostCore.ts +51 -5
- package/src/Incentives/AllowListIncentive.test.ts +19 -21
- package/src/Incentives/CGDAIncentive.test.ts +20 -22
- package/src/Incentives/ERC1155Incentive.test.ts +14 -15
- package/src/Incentives/ERC20Incentive.test.ts +17 -19
- package/src/Incentives/ERC20VariableCriteriaIncentive.test.ts +62 -10
- package/src/Incentives/ERC20VariableCriteriaIncentive.ts +79 -37
- package/src/Incentives/ERC20VariableIncentive.test.ts +16 -18
- package/src/Incentives/ERC20VariableIncentive.ts +16 -8
- package/src/Incentives/Incentive.ts +4 -1
- package/src/Incentives/PointsIncentive.test.ts +3 -5
- package/src/Validators/LimitedSignerValidator.test.ts +223 -0
- package/src/Validators/LimitedSignerValidator.ts +707 -0
- package/src/Validators/SignerValidator.test.ts +21 -22
- package/src/Validators/SignerValidator.ts +2 -2
- package/src/Validators/Validator.test.ts +7 -1
- package/src/Validators/Validator.ts +30 -3
- package/src/index.test.ts +2 -0
- package/src/index.ts +1 -0
- package/src/utils.ts +11 -0
- package/dist/BoostCore-Btl5BdAs.cjs +0 -3
- package/dist/BoostCore-Btl5BdAs.cjs.map +0 -1
- package/dist/BoostCore-CD56zbYX.js +0 -2641
- package/dist/BoostCore-CD56zbYX.js.map +0 -1
- package/dist/Incentive-CcnOIc8L.cjs +0 -2
- package/dist/Incentive-CcnOIc8L.cjs.map +0 -1
- package/dist/Incentive-rM5nKznp.js.map +0 -1
- package/dist/componentInterfaces-BBCFkrZv.js.map +0 -1
- package/dist/deployments-fJsWblwS.js.map +0 -1
- package/dist/generated-CsNyWPKA.js.map +0 -1
- package/dist/generated-DHerxf1y.cjs +0 -3
- 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
|
+
});
|