@boostxyz/sdk 5.0.0 → 5.1.0

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 (126) hide show
  1. package/dist/Actions/Action.cjs +1 -1
  2. package/dist/Actions/Action.js +5 -5
  3. package/dist/Actions/EventAction.cjs +1 -1
  4. package/dist/Actions/EventAction.cjs.map +1 -1
  5. package/dist/Actions/EventAction.d.ts +18 -0
  6. package/dist/Actions/EventAction.d.ts.map +1 -1
  7. package/dist/Actions/EventAction.js +201 -132
  8. package/dist/Actions/EventAction.js.map +1 -1
  9. package/dist/AllowLists/AllowList.cjs +1 -1
  10. package/dist/AllowLists/AllowList.js +3 -3
  11. package/dist/AllowLists/SimpleAllowList.cjs +1 -1
  12. package/dist/AllowLists/SimpleAllowList.js +8 -8
  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 -2
  18. package/dist/BoostCore.cjs.map +1 -1
  19. package/dist/BoostCore.d.ts +14 -0
  20. package/dist/BoostCore.d.ts.map +1 -1
  21. package/dist/BoostCore.js +94 -75
  22. package/dist/BoostCore.js.map +1 -1
  23. package/dist/BoostRegistry.cjs +1 -1
  24. package/dist/BoostRegistry.js +6 -6
  25. package/dist/{Budget-fHCvlPfB.js → Budget-CTxrE06r.js} +53 -53
  26. package/dist/{Budget-fHCvlPfB.js.map → Budget-CTxrE06r.js.map} +1 -1
  27. package/dist/{Budget-Cnyh81n5.cjs → Budget-Cui2BUr4.cjs} +2 -2
  28. package/dist/{Budget-Cnyh81n5.cjs.map → Budget-Cui2BUr4.cjs.map} +1 -1
  29. package/dist/Budgets/Budget.cjs +1 -1
  30. package/dist/Budgets/Budget.js +3 -3
  31. package/dist/Budgets/ManagedBudget.cjs +1 -1
  32. package/dist/Budgets/ManagedBudget.js +29 -29
  33. package/dist/Deployable/DeployableTarget.cjs +1 -1
  34. package/dist/Deployable/DeployableTarget.js +1 -1
  35. package/dist/Deployable/DeployableTargetWithRBAC.cjs +1 -1
  36. package/dist/Deployable/DeployableTargetWithRBAC.js +15 -15
  37. package/dist/Incentive-AWwdbmix.cjs +2 -0
  38. package/dist/Incentive-AWwdbmix.cjs.map +1 -0
  39. package/dist/Incentive-CsFJZxYl.js +901 -0
  40. package/dist/Incentive-CsFJZxYl.js.map +1 -0
  41. package/dist/Incentives/AllowListIncentive.cjs +1 -1
  42. package/dist/Incentives/AllowListIncentive.js +11 -11
  43. package/dist/Incentives/CGDAIncentive.cjs +1 -1
  44. package/dist/Incentives/CGDAIncentive.cjs.map +1 -1
  45. package/dist/Incentives/CGDAIncentive.d.ts +1 -1
  46. package/dist/Incentives/CGDAIncentive.d.ts.map +1 -1
  47. package/dist/Incentives/CGDAIncentive.js +24 -22
  48. package/dist/Incentives/CGDAIncentive.js.map +1 -1
  49. package/dist/Incentives/ERC20Incentive.cjs +1 -1
  50. package/dist/Incentives/ERC20Incentive.cjs.map +1 -1
  51. package/dist/Incentives/ERC20Incentive.js +19 -19
  52. package/dist/Incentives/ERC20Incentive.js.map +1 -1
  53. package/dist/Incentives/ERC20PeggedVariableCriteriaIncentive.d.ts +1035 -0
  54. package/dist/Incentives/ERC20PeggedVariableCriteriaIncentive.d.ts.map +1 -0
  55. package/dist/Incentives/ERC20VariableCriteriaIncentive.cjs +1 -1
  56. package/dist/Incentives/ERC20VariableCriteriaIncentive.cjs.map +1 -1
  57. package/dist/Incentives/ERC20VariableCriteriaIncentive.js +19 -19
  58. package/dist/Incentives/ERC20VariableCriteriaIncentive.js.map +1 -1
  59. package/dist/Incentives/ERC20VariableIncentive.cjs +1 -1
  60. package/dist/Incentives/ERC20VariableIncentive.cjs.map +1 -1
  61. package/dist/Incentives/ERC20VariableIncentive.d.ts +1 -1
  62. package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -1
  63. package/dist/Incentives/ERC20VariableIncentive.js +25 -23
  64. package/dist/Incentives/ERC20VariableIncentive.js.map +1 -1
  65. package/dist/Incentives/Incentive.cjs +1 -1
  66. package/dist/Incentives/Incentive.d.ts +6 -5
  67. package/dist/Incentives/Incentive.d.ts.map +1 -1
  68. package/dist/Incentives/Incentive.js +17 -16
  69. package/dist/Incentives/PointsIncentive.cjs +1 -1
  70. package/dist/Incentives/PointsIncentive.js +8 -8
  71. package/dist/{SimpleDenyList-CgQvS1ek.cjs → SimpleDenyList-DQT0Fj3v.cjs} +2 -2
  72. package/dist/{SimpleDenyList-CgQvS1ek.cjs.map → SimpleDenyList-DQT0Fj3v.cjs.map} +1 -1
  73. package/dist/{SimpleDenyList-GZlSeh2G.js → SimpleDenyList-kcqV-01w.js} +12 -12
  74. package/dist/{SimpleDenyList-GZlSeh2G.js.map → SimpleDenyList-kcqV-01w.js.map} +1 -1
  75. package/dist/Validators/LimitedSignerValidator.cjs +1 -1
  76. package/dist/Validators/LimitedSignerValidator.js +18 -18
  77. package/dist/Validators/SignerValidator.cjs +1 -1
  78. package/dist/Validators/SignerValidator.js +16 -16
  79. package/dist/Validators/Validator.cjs +1 -1
  80. package/dist/Validators/Validator.js +4 -4
  81. package/dist/componentInterfaces-D7r9xJmt.cjs +2 -0
  82. package/dist/componentInterfaces-D7r9xJmt.cjs.map +1 -0
  83. package/dist/componentInterfaces-PR3ijhgZ.js +18 -0
  84. package/dist/componentInterfaces-PR3ijhgZ.js.map +1 -0
  85. package/dist/{deployments-CMdsItcq.cjs → deployments-BNFI9vnc.cjs} +2 -2
  86. package/dist/deployments-BNFI9vnc.cjs.map +1 -0
  87. package/dist/{deployments-DzhmI-zL.js → deployments-D68FgefY.js} +31 -31
  88. package/dist/deployments-D68FgefY.js.map +1 -0
  89. package/dist/deployments.json +20 -15
  90. package/dist/generated-CRD9XfOT.cjs +3 -0
  91. package/dist/generated-CRD9XfOT.cjs.map +1 -0
  92. package/dist/{generated-Hbd0NIf9.js → generated-ClbO_ULI.js} +1274 -709
  93. package/dist/generated-ClbO_ULI.js.map +1 -0
  94. package/dist/index.cjs +1 -1
  95. package/dist/index.d.ts +1 -0
  96. package/dist/index.d.ts.map +1 -1
  97. package/dist/index.js +133 -129
  98. package/dist/utils.cjs +1 -1
  99. package/dist/utils.cjs.map +1 -1
  100. package/dist/utils.d.ts +7 -1
  101. package/dist/utils.d.ts.map +1 -1
  102. package/dist/utils.js +1121 -41
  103. package/dist/utils.js.map +1 -1
  104. package/package.json +1 -1
  105. package/src/Actions/EventAction.ts +85 -1
  106. package/src/BoostCore.ts +27 -0
  107. package/src/Incentives/CGDAIncentive.ts +3 -1
  108. package/src/Incentives/ERC20PeggedVariableCriteriaIncentive.test.ts +315 -0
  109. package/src/Incentives/ERC20PeggedVariableCriteriaIncentive.ts +728 -0
  110. package/src/Incentives/ERC20VariableIncentive.ts +3 -1
  111. package/src/Incentives/Incentive.ts +8 -2
  112. package/src/index.ts +1 -0
  113. package/src/utils.ts +10 -0
  114. package/dist/Incentive-M45PaQsT.js +0 -397
  115. package/dist/Incentive-M45PaQsT.js.map +0 -1
  116. package/dist/Incentive-axLU7ndr.cjs +0 -2
  117. package/dist/Incentive-axLU7ndr.cjs.map +0 -1
  118. package/dist/componentInterfaces-Bt-4sNB5.cjs +0 -2
  119. package/dist/componentInterfaces-Bt-4sNB5.cjs.map +0 -1
  120. package/dist/componentInterfaces-C4uAYjSo.js +0 -16
  121. package/dist/componentInterfaces-C4uAYjSo.js.map +0 -1
  122. package/dist/deployments-CMdsItcq.cjs.map +0 -1
  123. package/dist/deployments-DzhmI-zL.js.map +0 -1
  124. package/dist/generated-CNkDfjzI.cjs +0 -3
  125. package/dist/generated-CNkDfjzI.cjs.map +0 -1
  126. package/dist/generated-Hbd0NIf9.js.map +0 -1
@@ -0,0 +1,728 @@
1
+ import {
2
+ erc20PeggedVariableCriteriaIncentiveAbi,
3
+ readErc20PeggedVariableCriteriaIncentiveAsset,
4
+ readErc20PeggedVariableCriteriaIncentiveClaimed,
5
+ readErc20PeggedVariableCriteriaIncentiveClaims,
6
+ readErc20PeggedVariableCriteriaIncentiveCurrentReward,
7
+ readErc20PeggedVariableCriteriaIncentiveGetIncentiveCriteria,
8
+ readErc20PeggedVariableCriteriaIncentiveGetMaxReward,
9
+ readErc20PeggedVariableCriteriaIncentiveGetPeg,
10
+ readErc20PeggedVariableCriteriaIncentiveIsClaimable,
11
+ readErc20PeggedVariableCriteriaIncentiveLimit,
12
+ readErc20PeggedVariableCriteriaIncentiveOwner,
13
+ readErc20PeggedVariableCriteriaIncentivePeg,
14
+ readErc20PeggedVariableCriteriaIncentiveReward,
15
+ readErc20PeggedVariableCriteriaIncentiveTotalClaimed,
16
+ simulateErc20PeggedVariableCriteriaIncentiveClaim,
17
+ simulateErc20PeggedVariableCriteriaIncentiveClawback,
18
+ writeErc20PeggedVariableCriteriaIncentiveClaim,
19
+ writeErc20PeggedVariableCriteriaIncentiveClawback,
20
+ } from '@boostxyz/evm';
21
+ import { bytecode } from '@boostxyz/evm/artifacts/contracts/incentives/ERC20PeggedVariableCriteriaIncentive.sol/ERC20PeggedVariableCriteriaIncentive.json';
22
+ import { getTransaction, getTransactionReceipt } from '@wagmi/core';
23
+ import type { AbiEvent } from 'abitype';
24
+ import {
25
+ type AbiFunction,
26
+ type Address,
27
+ type ContractEventName,
28
+ type Hex,
29
+ decodeFunctionData,
30
+ encodeAbiParameters,
31
+ parseEventLogs,
32
+ zeroAddress,
33
+ } from 'viem';
34
+ import { ERC20Incentive as ERC20IncentiveBases } from '../../dist/deployments.json';
35
+ import { SignatureType } from '../Actions/EventAction';
36
+ import type {
37
+ DeployableOptions,
38
+ GenericDeployableParams,
39
+ } from '../Deployable/Deployable';
40
+ import { DeployableTarget } from '../Deployable/DeployableTarget';
41
+ import { type ClaimPayload, prepareClaimPayload } from '../claiming';
42
+ import {
43
+ DecodedArgsError,
44
+ IncentiveCriteriaNotFoundError,
45
+ InvalidCriteriaTypeError,
46
+ NoMatchingLogsError,
47
+ } from '../errors';
48
+ import {
49
+ CheatCodes,
50
+ type GenericLog,
51
+ type ReadParams,
52
+ RegistryType,
53
+ type WriteParams,
54
+ } from '../utils';
55
+ import type {
56
+ GetIncentiveScalarParams,
57
+ IncentiveCriteria,
58
+ } from './ERC20VariableCriteriaIncentive';
59
+
60
+ export { erc20PeggedVariableCriteriaIncentiveAbi };
61
+
62
+ /**
63
+ * The object representation of a `Erc20PeggedVariableCriteriaIncentive.InitPayload`
64
+ *
65
+ * @export
66
+ * @interface Erc20PeggedVariableCriteriaIncentive
67
+ * @typedef {Erc20PeggedVariableCriteriaIncentive}
68
+ */
69
+ export interface ERC20PeggedVariableCriteriaIncentivePayload {
70
+ /**
71
+ * The address of the incentivized asset.
72
+ *
73
+ * @type {Address}
74
+ */
75
+ asset: Address;
76
+ /**
77
+ * The peg to normalize to.
78
+ *
79
+ * @type {Address}
80
+ */
81
+ peg: Address;
82
+ /**
83
+ * The amount of the asset to distribute.
84
+ *
85
+ * @type {bigint}
86
+ */
87
+ reward: bigint;
88
+ /**
89
+ * Total spend for the incentive.
90
+ *
91
+ * @type {bigint}
92
+ */
93
+ limit: bigint;
94
+ /**
95
+ * Maximum reward each claim is elligible for.
96
+ *
97
+ * @type {bigint}
98
+ */
99
+ maxReward: bigint;
100
+ /**
101
+ * (Optional) The address of the entity that can managed the incentive.
102
+ *
103
+ * @type {Address}
104
+ * @optional
105
+ */
106
+ manager?: Address;
107
+ /**
108
+ * The criteria for the incentive that determines how the reward is distributed.
109
+ *
110
+ * @type {IncentiveCriteria}
111
+ */
112
+ criteria: IncentiveCriteria;
113
+ }
114
+
115
+ /**
116
+ * A generic `viem.Log` event with support for `Erc20PeggedVariableCriteriaIncentive` event types.
117
+ *
118
+ * @export
119
+ * @typedef {Erc20PeggedVariableCriteriaIncentiveLog}
120
+ * @template {ContractEventName<typeof erc20PeggedVariableCriteriaIncentiveAbi>} [event=ContractEventName<
121
+ * typeof erc20PeggedVariableCriteriaIncentiveAbi
122
+ * >]
123
+ */
124
+ export type Erc20PeggedVariableCriteriaIncentiveLog<
125
+ event extends ContractEventName<
126
+ typeof erc20PeggedVariableCriteriaIncentiveAbi
127
+ > = ContractEventName<typeof erc20PeggedVariableCriteriaIncentiveAbi>,
128
+ > = GenericLog<typeof erc20PeggedVariableCriteriaIncentiveAbi, event>;
129
+
130
+ /**
131
+ * A simple ERC20 incentive implementation that allows claiming of tokens
132
+ *
133
+ * @export
134
+ * @class Erc20PeggedVariableCriteriaIncentive
135
+ * @typedef {ERC20PeggedVariableCriteriaIncentive}
136
+ * @extends {DeployableTarget<ERC20PeggedVariableCriteriaIncentive>}
137
+ */
138
+ export class ERC20PeggedVariableCriteriaIncentive extends DeployableTarget<
139
+ ERC20PeggedVariableCriteriaIncentivePayload,
140
+ typeof erc20PeggedVariableCriteriaIncentiveAbi
141
+ > {
142
+ public override readonly abi = erc20PeggedVariableCriteriaIncentiveAbi;
143
+ /**
144
+ * @inheritdoc
145
+ *
146
+ * @public
147
+ * @static
148
+ * @type {Record<number, Address>}
149
+ */
150
+ public static override bases: Record<number, Address> = {
151
+ 31337: import.meta.env.VITE_ERC20_INCENTIVE_BASE,
152
+ ...(ERC20IncentiveBases as Record<number, Address>),
153
+ };
154
+ /**
155
+ * @inheritdoc
156
+ *
157
+ * @public
158
+ * @static
159
+ * @type {RegistryType}
160
+ */
161
+ public static override registryType: RegistryType = RegistryType.INCENTIVE;
162
+
163
+ /**
164
+ * The owner of the incentive
165
+ *
166
+ * @public
167
+ * @async
168
+ * @param {?ReadParams} [params]
169
+ * @returns {Promise<Address>}
170
+ */
171
+ public async owner(params?: ReadParams) {
172
+ return await readErc20PeggedVariableCriteriaIncentiveOwner(this._config, {
173
+ address: this.assertValidAddress(),
174
+ args: [],
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
+ * Calculates the current reward based on the time since the last claim. The reward is calculated based on the time since the last claim, the available budget, and the reward parameters. It increases linearly over time in the absence of claims, with each hour adding `rewardBoost` to the current reward, up to the available budget. For example, if there is one claim in the first hour, then no claims for three hours, the claimable reward would be `initialReward - rewardDecay + (rewardBoost * 3)`
182
+ *
183
+ * @public
184
+ * @async
185
+ * @param {?ReadParams} [params]
186
+ * @returns {Promise<bigint>} - The current reward
187
+ */
188
+ public async currentReward(params?: ReadParams) {
189
+ return await readErc20PeggedVariableCriteriaIncentiveCurrentReward(
190
+ this._config,
191
+ {
192
+ address: this.assertValidAddress(),
193
+ args: [],
194
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
195
+ ...(params as any),
196
+ },
197
+ );
198
+ }
199
+
200
+ /**
201
+ * Retrieves the maximum reward amount per claim.
202
+ *
203
+ * @public
204
+ * @async
205
+ * @param {?ReadParams} [params]
206
+ * @returns {Promise<bigint>} The maximum reward amount per claim
207
+ */
208
+ public async getMaxReward(params?: ReadParams): Promise<bigint> {
209
+ const maxReward =
210
+ await readErc20PeggedVariableCriteriaIncentiveGetMaxReward(this._config, {
211
+ ...params,
212
+ address: this.assertValidAddress(),
213
+ });
214
+
215
+ return maxReward;
216
+ }
217
+
218
+ /**
219
+ * Fetches the incentive scalar from a transaction hash
220
+ *
221
+ * @param {GetIncentiveScalarParams} params
222
+ * @param {?ReadParams} [params]
223
+ * @returns {Promise<bigint>}
224
+ * @throws {InvalidCriteriaTypeError | NoMatchingLogsError | DecodedArgsError}
225
+ */
226
+ public async getIncentiveScalar(
227
+ { chainId, hash, knownSignatures }: GetIncentiveScalarParams,
228
+ params?: ReadParams,
229
+ ): Promise<bigint> {
230
+ const criteria = await this.getIncentiveCriteria(params);
231
+ if (criteria.criteriaType === SignatureType.EVENT) {
232
+ const transactionReceipt = await getTransactionReceipt(this._config, {
233
+ chainId,
234
+ hash,
235
+ });
236
+ if (criteria.fieldIndex === CheatCodes.GAS_REBATE_INCENTIVE) {
237
+ const totalCost =
238
+ transactionReceipt.gasUsed * transactionReceipt.effectiveGasPrice + // Normal gas cost
239
+ (transactionReceipt.blobGasUsed ?? 0n) *
240
+ (transactionReceipt.blobGasPrice ?? 0n); // Blob gas cost - account for potential undefined values
241
+ return totalCost;
242
+ }
243
+ const logs = transactionReceipt.logs;
244
+
245
+ if (logs.length === 0) {
246
+ throw new NoMatchingLogsError(
247
+ `No logs found for event signature ${criteria.signature}`,
248
+ );
249
+ }
250
+
251
+ // Decode the event log
252
+ try {
253
+ // Decode function data
254
+ const eventAbi = knownSignatures[criteria.signature] as AbiEvent;
255
+ const decodedEvents = parseEventLogs({
256
+ abi: [eventAbi],
257
+ logs,
258
+ });
259
+ if (decodedEvents == undefined || decodedEvents.length === 0) {
260
+ throw new NoMatchingLogsError(
261
+ `No logs found for event signature ${criteria.signature}`,
262
+ );
263
+ }
264
+ const scalarValue = (decodedEvents[0]?.args as string[])[
265
+ criteria.fieldIndex
266
+ ];
267
+
268
+ if (scalarValue === undefined) {
269
+ throw new DecodedArgsError(
270
+ `Decoded argument at index ${criteria.fieldIndex} is undefined`,
271
+ );
272
+ }
273
+ return BigInt(scalarValue);
274
+ } catch (e) {
275
+ throw new DecodedArgsError(
276
+ `Failed to decode event log for signature ${criteria.signature}: ${(e as Error).message}`,
277
+ );
278
+ }
279
+ } else if (criteria.criteriaType === SignatureType.FUNC) {
280
+ // Fetch the transaction data
281
+ const transaction = await getTransaction(this._config, {
282
+ chainId,
283
+ hash,
284
+ });
285
+ try {
286
+ // Decode function data
287
+ const func = knownSignatures[criteria.signature] as AbiFunction;
288
+ const decodedFunction = decodeFunctionData({
289
+ abi: [func],
290
+ data: transaction.input,
291
+ });
292
+ const scalarValue = decodedFunction.args[criteria.fieldIndex] as string;
293
+ if (scalarValue === undefined || scalarValue === null) {
294
+ throw new DecodedArgsError(
295
+ `Decoded argument at index ${criteria.fieldIndex} is undefined`,
296
+ );
297
+ }
298
+ return BigInt(scalarValue);
299
+ } catch (e) {
300
+ throw new DecodedArgsError(
301
+ `Failed to decode function data for signature ${criteria.signature}: ${(e as Error).message}`,
302
+ );
303
+ }
304
+ } else {
305
+ throw new InvalidCriteriaTypeError(
306
+ `Invalid criteria type ${criteria.criteriaType}`,
307
+ );
308
+ }
309
+ }
310
+
311
+ /**
312
+ * The number of claims that have been made
313
+ *
314
+ * @public
315
+ * @async
316
+ * @param {?ReadParams} [params]
317
+ * @returns {Promise<bigint>}
318
+ */
319
+ public async claims(params?: ReadParams) {
320
+ return await readErc20PeggedVariableCriteriaIncentiveClaims(this._config, {
321
+ address: this.assertValidAddress(),
322
+ args: [],
323
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
324
+ ...(params as any),
325
+ });
326
+ }
327
+
328
+ /**
329
+ * The total amount of rewards claimed
330
+ *
331
+ * @public
332
+ * @async
333
+ * @param {?ReadParams} [params]
334
+ * @returns {Promise<bigint>}
335
+ */
336
+ public async totalClaimed(params?: ReadParams) {
337
+ return await readErc20PeggedVariableCriteriaIncentiveTotalClaimed(
338
+ this._config,
339
+ {
340
+ address: this.assertValidAddress(),
341
+ args: [],
342
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
343
+ ...(params as any),
344
+ },
345
+ );
346
+ }
347
+
348
+ /**
349
+ * A mapping of address to claim status
350
+ *
351
+ * @public
352
+ * @async
353
+ * @param {Address} address
354
+ * @param {?ReadParams} [params]
355
+ * @returns {Promise<boolean>}
356
+ */
357
+ public async claimed(address: Address, params?: ReadParams) {
358
+ return await readErc20PeggedVariableCriteriaIncentiveClaimed(this._config, {
359
+ address: this.assertValidAddress(),
360
+ args: [address],
361
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
362
+ ...(params as any),
363
+ });
364
+ }
365
+
366
+ /**
367
+ * The address of the ERC20-like token
368
+ *
369
+ * @public
370
+ * @async
371
+ * @param {?ReadParams} [params]
372
+ * @returns {Promise<Address>}
373
+ */
374
+ public async asset(params?: ReadParams) {
375
+ return await readErc20PeggedVariableCriteriaIncentiveAsset(this._config, {
376
+ address: this.assertValidAddress(),
377
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
378
+ ...(params as any),
379
+ });
380
+ }
381
+
382
+ /**
383
+ * The address of the pegged ERC20-like token
384
+ *
385
+ * @public
386
+ * @async
387
+ * @param {?ReadParams} [params]
388
+ * @returns {Promise<Address>}
389
+ */
390
+ public async peg(params?: ReadParams) {
391
+ return await readErc20PeggedVariableCriteriaIncentivePeg(this._config, {
392
+ address: this.assertValidAddress(),
393
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
394
+ ...(params as any),
395
+ });
396
+ }
397
+
398
+ /**
399
+ * The reward amount issued for each claim
400
+ *
401
+ * @public
402
+ * @async
403
+ * @param {?ReadParams} [params]
404
+ * @returns {Promise<bigint>}
405
+ */
406
+ public async reward(params?: ReadParams) {
407
+ return await readErc20PeggedVariableCriteriaIncentiveReward(this._config, {
408
+ address: this.assertValidAddress(),
409
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
410
+ ...(params as any),
411
+ });
412
+ }
413
+
414
+ /**
415
+ * The limit (max possible rewards payout in reward token)
416
+ *
417
+ * @public
418
+ * @async
419
+ * @param {?ReadParams} [params]
420
+ * @returns {Promise<bigint>}
421
+ */
422
+ public async limit(params?: ReadParams) {
423
+ return await readErc20PeggedVariableCriteriaIncentiveLimit(this._config, {
424
+ address: this.assertValidAddress(),
425
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
426
+ ...(params as any),
427
+ });
428
+ }
429
+
430
+ /**
431
+ * Claim the incentive
432
+ *
433
+ * @public
434
+ * @async
435
+ * @param {ClaimPayload} payload
436
+ * @param {?WriteParams} [params]
437
+ * @returns {Promise<boolean>} - Returns true if successfully claimed
438
+ */
439
+ protected async claim(payload: ClaimPayload, params?: WriteParams) {
440
+ return await this.awaitResult(this.claimRaw(payload, params));
441
+ }
442
+
443
+ /**
444
+ * Claim the incentive
445
+ *
446
+ * @public
447
+ * @async
448
+ * @param {ClaimPayload} payload
449
+ * @param {?WriteParams} [params]
450
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - Returns true if successfully claimed
451
+ */
452
+ protected async claimRaw(payload: ClaimPayload, params?: WriteParams) {
453
+ const { request, result } =
454
+ await simulateErc20PeggedVariableCriteriaIncentiveClaim(this._config, {
455
+ address: this.assertValidAddress(),
456
+ args: [prepareClaimPayload(payload)],
457
+ ...this.optionallyAttachAccount(),
458
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
459
+ ...(params as any),
460
+ });
461
+ const hash = await writeErc20PeggedVariableCriteriaIncentiveClaim(
462
+ this._config,
463
+ request,
464
+ );
465
+ return { hash, result };
466
+ }
467
+
468
+ /**
469
+ * Clawback assets from the incentive
470
+ *
471
+ * @public
472
+ * @async
473
+ * @param {ClaimPayload} payload
474
+ * @param {?WriteParams} [params]
475
+ * @returns {Promise<boolean>} - True if the assets were successfully clawbacked
476
+ */
477
+ public async clawback(payload: ClaimPayload, params?: WriteParams) {
478
+ return await this.awaitResult(this.clawbackRaw(payload, params));
479
+ }
480
+
481
+ /**
482
+ * Clawback assets from the incentive
483
+ *
484
+ * @public
485
+ * @async
486
+ * @param {ClaimPayload} payload
487
+ * @param {?WriteParams} [params]
488
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if the assets were successfully clawbacked
489
+ */
490
+ public async clawbackRaw(payload: ClaimPayload, params?: WriteParams) {
491
+ const { request, result } =
492
+ await simulateErc20PeggedVariableCriteriaIncentiveClawback(this._config, {
493
+ address: this.assertValidAddress(),
494
+ args: [prepareClaimPayload(payload)],
495
+ ...this.optionallyAttachAccount(),
496
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
497
+ ...(params as any),
498
+ });
499
+ const hash = await writeErc20PeggedVariableCriteriaIncentiveClawback(
500
+ this._config,
501
+ request,
502
+ );
503
+ return { hash, result };
504
+ }
505
+
506
+ /**
507
+ * Check if an incentive is claimable.
508
+ *
509
+ * @public
510
+ * @async
511
+ * @param {ClaimPayload} payload
512
+ * @param {?ReadParams} [params]
513
+ * @returns {Promise<boolean>} = True if the incentive is claimable based on the data payload
514
+ */
515
+ public async isClaimable(payload: ClaimPayload, params?: ReadParams) {
516
+ return await readErc20PeggedVariableCriteriaIncentiveIsClaimable(
517
+ this._config,
518
+ {
519
+ address: this.assertValidAddress(),
520
+ args: [payload.target, payload.data],
521
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
522
+ ...(params as any),
523
+ },
524
+ );
525
+ }
526
+
527
+ /**
528
+ * read the peg token for the incentive.
529
+ *
530
+ * @public
531
+ * @async
532
+ * @param {?ReadParams} [params]
533
+ * @returns {Promise<Address>} = The address of the token the reward is pegged to
534
+ */
535
+ public async getPeg(params?: ReadParams) {
536
+ return await readErc20PeggedVariableCriteriaIncentiveGetPeg(this._config, {
537
+ address: this.assertValidAddress(),
538
+ args: [],
539
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
540
+ ...(params as any),
541
+ });
542
+ }
543
+
544
+ /**
545
+ * Get the maximum amount that can be claimed by this incentive. Useful when used in conjunction with `BoostCore.calculateProtocolFee`
546
+ *
547
+ * @public
548
+ * @async
549
+ * @param {?ReadParams} [params]
550
+ * @returns {Promise<bigint>} = Return a bigint representing that maximum amount that can be distributed by this incentive.
551
+ */
552
+ public async getTotalBudget(params?: ReadParams) {
553
+ return await this.limit(params);
554
+ }
555
+
556
+ /**
557
+ * Check if any claims remain by comparing the incentive's total claims against its limit. Does not take requesting user's elligibility into account.
558
+ *
559
+ * @public
560
+ * @async
561
+ * @param {?ReadParams} [params]
562
+ * @returns {Promise<boolean>} - True if total claims is less than limit
563
+ */
564
+ public async canBeClaimed(params?: ReadParams) {
565
+ return (await this.getRemainingClaimPotential(params)) > 0n;
566
+ }
567
+
568
+ /**
569
+ * Check how many claims remain by comparing the incentive's total claims against its limit. Does not take requesting user's elligibility into account.
570
+ *
571
+ * @public
572
+ * @async
573
+ * @param {?ReadParams} [params]
574
+ * @returns {Promise<bigint>} - True if total claims is less than limit
575
+ */
576
+ public async getRemainingClaimPotential(params?: ReadParams) {
577
+ const [totalClaimed, limit] = await Promise.all([
578
+ this.totalClaimed(params),
579
+ this.limit(params),
580
+ ]);
581
+ return limit - totalClaimed;
582
+ }
583
+
584
+ /**
585
+ *Functions from the ERC20VariableIncentive contract
586
+ */
587
+
588
+ /**
589
+ * Fetches the IncentiveCriteria struct from the contract
590
+ *
591
+ * @param {?ReadParams} [params]
592
+ * @returns {Promise<IncentiveCriteria>} Incentive criteria structure
593
+ * @throws {IncentiveCriteriaNotFoundError}
594
+ */
595
+ public async getIncentiveCriteria(
596
+ params?: ReadParams,
597
+ ): Promise<IncentiveCriteria> {
598
+ try {
599
+ const criteria =
600
+ await readErc20PeggedVariableCriteriaIncentiveGetIncentiveCriteria(
601
+ this._config,
602
+ {
603
+ ...params,
604
+ address: this.assertValidAddress(),
605
+ },
606
+ );
607
+
608
+ return criteria;
609
+ } catch (e) {
610
+ throw new IncentiveCriteriaNotFoundError(e as Error);
611
+ }
612
+ }
613
+
614
+ /**
615
+ * @inheritdoc
616
+ *
617
+ * @public
618
+ * @param {?ERC20PeggedVariableCriteriaIncentivePayload} [_payload]
619
+ * @param {?DeployableOptions} [_options]
620
+ * @returns {GenericDeployableParams}
621
+ */
622
+ public override buildParameters(
623
+ _payload?: ERC20PeggedVariableCriteriaIncentivePayload,
624
+ _options?: DeployableOptions,
625
+ ): GenericDeployableParams {
626
+ const [payload, options] = this.validateDeploymentConfig(
627
+ _payload,
628
+ _options,
629
+ );
630
+ return {
631
+ abi: erc20PeggedVariableCriteriaIncentiveAbi,
632
+ bytecode: bytecode as Hex,
633
+ args: [prepareERC20PeggedVariableCriteriaIncentivePayload(payload)],
634
+ ...this.optionallyAttachAccount(options.account),
635
+ };
636
+ }
637
+
638
+ /**
639
+ * Encodes an amount to clawback from the incentive
640
+ *
641
+ * @public
642
+ * @param {bigint} amount - How much of the asset to clawback
643
+ * @returns {Hex} - Returns an encoded uint256
644
+ */
645
+ public buildClawbackData(amount: bigint) {
646
+ return encodeAbiParameters([{ type: 'uint256' }], [amount]);
647
+ }
648
+
649
+ /**
650
+ * Builds the claim data for the ERC20PeggedVariableCriteriaIncentivePayload.
651
+ *
652
+ * @public
653
+ * @param {bigint} rewardAmount
654
+ * @returns {Hash} Returns the encoded claim data
655
+ * @description This function returns the encoded claim data for the ERC20PeggedVariableCriteriaIncentivePayload.
656
+ */
657
+ public buildClaimData(rewardAmount: bigint) {
658
+ return encodeAbiParameters(
659
+ [{ type: 'uint256', name: 'rewardAmount' }],
660
+ [rewardAmount],
661
+ );
662
+ }
663
+ }
664
+
665
+ /**
666
+ * Given a {@link ERC20PeggedVariableCriteriaIncentivePayload}, properly encode a `ERC20PeggedVariableCriteriaIncentivePayload.InitPayload` for use with {@link ERC20PeggedVariableCriteriaIncentivePayload} initialization.
667
+ *
668
+ * @param {ERC20PeggedVariableCriteriaIncentivePayload} param0
669
+ * @param {Address} param0.asset - The address of the incentivized asset.
670
+ * @param {Address} param0.peg - The peg to normalize to.
671
+ * @param {bigint} param0.reward - The amount of the asset to distribute.
672
+ * @param {bigint} param0.limit - How many times can this incentive be claimed.
673
+ * @param {Address} [param0.manager=zeroAddress] - The entity that can manage the incentive.
674
+ * @param {IncentiveCriteria} param0.criteria - The incentive criteria for reward distribution.
675
+ * @returns {Hex}
676
+ */
677
+ export function prepareERC20PeggedVariableCriteriaIncentivePayload({
678
+ asset,
679
+ peg,
680
+ reward,
681
+ limit,
682
+ maxReward = 0n,
683
+ manager = zeroAddress,
684
+ criteria,
685
+ }: ERC20PeggedVariableCriteriaIncentivePayload) {
686
+ return encodeAbiParameters(
687
+ [
688
+ {
689
+ type: 'tuple',
690
+ name: 'initPayloadExtended',
691
+ components: [
692
+ { type: 'address', name: 'asset' },
693
+ { type: 'address', name: 'peg' },
694
+ { type: 'uint256', name: 'reward' },
695
+ { type: 'uint256', name: 'limit' },
696
+ { type: 'address', name: 'manager' },
697
+ { type: 'uint256', name: 'maxReward' },
698
+ {
699
+ type: 'tuple',
700
+ name: 'criteria',
701
+ components: [
702
+ { type: 'uint8', name: 'criteriaType' },
703
+ { type: 'bytes32', name: 'signature' },
704
+ { type: 'uint8', name: 'fieldIndex' },
705
+ { type: 'address', name: 'targetContract' },
706
+ ],
707
+ },
708
+ ],
709
+ },
710
+ ],
711
+ [
712
+ {
713
+ asset,
714
+ peg,
715
+ reward,
716
+ limit,
717
+ manager,
718
+ maxReward,
719
+ criteria: {
720
+ criteriaType: criteria.criteriaType,
721
+ signature: criteria.signature,
722
+ fieldIndex: criteria.fieldIndex,
723
+ targetContract: criteria.targetContract,
724
+ },
725
+ },
726
+ ],
727
+ );
728
+ }