@boostxyz/sdk 7.0.0-canary.0 → 7.0.0-canary.2

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 (118) 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.js +56 -56
  5. package/dist/AllowLists/AllowList.cjs +1 -1
  6. package/dist/AllowLists/AllowList.js +5 -5
  7. package/dist/AllowLists/SimpleAllowList.cjs +1 -1
  8. package/dist/AllowLists/SimpleAllowList.js +17 -17
  9. package/dist/AllowLists/SimpleDenyList.cjs +1 -1
  10. package/dist/AllowLists/SimpleDenyList.js +3 -3
  11. package/dist/Auth/PassthroughAuth.cjs +1 -1
  12. package/dist/Auth/PassthroughAuth.js +1 -1
  13. package/dist/BoostCore.cjs +2 -2
  14. package/dist/BoostCore.js +141 -141
  15. package/dist/BoostRegistry.cjs +1 -1
  16. package/dist/BoostRegistry.js +11 -11
  17. package/dist/{Budget-Bvi5Qjqp.js → Budget-D2aQ8V__.js} +54 -54
  18. package/dist/{Budget-Bvi5Qjqp.js.map → Budget-D2aQ8V__.js.map} +1 -1
  19. package/dist/{Budget-B_kgJGDu.cjs → Budget-lcBEy-fx.cjs} +2 -2
  20. package/dist/{Budget-B_kgJGDu.cjs.map → Budget-lcBEy-fx.cjs.map} +1 -1
  21. package/dist/Budgets/Budget.cjs +1 -1
  22. package/dist/Budgets/Budget.js +3 -3
  23. package/dist/Budgets/ManagedBudget.cjs +1 -1
  24. package/dist/Budgets/ManagedBudget.js +29 -29
  25. package/dist/Deployable/DeployableTarget.cjs +1 -1
  26. package/dist/Deployable/DeployableTarget.js +1 -1
  27. package/dist/Deployable/DeployableTargetWithRBAC.cjs +1 -1
  28. package/dist/Deployable/DeployableTargetWithRBAC.js +16 -16
  29. package/dist/Incentive-DJZmgtA9.js +449 -0
  30. package/dist/{Incentive-CLKutfnD.js.map → Incentive-DJZmgtA9.js.map} +1 -1
  31. package/dist/{Incentive-CLSVNxDz.cjs → Incentive-DfVj0SE5.cjs} +2 -2
  32. package/dist/{Incentive-CLSVNxDz.cjs.map → Incentive-DfVj0SE5.cjs.map} +1 -1
  33. package/dist/Incentives/AllowListIncentive.cjs +1 -1
  34. package/dist/Incentives/AllowListIncentive.js +15 -15
  35. package/dist/Incentives/CGDAIncentive.cjs +1 -1
  36. package/dist/Incentives/CGDAIncentive.js +9 -9
  37. package/dist/Incentives/ERC20Incentive.cjs +1 -1
  38. package/dist/Incentives/ERC20Incentive.js +15 -15
  39. package/dist/Incentives/ERC20PeggedVariableCriteriaIncentive.cjs +2 -0
  40. package/dist/Incentives/ERC20PeggedVariableCriteriaIncentive.cjs.map +1 -0
  41. package/dist/Incentives/ERC20PeggedVariableCriteriaIncentive.d.ts +1093 -0
  42. package/dist/Incentives/ERC20PeggedVariableCriteriaIncentive.d.ts.map +1 -0
  43. package/dist/Incentives/ERC20PeggedVariableCriteriaIncentive.js +604 -0
  44. package/dist/Incentives/ERC20PeggedVariableCriteriaIncentive.js.map +1 -0
  45. package/dist/Incentives/ERC20PeggedVariableCriteriaIncentiveV2.cjs +1 -1
  46. package/dist/Incentives/ERC20PeggedVariableCriteriaIncentiveV2.cjs.map +1 -1
  47. package/dist/Incentives/ERC20PeggedVariableCriteriaIncentiveV2.d.ts +4 -4
  48. package/dist/Incentives/ERC20PeggedVariableCriteriaIncentiveV2.d.ts.map +1 -1
  49. package/dist/Incentives/ERC20PeggedVariableCriteriaIncentiveV2.js +33 -33
  50. package/dist/Incentives/ERC20PeggedVariableCriteriaIncentiveV2.js.map +1 -1
  51. package/dist/Incentives/ERC20VariableCriteriaIncentive.cjs +2 -0
  52. package/dist/Incentives/ERC20VariableCriteriaIncentive.cjs.map +1 -0
  53. package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts +884 -0
  54. package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts.map +1 -0
  55. package/dist/Incentives/ERC20VariableCriteriaIncentive.js +239 -0
  56. package/dist/Incentives/ERC20VariableCriteriaIncentive.js.map +1 -0
  57. package/dist/Incentives/ERC20VariableCriteriaIncentiveV2.cjs +1 -1
  58. package/dist/Incentives/ERC20VariableCriteriaIncentiveV2.cjs.map +1 -1
  59. package/dist/Incentives/ERC20VariableCriteriaIncentiveV2.d.ts +7 -7
  60. package/dist/Incentives/ERC20VariableCriteriaIncentiveV2.d.ts.map +1 -1
  61. package/dist/Incentives/ERC20VariableCriteriaIncentiveV2.js +11 -11
  62. package/dist/Incentives/ERC20VariableCriteriaIncentiveV2.js.map +1 -1
  63. package/dist/Incentives/ERC20VariableIncentive.cjs +1 -1
  64. package/dist/Incentives/ERC20VariableIncentive.js +12 -12
  65. package/dist/Incentives/Incentive.cjs +1 -1
  66. package/dist/Incentives/Incentive.d.ts +6 -4
  67. package/dist/Incentives/Incentive.d.ts.map +1 -1
  68. package/dist/Incentives/Incentive.js +23 -19
  69. package/dist/Incentives/Incentive.js.map +1 -1
  70. package/dist/Incentives/PointsIncentive.cjs +1 -1
  71. package/dist/Incentives/PointsIncentive.js +8 -8
  72. package/dist/{SimpleDenyList-C1C_BHkY.js → SimpleDenyList-C-T2RCgi.js} +14 -14
  73. package/dist/{SimpleDenyList-C1C_BHkY.js.map → SimpleDenyList-C-T2RCgi.js.map} +1 -1
  74. package/dist/{SimpleDenyList-CWthbyj7.cjs → SimpleDenyList-Dxle-6uU.cjs} +2 -2
  75. package/dist/{SimpleDenyList-CWthbyj7.cjs.map → SimpleDenyList-Dxle-6uU.cjs.map} +1 -1
  76. package/dist/Validators/LimitedSignerValidator.cjs +1 -1
  77. package/dist/Validators/LimitedSignerValidator.js +17 -17
  78. package/dist/Validators/SignerValidator.cjs +1 -1
  79. package/dist/Validators/SignerValidator.js +6 -6
  80. package/dist/Validators/Validator.cjs +1 -1
  81. package/dist/Validators/Validator.js +2 -2
  82. package/dist/componentInterfaces-C5ig8mCK.cjs +2 -0
  83. package/dist/componentInterfaces-C5ig8mCK.cjs.map +1 -0
  84. package/dist/componentInterfaces-Ddus5rIA.js +23 -0
  85. package/dist/componentInterfaces-Ddus5rIA.js.map +1 -0
  86. package/dist/{deployments-De8_J7SS.js → deployments-C-e2CGJJ.js} +47 -35
  87. package/dist/{deployments-De8_J7SS.js.map → deployments-C-e2CGJJ.js.map} +1 -1
  88. package/dist/deployments-YkNK95HE.cjs +2 -0
  89. package/dist/deployments-YkNK95HE.cjs.map +1 -0
  90. package/dist/deployments.json +12 -12
  91. package/dist/{generated-BJfQ-EBO.js → generated-CINzoGbl.js} +1890 -765
  92. package/dist/generated-CINzoGbl.js.map +1 -0
  93. package/dist/generated-C_JEoLDO.cjs +3 -0
  94. package/dist/generated-C_JEoLDO.cjs.map +1 -0
  95. package/dist/index.cjs +1 -1
  96. package/dist/index.d.ts +2 -0
  97. package/dist/index.d.ts.map +1 -1
  98. package/dist/index.js +150 -141
  99. package/dist/index.js.map +1 -1
  100. package/package.json +13 -1
  101. package/src/Incentives/ERC20PeggedVariableCriteriaIncentive.ts +852 -0
  102. package/src/Incentives/ERC20PeggedVariableCriteriaIncentiveV2.test.ts +6 -6
  103. package/src/Incentives/ERC20PeggedVariableCriteriaIncentiveV2.ts +5 -5
  104. package/src/Incentives/ERC20VariableCriteriaIncentive.ts +437 -0
  105. package/src/Incentives/ERC20VariableCriteriaIncentiveV2.test.ts +6 -6
  106. package/src/Incentives/ERC20VariableCriteriaIncentiveV2.ts +7 -7
  107. package/src/Incentives/Incentive.ts +11 -0
  108. package/src/index.ts +2 -0
  109. package/dist/Incentive-CLKutfnD.js +0 -445
  110. package/dist/componentInterfaces-BVHB4Fjw.js +0 -21
  111. package/dist/componentInterfaces-BVHB4Fjw.js.map +0 -1
  112. package/dist/componentInterfaces-BqhL-meV.cjs +0 -2
  113. package/dist/componentInterfaces-BqhL-meV.cjs.map +0 -1
  114. package/dist/deployments-D9QxJGrC.cjs +0 -2
  115. package/dist/deployments-D9QxJGrC.cjs.map +0 -1
  116. package/dist/generated-BJfQ-EBO.js.map +0 -1
  117. package/dist/generated-mJJNq-xb.cjs +0 -3
  118. package/dist/generated-mJJNq-xb.cjs.map +0 -1
@@ -0,0 +1,852 @@
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
+ decodeAbiParameters,
30
+ decodeFunctionData,
31
+ encodeAbiParameters,
32
+ parseEther,
33
+ parseEventLogs,
34
+ zeroAddress,
35
+ zeroHash,
36
+ } from 'viem';
37
+ import { ERC20PeggedVariableCriteriaIncentive as ERC20PeggedVariableCriteriaIncentiveBases } from '../../dist/deployments.json';
38
+ import { SignatureType } from '../Actions/EventAction';
39
+ import type {
40
+ DeployableOptions,
41
+ GenericDeployableParams,
42
+ } from '../Deployable/Deployable';
43
+ import { DeployableTarget } from '../Deployable/DeployableTarget';
44
+ import { type ClaimPayload, prepareClaimPayload } from '../claiming';
45
+ import {
46
+ DecodedArgsError,
47
+ IncentiveCriteriaNotFoundError,
48
+ InvalidCriteriaTypeError,
49
+ NoMatchingLogsError,
50
+ } from '../errors';
51
+ import {
52
+ CheatCodes,
53
+ type GenericLog,
54
+ type ReadParams,
55
+ RegistryType,
56
+ type WriteParams,
57
+ } from '../utils';
58
+ import type {
59
+ GetIncentiveScalarParams,
60
+ IncentiveCriteria,
61
+ } from './ERC20VariableCriteriaIncentive';
62
+
63
+ export { erc20PeggedVariableCriteriaIncentiveAbi };
64
+
65
+ /**
66
+ * The object representation of a `Erc20PeggedVariableCriteriaIncentive.InitPayload`
67
+ *
68
+ * @export
69
+ * @deprecated Please use only v2 implementations
70
+ * @interface Erc20PeggedVariableCriteriaIncentive
71
+ * @typedef {Erc20PeggedVariableCriteriaIncentive}
72
+ */
73
+ export interface ERC20PeggedVariableCriteriaIncentivePayload {
74
+ /**
75
+ * The address of the incentivized asset.
76
+ *
77
+ * @type {Address}
78
+ */
79
+ asset: Address;
80
+ /**
81
+ * The peg to normalize to.
82
+ *
83
+ * @type {Address}
84
+ */
85
+ peg: Address;
86
+ /**
87
+ * The amount of the asset to distribute.
88
+ *
89
+ * @type {bigint}
90
+ */
91
+ reward: bigint;
92
+ /**
93
+ * Total spend for the incentive.
94
+ *
95
+ * @type {bigint}
96
+ */
97
+ limit: bigint;
98
+ /**
99
+ * Maximum reward each claim is elligible for.
100
+ *
101
+ * @type {bigint}
102
+ */
103
+ maxReward: bigint;
104
+ /**
105
+ * (Optional) The address of the entity that can managed the incentive.
106
+ *
107
+ * @type {Address}
108
+ * @optional
109
+ */
110
+ manager?: Address;
111
+ /**
112
+ * The criteria for the incentive that determines how the reward is distributed.
113
+ *
114
+ * @type {IncentiveCriteria}
115
+ */
116
+ criteria: IncentiveCriteria;
117
+ }
118
+
119
+ /**
120
+ * A generic `viem.Log` event with support for `Erc20PeggedVariableCriteriaIncentive` event types.
121
+ *
122
+ * @export
123
+ * @typedef {Erc20PeggedVariableCriteriaIncentiveLog}
124
+ * @template {ContractEventName<typeof erc20PeggedVariableCriteriaIncentiveAbi>} [event=ContractEventName<
125
+ * typeof erc20PeggedVariableCriteriaIncentiveAbi
126
+ * >]
127
+ */
128
+ export type Erc20PeggedVariableCriteriaIncentiveLog<
129
+ event extends ContractEventName<
130
+ typeof erc20PeggedVariableCriteriaIncentiveAbi
131
+ > = ContractEventName<typeof erc20PeggedVariableCriteriaIncentiveAbi>,
132
+ > = GenericLog<typeof erc20PeggedVariableCriteriaIncentiveAbi, event>;
133
+
134
+ /**
135
+ * A simple ERC20 incentive implementation that allows claiming of tokens
136
+ *
137
+ * @export
138
+ * @deprecated Please use only v2 implementations
139
+ * @class Erc20PeggedVariableCriteriaIncentive
140
+ * @typedef {ERC20PeggedVariableCriteriaIncentive}
141
+ * @extends {DeployableTarget<ERC20PeggedVariableCriteriaIncentive>}
142
+ */
143
+ export class ERC20PeggedVariableCriteriaIncentive extends DeployableTarget<
144
+ ERC20PeggedVariableCriteriaIncentivePayload,
145
+ typeof erc20PeggedVariableCriteriaIncentiveAbi
146
+ > {
147
+ public override readonly abi = erc20PeggedVariableCriteriaIncentiveAbi;
148
+ /**
149
+ * @inheritdoc
150
+ *
151
+ * @public
152
+ * @static
153
+ * @type {Record<number, Address>}
154
+ */
155
+ public static override bases: Record<number, Address> = {
156
+ 31337: import.meta.env.VITE_ERC20_INCENTIVE_BASE,
157
+ ...(ERC20PeggedVariableCriteriaIncentiveBases as Record<number, Address>),
158
+ };
159
+ /**
160
+ * @inheritdoc
161
+ *
162
+ * @public
163
+ * @static
164
+ * @type {RegistryType}
165
+ */
166
+ public static override registryType: RegistryType = RegistryType.INCENTIVE;
167
+
168
+ /**
169
+ * The owner of the incentive
170
+ *
171
+ * @public
172
+ * @async
173
+ * @param {?ReadParams} [params]
174
+ * @returns {Promise<Address>}
175
+ */
176
+ public async owner(params?: ReadParams) {
177
+ return await readErc20PeggedVariableCriteriaIncentiveOwner(this._config, {
178
+ address: this.assertValidAddress(),
179
+ args: [],
180
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
181
+ ...(params as any),
182
+ });
183
+ }
184
+
185
+ /**
186
+ * 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)`
187
+ *
188
+ * @public
189
+ * @async
190
+ * @param {?ReadParams} [params]
191
+ * @returns {Promise<bigint>} - The current reward
192
+ */
193
+ public async currentReward(params?: ReadParams) {
194
+ return await readErc20PeggedVariableCriteriaIncentiveCurrentReward(
195
+ this._config,
196
+ {
197
+ address: this.assertValidAddress(),
198
+ args: [],
199
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
200
+ ...(params as any),
201
+ },
202
+ );
203
+ }
204
+
205
+ /**
206
+ * Retrieves the maximum reward amount per claim.
207
+ *
208
+ * @public
209
+ * @async
210
+ * @param {?ReadParams} [params]
211
+ * @returns {Promise<bigint>} The maximum reward amount per claim
212
+ */
213
+ public async getMaxReward(params?: ReadParams): Promise<bigint> {
214
+ const maxReward =
215
+ await readErc20PeggedVariableCriteriaIncentiveGetMaxReward(this._config, {
216
+ ...params,
217
+ address: this.assertValidAddress(),
218
+ });
219
+
220
+ return maxReward;
221
+ }
222
+
223
+ /**
224
+ * Fetches the incentive scalar from a transaction hash
225
+ *
226
+ * @param {GetIncentiveScalarParams} params
227
+ * @param {?ReadParams} [params]
228
+ * @returns {Promise<bigint>}
229
+ * @throws {InvalidCriteriaTypeError | NoMatchingLogsError | DecodedArgsError}
230
+ */
231
+ public async getIncentiveScalar(
232
+ { chainId, hash, knownSignatures }: GetIncentiveScalarParams,
233
+ params?: ReadParams,
234
+ ): Promise<bigint> {
235
+ const criteria = await this.getIncentiveCriteria(params);
236
+ if (criteria.criteriaType === SignatureType.EVENT) {
237
+ const transactionReceipt = await getTransactionReceipt(this._config, {
238
+ chainId,
239
+ hash,
240
+ });
241
+ if (criteria.fieldIndex === CheatCodes.GAS_REBATE_INCENTIVE) {
242
+ const totalCost =
243
+ transactionReceipt.gasUsed * transactionReceipt.effectiveGasPrice + // Normal gas cost
244
+ (transactionReceipt.blobGasUsed ?? 0n) *
245
+ (transactionReceipt.blobGasPrice ?? 0n); // Blob gas cost - account for potential undefined values
246
+ return totalCost;
247
+ }
248
+ const logs = transactionReceipt.logs;
249
+
250
+ if (logs.length === 0) {
251
+ throw new NoMatchingLogsError(
252
+ `No logs found for event signature ${criteria.signature}`,
253
+ );
254
+ }
255
+
256
+ // Decode the event log
257
+ try {
258
+ // Decode function data
259
+ const eventAbi = knownSignatures[criteria.signature] as AbiEvent;
260
+ const decodedEvents = parseEventLogs({
261
+ abi: [eventAbi],
262
+ logs,
263
+ });
264
+ if (decodedEvents == undefined || decodedEvents.length === 0) {
265
+ throw new NoMatchingLogsError(
266
+ `No logs found for event signature ${criteria.signature}`,
267
+ );
268
+ }
269
+ const scalarValue = (decodedEvents[0]?.args as string[])[
270
+ criteria.fieldIndex
271
+ ];
272
+
273
+ if (scalarValue === undefined) {
274
+ throw new DecodedArgsError(
275
+ `Decoded argument at index ${criteria.fieldIndex} is undefined`,
276
+ );
277
+ }
278
+ return BigInt(scalarValue);
279
+ } catch (e) {
280
+ throw new DecodedArgsError(
281
+ `Failed to decode event log for signature ${criteria.signature}: ${(e as Error).message}`,
282
+ );
283
+ }
284
+ } else if (criteria.criteriaType === SignatureType.FUNC) {
285
+ // Fetch the transaction data
286
+ const transaction = await getTransaction(this._config, {
287
+ chainId,
288
+ hash,
289
+ });
290
+ try {
291
+ // Decode function data
292
+ const func = knownSignatures[criteria.signature] as AbiFunction;
293
+ const decodedFunction = decodeFunctionData({
294
+ abi: [func],
295
+ data: transaction.input,
296
+ });
297
+ const scalarValue = decodedFunction.args[criteria.fieldIndex] as string;
298
+ if (scalarValue === undefined || scalarValue === null) {
299
+ throw new DecodedArgsError(
300
+ `Decoded argument at index ${criteria.fieldIndex} is undefined`,
301
+ );
302
+ }
303
+ return BigInt(scalarValue);
304
+ } catch (e) {
305
+ throw new DecodedArgsError(
306
+ `Failed to decode function data for signature ${criteria.signature}: ${(e as Error).message}`,
307
+ );
308
+ }
309
+ } else {
310
+ throw new InvalidCriteriaTypeError(
311
+ `Invalid criteria type ${criteria.criteriaType}`,
312
+ );
313
+ }
314
+ }
315
+
316
+ /**
317
+ * The number of claims that have been made
318
+ *
319
+ * @public
320
+ * @async
321
+ * @param {?ReadParams} [params]
322
+ * @returns {Promise<bigint>}
323
+ */
324
+ public async claims(params?: ReadParams) {
325
+ return await readErc20PeggedVariableCriteriaIncentiveClaims(this._config, {
326
+ address: this.assertValidAddress(),
327
+ args: [],
328
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
329
+ ...(params as any),
330
+ });
331
+ }
332
+
333
+ /**
334
+ * The total amount of rewards claimed
335
+ *
336
+ * @public
337
+ * @async
338
+ * @param {?ReadParams} [params]
339
+ * @returns {Promise<bigint>}
340
+ */
341
+ public async totalClaimed(params?: ReadParams) {
342
+ return await readErc20PeggedVariableCriteriaIncentiveTotalClaimed(
343
+ this._config,
344
+ {
345
+ address: this.assertValidAddress(),
346
+ args: [],
347
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
348
+ ...(params as any),
349
+ },
350
+ );
351
+ }
352
+
353
+ /**
354
+ * A mapping of address to claim status
355
+ *
356
+ * @public
357
+ * @async
358
+ * @param {Address} address
359
+ * @param {?ReadParams} [params]
360
+ * @returns {Promise<boolean>}
361
+ */
362
+ public async claimed(address: Address, params?: ReadParams) {
363
+ return await readErc20PeggedVariableCriteriaIncentiveClaimed(this._config, {
364
+ address: this.assertValidAddress(),
365
+ args: [address],
366
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
367
+ ...(params as any),
368
+ });
369
+ }
370
+
371
+ /**
372
+ * The address of the ERC20-like token
373
+ *
374
+ * @public
375
+ * @async
376
+ * @param {?ReadParams} [params]
377
+ * @returns {Promise<Address>}
378
+ */
379
+ public async asset(params?: ReadParams) {
380
+ return await readErc20PeggedVariableCriteriaIncentiveAsset(this._config, {
381
+ address: this.assertValidAddress(),
382
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
383
+ ...(params as any),
384
+ });
385
+ }
386
+
387
+ /**
388
+ * The address of the pegged ERC20-like token
389
+ *
390
+ * @public
391
+ * @async
392
+ * @param {?ReadParams} [params]
393
+ * @returns {Promise<Address>}
394
+ */
395
+ public async peg(params?: ReadParams) {
396
+ return await readErc20PeggedVariableCriteriaIncentivePeg(this._config, {
397
+ address: this.assertValidAddress(),
398
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
399
+ ...(params as any),
400
+ });
401
+ }
402
+
403
+ /**
404
+ * The reward amount issued for each claim
405
+ *
406
+ * @public
407
+ * @async
408
+ * @param {?ReadParams} [params]
409
+ * @returns {Promise<bigint>}
410
+ */
411
+ public async reward(params?: ReadParams) {
412
+ return await readErc20PeggedVariableCriteriaIncentiveReward(this._config, {
413
+ address: this.assertValidAddress(),
414
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
415
+ ...(params as any),
416
+ });
417
+ }
418
+
419
+ /**
420
+ * The limit (max possible rewards payout in reward token)
421
+ *
422
+ * @public
423
+ * @async
424
+ * @param {?ReadParams} [params]
425
+ * @returns {Promise<bigint>}
426
+ */
427
+ public async limit(params?: ReadParams) {
428
+ return await readErc20PeggedVariableCriteriaIncentiveLimit(this._config, {
429
+ address: this.assertValidAddress(),
430
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
431
+ ...(params as any),
432
+ });
433
+ }
434
+
435
+ /**
436
+ * Claim the incentive
437
+ *
438
+ * @public
439
+ * @async
440
+ * @param {ClaimPayload} payload
441
+ * @param {?WriteParams} [params]
442
+ * @returns {Promise<boolean>} - Returns true if successfully claimed
443
+ */
444
+ protected async claim(payload: ClaimPayload, params?: WriteParams) {
445
+ return await this.awaitResult(this.claimRaw(payload, params));
446
+ }
447
+
448
+ /**
449
+ * Claim the incentive
450
+ *
451
+ * @public
452
+ * @async
453
+ * @param {ClaimPayload} payload
454
+ * @param {?WriteParams} [params]
455
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - Returns true if successfully claimed
456
+ */
457
+ protected async claimRaw(payload: ClaimPayload, params?: WriteParams) {
458
+ const { request, result } =
459
+ await simulateErc20PeggedVariableCriteriaIncentiveClaim(this._config, {
460
+ address: this.assertValidAddress(),
461
+ args: [prepareClaimPayload(payload)],
462
+ ...this.optionallyAttachAccount(),
463
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
464
+ ...(params as any),
465
+ });
466
+ const hash = await writeErc20PeggedVariableCriteriaIncentiveClaim(
467
+ this._config,
468
+ request,
469
+ );
470
+ return { hash, result };
471
+ }
472
+
473
+ /**
474
+ * Clawback assets from the incentive
475
+ *
476
+ * @public
477
+ * @async
478
+ * @param {ClaimPayload} payload
479
+ * @param {?WriteParams} [params]
480
+ * @returns {Promise<boolean>} - True if the assets were successfully clawbacked
481
+ */
482
+ public async clawback(payload: ClaimPayload, params?: WriteParams) {
483
+ return await this.awaitResult(this.clawbackRaw(payload, params));
484
+ }
485
+
486
+ /**
487
+ * Clawback assets from the incentive
488
+ *
489
+ * @public
490
+ * @async
491
+ * @param {ClaimPayload} payload
492
+ * @param {?WriteParams} [params]
493
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if the assets were successfully clawbacked
494
+ */
495
+ public async clawbackRaw(payload: ClaimPayload, params?: WriteParams) {
496
+ const { request, result } =
497
+ await simulateErc20PeggedVariableCriteriaIncentiveClawback(this._config, {
498
+ address: this.assertValidAddress(),
499
+ args: [prepareClaimPayload(payload)],
500
+ ...this.optionallyAttachAccount(),
501
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
502
+ ...(params as any),
503
+ });
504
+ const hash = await writeErc20PeggedVariableCriteriaIncentiveClawback(
505
+ this._config,
506
+ request,
507
+ );
508
+ return { hash, result };
509
+ }
510
+
511
+ /**
512
+ * Check if an incentive is claimable.
513
+ *
514
+ * @public
515
+ * @async
516
+ * @param {ClaimPayload} payload
517
+ * @param {?ReadParams} [params]
518
+ * @returns {Promise<boolean>} = True if the incentive is claimable based on the data payload
519
+ */
520
+ public async isClaimable(payload: ClaimPayload, params?: ReadParams) {
521
+ return await readErc20PeggedVariableCriteriaIncentiveIsClaimable(
522
+ this._config,
523
+ {
524
+ address: this.assertValidAddress(),
525
+ args: [payload.target, payload.data],
526
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
527
+ ...(params as any),
528
+ },
529
+ );
530
+ }
531
+
532
+ /**
533
+ * read the peg token for the incentive.
534
+ *
535
+ * @public
536
+ * @async
537
+ * @param {?ReadParams} [params]
538
+ * @returns {Promise<Address>} = The address of the token the reward is pegged to
539
+ */
540
+ public async getPeg(params?: ReadParams) {
541
+ return await readErc20PeggedVariableCriteriaIncentiveGetPeg(this._config, {
542
+ address: this.assertValidAddress(),
543
+ args: [],
544
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
545
+ ...(params as any),
546
+ });
547
+ }
548
+
549
+ /**
550
+ * Get the maximum amount that can be claimed by this incentive. Useful when used in conjunction with `BoostCore.calculateProtocolFee`
551
+ *
552
+ * @public
553
+ * @async
554
+ * @param {?ReadParams} [params]
555
+ * @returns {Promise<bigint>} = Return a bigint representing that maximum amount that can be distributed by this incentive.
556
+ */
557
+ public async getTotalBudget(params?: ReadParams) {
558
+ return await this.limit(params);
559
+ }
560
+
561
+ /**
562
+ * Check if any claims remain by comparing the incentive's total claims against its limit. Does not take requesting user's elligibility into account.
563
+ *
564
+ * @public
565
+ * @async
566
+ * @param {?ReadParams} [params]
567
+ * @returns {Promise<boolean>} - True if total claims is less than limit
568
+ */
569
+ public async canBeClaimed(params?: ReadParams) {
570
+ return (await this.getRemainingClaimPotential(params)) > 0n;
571
+ }
572
+
573
+ /**
574
+ * Check how many claims remain by comparing the incentive's total claims against its limit. Does not take requesting user's elligibility into account.
575
+ *
576
+ * @public
577
+ * @async
578
+ * @param {?ReadParams} [params]
579
+ * @returns {Promise<bigint>} - True if total claims is less than limit
580
+ */
581
+ public async getRemainingClaimPotential(params?: ReadParams) {
582
+ const [totalClaimed, limit] = await Promise.all([
583
+ this.totalClaimed(params),
584
+ this.limit(params),
585
+ ]);
586
+ return limit - totalClaimed;
587
+ }
588
+
589
+ /**
590
+ *Functions from the ERC20VariableIncentive contract
591
+ */
592
+
593
+ /**
594
+ * Fetches the IncentiveCriteria struct from the contract
595
+ *
596
+ * @param {?ReadParams} [params]
597
+ * @returns {Promise<IncentiveCriteria>} Incentive criteria structure
598
+ * @throws {IncentiveCriteriaNotFoundError}
599
+ */
600
+ public async getIncentiveCriteria(
601
+ params?: ReadParams,
602
+ ): Promise<IncentiveCriteria> {
603
+ try {
604
+ const criteria =
605
+ await readErc20PeggedVariableCriteriaIncentiveGetIncentiveCriteria(
606
+ this._config,
607
+ {
608
+ ...params,
609
+ address: this.assertValidAddress(),
610
+ },
611
+ );
612
+
613
+ return criteria;
614
+ } catch (e) {
615
+ throw new IncentiveCriteriaNotFoundError(e as Error);
616
+ }
617
+ }
618
+
619
+ /**
620
+ * Generates a top-up payload for the ERC20PeggedIncentive contract by incrementing
621
+ * the existing `limit` field by `netAmount`. The entire payload is then re-encoded
622
+ * via `prepareERC20PeggedIncentivePayload(...)`.
623
+ *
624
+ * @public
625
+ * @param {bigint} netAmount - The additional limit to add to this incentive.
626
+ * @returns {Hex} The ABI-encoded payload with the updated `limit`.
627
+ */
628
+ public async getTopupPayload(netAmount: bigint): Promise<Hex> {
629
+ return prepareERC20PeggedVariableCriteriaIncentivePayload({
630
+ asset: (await this.asset()) ?? zeroAddress,
631
+ peg: this.payload?.peg ?? zeroAddress,
632
+ reward: this.payload?.reward ?? 0n,
633
+ limit: netAmount,
634
+ maxReward: this.payload?.maxReward ?? 0n,
635
+ manager: this.payload?.manager ?? zeroAddress,
636
+ criteria: this.payload?.criteria ?? {
637
+ criteriaType: 0,
638
+ signature: zeroHash,
639
+ fieldIndex: 0,
640
+ targetContract: zeroAddress,
641
+ },
642
+ });
643
+ }
644
+
645
+ /**
646
+ * @inheritdoc
647
+ *
648
+ * @public
649
+ * @param {?ERC20PeggedVariableCriteriaIncentivePayload} [_payload]
650
+ * @param {?DeployableOptions} [_options]
651
+ * @returns {GenericDeployableParams}
652
+ */
653
+ public override buildParameters(
654
+ _payload?: ERC20PeggedVariableCriteriaIncentivePayload,
655
+ _options?: DeployableOptions,
656
+ ): GenericDeployableParams {
657
+ const [payload, options] = this.validateDeploymentConfig(
658
+ _payload,
659
+ _options,
660
+ );
661
+ return {
662
+ abi: erc20PeggedVariableCriteriaIncentiveAbi,
663
+ bytecode: bytecode as Hex,
664
+ args: [prepareERC20PeggedVariableCriteriaIncentivePayload(payload)],
665
+ ...this.optionallyAttachAccount(options.account),
666
+ };
667
+ }
668
+
669
+ /**
670
+ * Encodes an amount to clawback from the incentive
671
+ *
672
+ * @public
673
+ * @param {bigint} amount - How much of the asset to clawback
674
+ * @returns {Hex} - Returns an encoded uint256
675
+ */
676
+ public buildClawbackData(amount: bigint) {
677
+ return encodeAbiParameters([{ type: 'uint256' }], [amount]);
678
+ }
679
+
680
+ /**
681
+ * Builds the claim data for the ERC20PeggedVariableCriteriaIncentivePayload.
682
+ *
683
+ * @public
684
+ * @param {bigint} signedAmount
685
+ * @returns {Hash} Returns the encoded claim data
686
+ * @description This function returns the encoded claim data for the ERC20PeggedVariableCriteriaIncentivePayload.
687
+ */
688
+ public buildClaimData(signedAmount: bigint) {
689
+ return encodeAbiParameters(
690
+ [{ type: 'uint256', name: 'signedAmount' }],
691
+ [signedAmount],
692
+ );
693
+ }
694
+
695
+ /**
696
+ * Decodes claim data for the ERC20PeggedVariableCriteriaIncentive, returning the claim amount.
697
+ * Useful when deriving amount claimed from logs.
698
+ *
699
+ * @public
700
+ * @param {Hex} claimData
701
+ * @returns {Promise<bigint>} Returns the reward amount from a claim data payload
702
+ */
703
+ public async decodeClaimData(claimData: Hex) {
704
+ const boostClaimData = decodeAbiParameters(
705
+ [
706
+ {
707
+ type: 'tuple',
708
+ name: 'BoostClaimData',
709
+ components: [
710
+ { type: 'bytes', name: 'validatorData' },
711
+ { type: 'bytes', name: 'incentiveData' },
712
+ ],
713
+ },
714
+ ],
715
+ claimData,
716
+ );
717
+ const signedAmount = decodeAbiParameters(
718
+ [{ type: 'uint256' }],
719
+ boostClaimData[0].incentiveData,
720
+ )[0];
721
+ let claimAmount = signedAmount;
722
+ const [reward, maxReward] = await Promise.all([
723
+ this.reward(),
724
+ this.getMaxReward(),
725
+ ]);
726
+
727
+ if (reward === 0n) {
728
+ return claimAmount;
729
+ } else {
730
+ claimAmount = (reward * signedAmount) / parseEther('1');
731
+ }
732
+
733
+ if (maxReward !== 0n && claimAmount > maxReward) {
734
+ claimAmount = maxReward;
735
+ }
736
+
737
+ return claimAmount;
738
+ }
739
+
740
+ /**
741
+ * Decodes claim data for the ERC20PeggedVariableCriteriaIncentive, returning the claim amount.
742
+ * Useful when deriving amount claimed from logs.
743
+ * Use this function instead of `decodeClaimData` if you have reward details.
744
+ *
745
+ * @public
746
+ * @param {Hex} claimData
747
+ * @param {bigint} [reward]
748
+ * @param {bigint} [maxReward]
749
+ * @returns {BigInt} Returns the reward amount from a claim data payload
750
+ */
751
+ public decodeClaimDataWithRewardDetails(
752
+ claimData: Hex,
753
+ reward: bigint,
754
+ maxReward: bigint,
755
+ ) {
756
+ const boostClaimData = decodeAbiParameters(
757
+ [
758
+ {
759
+ type: 'tuple',
760
+ name: 'BoostClaimData',
761
+ components: [
762
+ { type: 'bytes', name: 'validatorData' },
763
+ { type: 'bytes', name: 'incentiveData' },
764
+ ],
765
+ },
766
+ ],
767
+ claimData,
768
+ );
769
+ const signedAmount = decodeAbiParameters(
770
+ [{ type: 'uint256' }],
771
+ boostClaimData[0].incentiveData,
772
+ )[0];
773
+ let claimAmount = signedAmount;
774
+
775
+ if (reward === 0n) {
776
+ return claimAmount;
777
+ } else {
778
+ claimAmount = (reward * signedAmount) / parseEther('1');
779
+ }
780
+
781
+ if (maxReward !== 0n && claimAmount > maxReward) {
782
+ claimAmount = maxReward;
783
+ }
784
+
785
+ return claimAmount;
786
+ }
787
+ }
788
+
789
+ /**
790
+ * Given a {@link ERC20PeggedVariableCriteriaIncentivePayload}, properly encode a `ERC20PeggedVariableCriteriaIncentivePayload.InitPayload` for use with {@link ERC20PeggedVariableCriteriaIncentivePayload} initialization.
791
+ *
792
+ * @param {ERC20PeggedVariableCriteriaIncentivePayload} param0
793
+ * @param {Address} param0.asset - The address of the incentivized asset.
794
+ * @param {Address} param0.peg - The peg to normalize to.
795
+ * @param {bigint} param0.reward - The amount of the asset to distribute.
796
+ * @param {bigint} param0.limit - How many times can this incentive be claimed.
797
+ * @param {Address} [param0.manager=zeroAddress] - The entity that can manage the incentive.
798
+ * @param {IncentiveCriteria} param0.criteria - The incentive criteria for reward distribution.
799
+ * @returns {Hex}
800
+ */
801
+ export function prepareERC20PeggedVariableCriteriaIncentivePayload({
802
+ asset,
803
+ peg,
804
+ reward,
805
+ limit,
806
+ maxReward = 0n,
807
+ manager = zeroAddress,
808
+ criteria,
809
+ }: ERC20PeggedVariableCriteriaIncentivePayload) {
810
+ return encodeAbiParameters(
811
+ [
812
+ {
813
+ type: 'tuple',
814
+ name: 'initPayloadExtended',
815
+ components: [
816
+ { type: 'address', name: 'asset' },
817
+ { type: 'address', name: 'peg' },
818
+ { type: 'uint256', name: 'reward' },
819
+ { type: 'uint256', name: 'limit' },
820
+ { type: 'address', name: 'manager' },
821
+ { type: 'uint256', name: 'maxReward' },
822
+ {
823
+ type: 'tuple',
824
+ name: 'criteria',
825
+ components: [
826
+ { type: 'uint8', name: 'criteriaType' },
827
+ { type: 'bytes32', name: 'signature' },
828
+ { type: 'uint8', name: 'fieldIndex' },
829
+ { type: 'address', name: 'targetContract' },
830
+ ],
831
+ },
832
+ ],
833
+ },
834
+ ],
835
+ [
836
+ {
837
+ asset,
838
+ peg,
839
+ reward,
840
+ limit,
841
+ manager,
842
+ maxReward,
843
+ criteria: {
844
+ criteriaType: criteria.criteriaType,
845
+ signature: criteria.signature,
846
+ fieldIndex: criteria.fieldIndex,
847
+ targetContract: criteria.targetContract,
848
+ },
849
+ },
850
+ ],
851
+ );
852
+ }