@boostxyz/sdk 6.1.3 → 7.0.0-canary.1

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