@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.
- package/dist/Actions/Action.cjs +2 -1
- package/dist/Actions/Action.cjs.map +1 -0
- package/dist/Actions/Action.d.ts +1 -1
- package/dist/Actions/Action.d.ts.map +1 -1
- package/dist/Actions/Action.js +15 -13
- package/dist/Actions/Action.js.map +1 -0
- package/dist/Actions/EventAction.cjs +1 -0
- package/dist/Actions/EventAction.cjs.map +1 -0
- package/dist/Actions/EventAction.js +1 -0
- package/dist/Actions/EventAction.js.map +1 -0
- package/dist/AllowLists/AllowList.cjs +2 -1
- package/dist/AllowLists/AllowList.cjs.map +1 -0
- package/dist/AllowLists/AllowList.d.ts +1 -2
- package/dist/AllowLists/AllowList.d.ts.map +1 -1
- package/dist/AllowLists/AllowList.js +16 -14
- package/dist/AllowLists/AllowList.js.map +1 -0
- package/dist/AllowLists/SimpleAllowList.cjs +1 -0
- package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
- package/dist/AllowLists/SimpleAllowList.js +1 -0
- package/dist/AllowLists/SimpleAllowList.js.map +1 -0
- package/dist/AllowLists/SimpleDenyList.cjs +1 -0
- package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
- package/dist/AllowLists/SimpleDenyList.js +1 -0
- package/dist/AllowLists/SimpleDenyList.js.map +1 -0
- package/dist/Auth/Auth.cjs +1 -0
- package/dist/Auth/Auth.cjs.map +1 -0
- package/dist/Auth/Auth.js +1 -0
- package/dist/Auth/Auth.js.map +1 -0
- package/dist/Auth/PassthroughAuth.cjs +1 -0
- package/dist/Auth/PassthroughAuth.cjs.map +1 -0
- package/dist/Auth/PassthroughAuth.js +1 -0
- package/dist/Auth/PassthroughAuth.js.map +1 -0
- package/dist/Boost.cjs +1 -0
- package/dist/Boost.cjs.map +1 -0
- package/dist/Boost.js +1 -0
- package/dist/Boost.js.map +1 -0
- package/dist/BoostCore.cjs +1 -0
- package/dist/BoostCore.cjs.map +1 -0
- package/dist/BoostCore.js +1 -0
- package/dist/BoostCore.js.map +1 -0
- package/dist/BoostRegistry.cjs +1 -0
- package/dist/BoostRegistry.cjs.map +1 -0
- package/dist/BoostRegistry.js +1 -0
- package/dist/BoostRegistry.js.map +1 -0
- package/dist/Budgets/Budget.cjs +2 -1
- package/dist/Budgets/Budget.cjs.map +1 -0
- package/dist/Budgets/Budget.d.ts +1 -1
- package/dist/Budgets/Budget.d.ts.map +1 -1
- package/dist/Budgets/Budget.js +14 -12
- package/dist/Budgets/Budget.js.map +1 -0
- package/dist/Budgets/ManagedBudget.cjs +1 -0
- package/dist/Budgets/ManagedBudget.cjs.map +1 -0
- package/dist/Budgets/ManagedBudget.js +1 -0
- package/dist/Budgets/ManagedBudget.js.map +1 -0
- package/dist/Deployable/Contract.cjs +1 -0
- package/dist/Deployable/Contract.cjs.map +1 -0
- package/dist/Deployable/Contract.js +1 -0
- package/dist/Deployable/Contract.js.map +1 -0
- package/dist/Deployable/Deployable.cjs +1 -0
- package/dist/Deployable/Deployable.cjs.map +1 -0
- package/dist/Deployable/Deployable.js +1 -0
- package/dist/Deployable/Deployable.js.map +1 -0
- package/dist/Deployable/DeployableTarget.cjs +1 -0
- package/dist/Deployable/DeployableTarget.cjs.map +1 -0
- package/dist/Deployable/DeployableTarget.js +1 -0
- package/dist/Deployable/DeployableTarget.js.map +1 -0
- package/dist/Incentives/AllowListIncentive.cjs +1 -0
- package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
- package/dist/Incentives/AllowListIncentive.js +1 -0
- package/dist/Incentives/AllowListIncentive.js.map +1 -0
- package/dist/Incentives/CGDAIncentive.cjs +1 -0
- package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
- package/dist/Incentives/CGDAIncentive.js +1 -0
- package/dist/Incentives/CGDAIncentive.js.map +1 -0
- package/dist/Incentives/ERC20Incentive.cjs +1 -0
- package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
- package/dist/Incentives/ERC20Incentive.js +1 -0
- package/dist/Incentives/ERC20Incentive.js.map +1 -0
- package/dist/Incentives/Incentive.cjs +2 -1
- package/dist/Incentives/Incentive.cjs.map +1 -0
- package/dist/Incentives/Incentive.d.ts +1 -4
- package/dist/Incentives/Incentive.d.ts.map +1 -1
- package/dist/Incentives/Incentive.js +39 -36
- package/dist/Incentives/Incentive.js.map +1 -0
- package/dist/Incentives/PointsIncentive.cjs +1 -0
- package/dist/Incentives/PointsIncentive.cjs.map +1 -0
- package/dist/Incentives/PointsIncentive.js +1 -0
- package/dist/Incentives/PointsIncentive.js.map +1 -0
- package/dist/Validators/SignerValidator.cjs +1 -0
- package/dist/Validators/SignerValidator.cjs.map +1 -0
- package/dist/Validators/SignerValidator.js +1 -0
- package/dist/Validators/SignerValidator.js.map +1 -0
- package/dist/Validators/Validator.cjs +2 -1
- package/dist/Validators/Validator.cjs.map +1 -0
- package/dist/Validators/Validator.d.ts +1 -1
- package/dist/Validators/Validator.d.ts.map +1 -1
- package/dist/Validators/Validator.js +9 -7
- package/dist/Validators/Validator.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 +1 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.js +1 -0
- package/dist/errors.js.map +1 -0
- package/dist/generated-Cd-Fe7W7.cjs +1 -0
- package/dist/generated-Cd-Fe7W7.cjs.map +1 -0
- package/dist/generated-DGpIVcv5.js +1 -0
- package/dist/generated-DGpIVcv5.js.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/utils.cjs +1 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -0
- package/dist/utils.js.map +1 -0
- package/package.json +5 -3
- package/src/Actions/Action.test.ts +77 -0
- package/src/Actions/Action.ts +61 -0
- package/src/Actions/ContractAction.test.ts +199 -0
- package/src/Actions/ContractAction.ts +238 -0
- package/src/Actions/ERC721MintAction.test.ts +112 -0
- package/src/Actions/ERC721MintAction.ts +238 -0
- package/src/Actions/EventAction.test.ts +182 -0
- package/src/Actions/EventAction.ts +382 -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 +240 -0
- package/src/AllowLists/SimpleDenyList.test.ts +52 -0
- package/src/AllowLists/SimpleDenyList.ts +289 -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 +155 -0
- package/src/BoostCore.test.ts +846 -0
- package/src/BoostCore.ts +1192 -0
- package/src/BoostRegistry.ts +449 -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 +743 -0
- package/src/Budgets/SimpleBudget.test.ts +152 -0
- package/src/Budgets/SimpleBudget.ts +521 -0
- package/src/Budgets/VestingBudget.test.ts +123 -0
- package/src/Budgets/VestingBudget.ts +532 -0
- package/src/Deployable/Contract.ts +229 -0
- package/src/Deployable/Deployable.ts +244 -0
- package/src/Deployable/DeployableTarget.ts +210 -0
- package/src/Incentives/AllowListIncentive.test.ts +146 -0
- package/src/Incentives/AllowListIncentive.ts +290 -0
- package/src/Incentives/CGDAIncentive.test.ts +136 -0
- package/src/Incentives/CGDAIncentive.ts +364 -0
- package/src/Incentives/ERC1155Incentive.test.ts +98 -0
- package/src/Incentives/ERC1155Incentive.ts +384 -0
- package/src/Incentives/ERC20Incentive.test.ts +141 -0
- package/src/Incentives/ERC20Incentive.ts +417 -0
- package/src/Incentives/ERC20VariableIncentive.test.ts +156 -0
- package/src/Incentives/ERC20VariableIncentive.ts +368 -0
- package/src/Incentives/Incentive.test.ts +92 -0
- package/src/Incentives/Incentive.ts +85 -0
- package/src/Incentives/PointsIncentive.test.ts +142 -0
- package/src/Incentives/PointsIncentive.ts +303 -0
- package/src/Validators/SignerValidator.test.ts +163 -0
- package/src/Validators/SignerValidator.ts +272 -0
- package/src/Validators/Validator.test.ts +21 -0
- package/src/Validators/Validator.ts +55 -0
- package/src/errors.ts +524 -0
- package/src/index.test.ts +40 -0
- package/src/index.ts +50 -0
- package/src/utils.test.ts +44 -0
- package/src/utils.ts +2247 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import {
|
|
2
|
+
pointsIncentiveAbi,
|
|
3
|
+
readPointsIncentiveClaimed,
|
|
4
|
+
readPointsIncentiveClaims,
|
|
5
|
+
readPointsIncentiveCurrentReward,
|
|
6
|
+
readPointsIncentiveIsClaimable,
|
|
7
|
+
readPointsIncentiveLimit,
|
|
8
|
+
readPointsIncentiveReward,
|
|
9
|
+
readPointsIncentiveSelector,
|
|
10
|
+
readPointsIncentiveVenue,
|
|
11
|
+
simulatePointsIncentiveClaim,
|
|
12
|
+
writePointsIncentiveClaim,
|
|
13
|
+
} from '@boostxyz/evm';
|
|
14
|
+
import { bytecode } from '@boostxyz/evm/artifacts/contracts/incentives/PointsIncentive.sol/PointsIncentive.json';
|
|
15
|
+
import type { Address, ContractEventName, Hex } from 'viem';
|
|
16
|
+
import type {
|
|
17
|
+
DeployableOptions,
|
|
18
|
+
GenericDeployableParams,
|
|
19
|
+
} from '../Deployable/Deployable';
|
|
20
|
+
import { DeployableTarget } from '../Deployable/DeployableTarget';
|
|
21
|
+
import {
|
|
22
|
+
type ClaimPayload,
|
|
23
|
+
type GenericLog,
|
|
24
|
+
type PointsIncentivePayload,
|
|
25
|
+
type ReadParams,
|
|
26
|
+
RegistryType,
|
|
27
|
+
type WriteParams,
|
|
28
|
+
prepareClaimPayload,
|
|
29
|
+
preparePointsIncentivePayload,
|
|
30
|
+
} from '../utils';
|
|
31
|
+
|
|
32
|
+
export { pointsIncentiveAbi };
|
|
33
|
+
export type { PointsIncentivePayload };
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A generic `viem.Log` event with support for `PointsIncentive` event types.
|
|
37
|
+
*
|
|
38
|
+
* @export
|
|
39
|
+
* @typedef {PointsIncentiveLog}
|
|
40
|
+
* @template {ContractEventName<
|
|
41
|
+
* typeof pointsIncentiveAbi
|
|
42
|
+
* >} [event=ContractEventName<typeof pointsIncentiveAbi>]
|
|
43
|
+
*/
|
|
44
|
+
export type PointsIncentiveLog<
|
|
45
|
+
event extends ContractEventName<
|
|
46
|
+
typeof pointsIncentiveAbi
|
|
47
|
+
> = ContractEventName<typeof pointsIncentiveAbi>,
|
|
48
|
+
> = GenericLog<typeof pointsIncentiveAbi, event>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A simple on-chain points incentive implementation that allows claiming of soulbound tokens.
|
|
52
|
+
*
|
|
53
|
+
* In order for any claim to be successful:
|
|
54
|
+
* - The claimer must not have already claimed the incentive; and
|
|
55
|
+
* - The maximum number of claims must not have been reached; and
|
|
56
|
+
* - This contract must be authorized to operate the points contract's issuance function
|
|
57
|
+
*
|
|
58
|
+
* @export
|
|
59
|
+
* @class PointsIncentive
|
|
60
|
+
* @typedef {PointsIncentive}
|
|
61
|
+
* @extends {DeployableTarget<PointsIncentivePayload>}
|
|
62
|
+
*/
|
|
63
|
+
export class PointsIncentive extends DeployableTarget<
|
|
64
|
+
PointsIncentivePayload,
|
|
65
|
+
typeof pointsIncentiveAbi
|
|
66
|
+
> {
|
|
67
|
+
public override readonly abi = pointsIncentiveAbi;
|
|
68
|
+
/**
|
|
69
|
+
* @inheritdoc
|
|
70
|
+
*
|
|
71
|
+
* @public
|
|
72
|
+
* @static
|
|
73
|
+
* @type {Address}
|
|
74
|
+
*/
|
|
75
|
+
public static override base: Address = import.meta.env
|
|
76
|
+
.VITE_POINTS_INCENTIVE_BASE;
|
|
77
|
+
/**
|
|
78
|
+
* @inheritdoc
|
|
79
|
+
*
|
|
80
|
+
* @public
|
|
81
|
+
* @static
|
|
82
|
+
* @type {RegistryType}
|
|
83
|
+
*/
|
|
84
|
+
public static override registryType: RegistryType = RegistryType.INCENTIVE;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The number of claims that have been made
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
* @async
|
|
91
|
+
* @param {?ReadParams<typeof erc20IncentiveAbi, 'claims'>} [params]
|
|
92
|
+
* @returns {Promise<bigint>}
|
|
93
|
+
*/
|
|
94
|
+
public async claims(
|
|
95
|
+
params?: ReadParams<typeof pointsIncentiveAbi, 'claims'>,
|
|
96
|
+
) {
|
|
97
|
+
return readPointsIncentiveClaims(this._config, {
|
|
98
|
+
address: this.assertValidAddress(),
|
|
99
|
+
args: [],
|
|
100
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
101
|
+
...(params as any),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The current reward
|
|
107
|
+
*
|
|
108
|
+
* @public
|
|
109
|
+
* @async
|
|
110
|
+
* @param {?ReadParams<typeof erc20IncentiveAbi, 'currentReward'>} [params]
|
|
111
|
+
* @returns {Promise<bigint>} - The current reward
|
|
112
|
+
*/
|
|
113
|
+
public async currentReward(
|
|
114
|
+
params?: ReadParams<typeof pointsIncentiveAbi, 'currentReward'>,
|
|
115
|
+
) {
|
|
116
|
+
return readPointsIncentiveCurrentReward(this._config, {
|
|
117
|
+
address: this.assertValidAddress(),
|
|
118
|
+
args: [],
|
|
119
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
120
|
+
...(params as any),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The reward amount issued for each claim
|
|
126
|
+
*
|
|
127
|
+
* @public
|
|
128
|
+
* @async
|
|
129
|
+
* @param {?ReadParams<typeof pointsIncentiveAbi, 'reward'>} [params]
|
|
130
|
+
* @returns {unknown}
|
|
131
|
+
*/
|
|
132
|
+
public async reward(
|
|
133
|
+
params?: ReadParams<typeof pointsIncentiveAbi, 'reward'>,
|
|
134
|
+
) {
|
|
135
|
+
return readPointsIncentiveReward(this._config, {
|
|
136
|
+
address: this.assertValidAddress(),
|
|
137
|
+
args: [],
|
|
138
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
139
|
+
...(params as any),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A mapping of address to claim status
|
|
145
|
+
*
|
|
146
|
+
* @public
|
|
147
|
+
* @async
|
|
148
|
+
* @param {Address} address
|
|
149
|
+
* @param {?ReadParams<typeof pointsIncentiveAbi, 'claimed'>} [params]
|
|
150
|
+
* @returns {unknown}
|
|
151
|
+
*/
|
|
152
|
+
public async claimed(
|
|
153
|
+
address: Address,
|
|
154
|
+
params?: ReadParams<typeof pointsIncentiveAbi, 'claimed'>,
|
|
155
|
+
) {
|
|
156
|
+
return readPointsIncentiveClaimed(this._config, {
|
|
157
|
+
address: this.assertValidAddress(),
|
|
158
|
+
args: [address],
|
|
159
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
160
|
+
...(params as any),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The address of the points contract
|
|
166
|
+
*
|
|
167
|
+
* @public
|
|
168
|
+
* @async
|
|
169
|
+
* @param {?ReadParams<typeof pointsIncentiveAbi, 'venue'>} [params]
|
|
170
|
+
* @returns {unknown}
|
|
171
|
+
*/
|
|
172
|
+
public async venue(params?: ReadParams<typeof pointsIncentiveAbi, 'venue'>) {
|
|
173
|
+
return readPointsIncentiveVenue(this._config, {
|
|
174
|
+
address: this.assertValidAddress(),
|
|
175
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
176
|
+
...(params as any),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The maximum number of claims that can be made (one per address)
|
|
182
|
+
*
|
|
183
|
+
* @public
|
|
184
|
+
* @async
|
|
185
|
+
* @param {?ReadParams<typeof pointsIncentiveAbi, 'limit'>} [params]
|
|
186
|
+
* @returns {Promise<bigint>}
|
|
187
|
+
*/
|
|
188
|
+
public async limit(params?: ReadParams<typeof pointsIncentiveAbi, 'limit'>) {
|
|
189
|
+
return readPointsIncentiveLimit(this._config, {
|
|
190
|
+
address: this.assertValidAddress(),
|
|
191
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
192
|
+
...(params as any),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The selector for the issuance function on the points contract
|
|
198
|
+
*
|
|
199
|
+
* @public
|
|
200
|
+
* @async
|
|
201
|
+
* @param {?ReadParams<typeof pointsIncentiveAbi, 'selector'>} [params]
|
|
202
|
+
* @returns {Promise<Hex>}
|
|
203
|
+
*/
|
|
204
|
+
public async selector(
|
|
205
|
+
params?: ReadParams<typeof pointsIncentiveAbi, 'selector'>,
|
|
206
|
+
) {
|
|
207
|
+
return readPointsIncentiveSelector(this._config, {
|
|
208
|
+
address: this.assertValidAddress(),
|
|
209
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
210
|
+
...(params as any),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Claim the incentive
|
|
216
|
+
*
|
|
217
|
+
* @public
|
|
218
|
+
* @async
|
|
219
|
+
* @param {ClaimPayload} payload
|
|
220
|
+
* @param {?WriteParams<typeof pointsIncentiveAbi, 'claim'>} [params]
|
|
221
|
+
* @returns {Promise<boolean>} - True if the incentive was successfully claimed
|
|
222
|
+
*/
|
|
223
|
+
public async claim(
|
|
224
|
+
payload: ClaimPayload,
|
|
225
|
+
params?: WriteParams<typeof pointsIncentiveAbi, 'claim'>,
|
|
226
|
+
) {
|
|
227
|
+
return this.awaitResult(this.claimRaw(payload, params));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Claim the incentive
|
|
232
|
+
*
|
|
233
|
+
* @public
|
|
234
|
+
* @async
|
|
235
|
+
* @param {ClaimPayload} payload
|
|
236
|
+
* @param {?WriteParams<typeof pointsIncentiveAbi, 'claim'>} [params]
|
|
237
|
+
* @returns {Promise<boolean>} - True if the incentive was successfully claimed
|
|
238
|
+
*/
|
|
239
|
+
public async claimRaw(
|
|
240
|
+
payload: ClaimPayload,
|
|
241
|
+
params?: WriteParams<typeof pointsIncentiveAbi, 'claim'>,
|
|
242
|
+
) {
|
|
243
|
+
const { request, result } = await simulatePointsIncentiveClaim(
|
|
244
|
+
this._config,
|
|
245
|
+
{
|
|
246
|
+
address: this.assertValidAddress(),
|
|
247
|
+
args: [prepareClaimPayload(payload)],
|
|
248
|
+
...this.optionallyAttachAccount(),
|
|
249
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
250
|
+
...(params as any),
|
|
251
|
+
},
|
|
252
|
+
);
|
|
253
|
+
const hash = await writePointsIncentiveClaim(this._config, request);
|
|
254
|
+
return { hash, result };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Check if an incentive is claimable.
|
|
259
|
+
* For the POOL strategy, the `bytes data` portion of the payload ignored.
|
|
260
|
+
* The recipient must not have already claimed the incentive.
|
|
261
|
+
*
|
|
262
|
+
* @public
|
|
263
|
+
* @async
|
|
264
|
+
* @param {ClaimPayload} payload
|
|
265
|
+
* @param {?ReadParams<typeof pointsIncentiveAbi, 'isClaimable'>} [params]
|
|
266
|
+
* @returns {Promise<boolean>} - True if the incentive is claimable based on the data payload
|
|
267
|
+
*/
|
|
268
|
+
public async isClaimable(
|
|
269
|
+
payload: ClaimPayload,
|
|
270
|
+
params?: ReadParams<typeof pointsIncentiveAbi, 'isClaimable'>,
|
|
271
|
+
) {
|
|
272
|
+
return readPointsIncentiveIsClaimable(this._config, {
|
|
273
|
+
address: this.assertValidAddress(),
|
|
274
|
+
args: [prepareClaimPayload(payload)],
|
|
275
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
276
|
+
...(params as any),
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* @inheritdoc
|
|
282
|
+
*
|
|
283
|
+
* @public
|
|
284
|
+
* @param {?PointsIncentivePayload} [_payload]
|
|
285
|
+
* @param {?DeployableOptions} [_options]
|
|
286
|
+
* @returns {GenericDeployableParams}
|
|
287
|
+
*/
|
|
288
|
+
public override buildParameters(
|
|
289
|
+
_payload?: PointsIncentivePayload,
|
|
290
|
+
_options?: DeployableOptions,
|
|
291
|
+
): GenericDeployableParams {
|
|
292
|
+
const [payload, options] = this.validateDeploymentConfig(
|
|
293
|
+
_payload,
|
|
294
|
+
_options,
|
|
295
|
+
);
|
|
296
|
+
return {
|
|
297
|
+
abi: pointsIncentiveAbi,
|
|
298
|
+
bytecode: bytecode as Hex,
|
|
299
|
+
args: [preparePointsIncentivePayload(payload)],
|
|
300
|
+
...this.optionallyAttachAccount(options.account),
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
|
|
2
|
+
import { isAddress, pad } from 'viem';
|
|
3
|
+
import { beforeAll, describe, expect, test } from 'vitest';
|
|
4
|
+
import { accounts } from '../../test/accounts';
|
|
5
|
+
import {
|
|
6
|
+
type Fixtures,
|
|
7
|
+
defaultOptions,
|
|
8
|
+
deployFixtures,
|
|
9
|
+
} from '../../test/helpers';
|
|
10
|
+
import { testAccount } from '../../test/viem';
|
|
11
|
+
import { prepareSignerValidatorClaimDataPayload } from '../utils';
|
|
12
|
+
import { SignerValidator } from './SignerValidator';
|
|
13
|
+
|
|
14
|
+
let fixtures: Fixtures;
|
|
15
|
+
|
|
16
|
+
function freshValidator(fixtures: Fixtures) {
|
|
17
|
+
return function freshValidator() {
|
|
18
|
+
// biome-ignore lint/style/noNonNullAssertion: this will never be undefined
|
|
19
|
+
const account = accounts.at(1)!.account;
|
|
20
|
+
return fixtures.registry.clone(
|
|
21
|
+
crypto.randomUUID(),
|
|
22
|
+
new fixtures.bases.SignerValidator(defaultOptions, {
|
|
23
|
+
signers: [defaultOptions.account.address, account],
|
|
24
|
+
validatorCaller: testAccount.address,
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('SignerValidator', () => {
|
|
31
|
+
beforeAll(async () => {
|
|
32
|
+
fixtures = await loadFixture(deployFixtures);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('can successfully be deployed', async () => {
|
|
36
|
+
const action = new SignerValidator(defaultOptions, {
|
|
37
|
+
signers: [testAccount.address],
|
|
38
|
+
validatorCaller: testAccount.address,
|
|
39
|
+
});
|
|
40
|
+
await action.deploy();
|
|
41
|
+
expect(isAddress(action.assertValidAddress())).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('initializes successfully', async () => {
|
|
45
|
+
const validator = await loadFixture(freshValidator(fixtures));
|
|
46
|
+
expect(await validator.signers(defaultOptions.account.address)).toBe(true);
|
|
47
|
+
// biome-ignore lint/style/noNonNullAssertion: this will never be undefined
|
|
48
|
+
expect(await validator.signers(accounts.at(1)!.account)).toBe(true);
|
|
49
|
+
// biome-ignore lint/style/noNonNullAssertion: this will never be undefined
|
|
50
|
+
expect(await validator.signers(accounts.at(2)!.account)).toBe(false);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('can validate hashes', async () => {
|
|
54
|
+
const validator = await loadFixture(freshValidator(fixtures));
|
|
55
|
+
|
|
56
|
+
// Define the input data
|
|
57
|
+
const boostId = 5n;
|
|
58
|
+
const incentiveQuantity = 1;
|
|
59
|
+
const incentiveId = 0n;
|
|
60
|
+
const claimant = '0x24582544C98a86eE59687c4D5B55D78f4FffA666';
|
|
61
|
+
const incentiveData = pad('0xdef456232173821931823712381232131391321934');
|
|
62
|
+
|
|
63
|
+
// biome-ignore lint/style/noNonNullAssertion: this will never be undefined
|
|
64
|
+
const trustedSigner = accounts.at(0)!;
|
|
65
|
+
// biome-ignore lint/style/noNonNullAssertion: this will never be undefined
|
|
66
|
+
const untrustedSigner = accounts.at(2)!;
|
|
67
|
+
|
|
68
|
+
const claimDataPayload = await prepareSignerValidatorClaimDataPayload({
|
|
69
|
+
signer: trustedSigner,
|
|
70
|
+
incentiveData,
|
|
71
|
+
chainId: defaultOptions.config.chains[0].id,
|
|
72
|
+
validator: validator.assertValidAddress(),
|
|
73
|
+
incentiveQuantity,
|
|
74
|
+
claimant,
|
|
75
|
+
boostId: boostId,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const badClaimDataPayload = await prepareSignerValidatorClaimDataPayload({
|
|
79
|
+
signer: untrustedSigner,
|
|
80
|
+
incentiveData,
|
|
81
|
+
chainId: defaultOptions.config.chains[0].id,
|
|
82
|
+
validator: validator.assertValidAddress(),
|
|
83
|
+
incentiveQuantity,
|
|
84
|
+
claimant,
|
|
85
|
+
boostId: boostId,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Validation using trusted signer
|
|
89
|
+
expect(
|
|
90
|
+
await validator.validate({
|
|
91
|
+
boostId: boostId,
|
|
92
|
+
incentiveId: incentiveId,
|
|
93
|
+
claimData: claimDataPayload,
|
|
94
|
+
claimant: claimant,
|
|
95
|
+
}),
|
|
96
|
+
).toBe(true);
|
|
97
|
+
|
|
98
|
+
// Validation using untrusted signer should throw an error
|
|
99
|
+
try {
|
|
100
|
+
await validator.validate({
|
|
101
|
+
boostId: boostId,
|
|
102
|
+
incentiveId: incentiveId,
|
|
103
|
+
claimData: badClaimDataPayload,
|
|
104
|
+
claimant: claimant,
|
|
105
|
+
});
|
|
106
|
+
} catch (e) {
|
|
107
|
+
expect(e).toBeInstanceOf(Error);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
test('will not revalidate the same hash', async () => {
|
|
111
|
+
const validator = await loadFixture(freshValidator(fixtures));
|
|
112
|
+
|
|
113
|
+
// Define the input data
|
|
114
|
+
const boostId = 5n;
|
|
115
|
+
const incentiveQuantity = 1;
|
|
116
|
+
const incentiveId = 0n;
|
|
117
|
+
const claimant = '0x24582544C98a86eE59687c4D5B55D78f4FffA666';
|
|
118
|
+
const incentiveData = pad('0xdef456232173821931823712381232131391321934');
|
|
119
|
+
|
|
120
|
+
// biome-ignore lint/style/noNonNullAssertion: this will never be undefined
|
|
121
|
+
const trustedSigner = accounts.at(0)!;
|
|
122
|
+
|
|
123
|
+
const claimDataPayload = await prepareSignerValidatorClaimDataPayload({
|
|
124
|
+
signer: trustedSigner,
|
|
125
|
+
incentiveData,
|
|
126
|
+
chainId: defaultOptions.config.chains[0].id,
|
|
127
|
+
validator: validator.assertValidAddress(),
|
|
128
|
+
incentiveQuantity,
|
|
129
|
+
claimant,
|
|
130
|
+
boostId: boostId,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
expect(
|
|
134
|
+
await validator.validate({
|
|
135
|
+
boostId,
|
|
136
|
+
incentiveId,
|
|
137
|
+
claimant,
|
|
138
|
+
claimData: claimDataPayload,
|
|
139
|
+
}),
|
|
140
|
+
).toBe(true);
|
|
141
|
+
|
|
142
|
+
// Attempt to validate the same hash again (should throw an error)
|
|
143
|
+
try {
|
|
144
|
+
await validator.validate({
|
|
145
|
+
boostId,
|
|
146
|
+
incentiveId,
|
|
147
|
+
claimData: claimDataPayload,
|
|
148
|
+
claimant,
|
|
149
|
+
});
|
|
150
|
+
} catch (e) {
|
|
151
|
+
expect(e).toBeInstanceOf(Error);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('can set authorized', async () => {
|
|
156
|
+
const validator = await loadFixture(freshValidator(fixtures));
|
|
157
|
+
// biome-ignore lint/style/noNonNullAssertion: this will never be undefined
|
|
158
|
+
const newSigner = accounts.at(2)!.account;
|
|
159
|
+
expect(await validator.signers(newSigner)).toBe(false);
|
|
160
|
+
await validator.setAuthorized([newSigner], [true]);
|
|
161
|
+
expect(await validator.signers(newSigner)).toBe(true);
|
|
162
|
+
});
|
|
163
|
+
});
|