@boostxyz/sdk 0.0.0-alpha.2 → 0.0.0-alpha.20

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 (271) hide show
  1. package/dist/Actions/Action.cjs +2 -1
  2. package/dist/Actions/Action.cjs.map +1 -0
  3. package/dist/Actions/Action.d.ts +1 -1
  4. package/dist/Actions/Action.d.ts.map +1 -1
  5. package/dist/Actions/Action.js +14 -12
  6. package/dist/Actions/Action.js.map +1 -0
  7. package/dist/Actions/ContractAction.d.ts +57 -14
  8. package/dist/Actions/ContractAction.d.ts.map +1 -1
  9. package/dist/Actions/ERC721MintAction.d.ts +50 -23
  10. package/dist/Actions/ERC721MintAction.d.ts.map +1 -1
  11. package/dist/Actions/EventAction.cjs +2 -1
  12. package/dist/Actions/EventAction.cjs.map +1 -0
  13. package/dist/Actions/EventAction.d.ts +405 -36
  14. package/dist/Actions/EventAction.d.ts.map +1 -1
  15. package/dist/Actions/EventAction.js +15 -209
  16. package/dist/Actions/EventAction.js.map +1 -0
  17. package/dist/AllowLists/AllowList.cjs +2 -1
  18. package/dist/AllowLists/AllowList.cjs.map +1 -0
  19. package/dist/AllowLists/AllowList.d.ts +6 -5
  20. package/dist/AllowLists/AllowList.d.ts.map +1 -1
  21. package/dist/AllowLists/AllowList.js +46 -22
  22. package/dist/AllowLists/AllowList.js.map +1 -0
  23. package/dist/AllowLists/OpenAllowList.d.ts +423 -0
  24. package/dist/AllowLists/OpenAllowList.d.ts.map +1 -0
  25. package/dist/AllowLists/SimpleAllowList.cjs +2 -1
  26. package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
  27. package/dist/AllowLists/SimpleAllowList.d.ts +124 -40
  28. package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -1
  29. package/dist/AllowLists/SimpleAllowList.js +77 -77
  30. package/dist/AllowLists/SimpleAllowList.js.map +1 -0
  31. package/dist/AllowLists/SimpleDenyList.cjs +2 -1
  32. package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
  33. package/dist/AllowLists/SimpleDenyList.d.ts +234 -13
  34. package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -1
  35. package/dist/AllowLists/SimpleDenyList.js +12 -200
  36. package/dist/AllowLists/SimpleDenyList.js.map +1 -0
  37. package/dist/Auth/Auth.cjs +1 -0
  38. package/dist/Auth/Auth.cjs.map +1 -0
  39. package/dist/Auth/Auth.js +1 -0
  40. package/dist/Auth/Auth.js.map +1 -0
  41. package/dist/Auth/PassthroughAuth.cjs +2 -1
  42. package/dist/Auth/PassthroughAuth.cjs.map +1 -0
  43. package/dist/Auth/PassthroughAuth.js +5 -4
  44. package/dist/Auth/PassthroughAuth.js.map +1 -0
  45. package/dist/Boost.cjs +2 -1
  46. package/dist/Boost.cjs.map +1 -0
  47. package/dist/Boost.d.ts +111 -1
  48. package/dist/Boost.d.ts.map +1 -1
  49. package/dist/Boost.js +140 -5
  50. package/dist/Boost.js.map +1 -0
  51. package/dist/BoostCore-3-U1xTQN.cjs +3 -0
  52. package/dist/BoostCore-3-U1xTQN.cjs.map +1 -0
  53. package/dist/BoostCore-DVGBUr2y.js +1477 -0
  54. package/dist/BoostCore-DVGBUr2y.js.map +1 -0
  55. package/dist/BoostCore.cjs +2 -2
  56. package/dist/BoostCore.cjs.map +1 -0
  57. package/dist/BoostCore.d.ts +166 -43
  58. package/dist/BoostCore.d.ts.map +1 -1
  59. package/dist/BoostCore.js +30 -1103
  60. package/dist/BoostCore.js.map +1 -0
  61. package/dist/BoostRegistry.cjs +2 -1
  62. package/dist/BoostRegistry.cjs.map +1 -0
  63. package/dist/BoostRegistry.d.ts +64 -23
  64. package/dist/BoostRegistry.d.ts.map +1 -1
  65. package/dist/BoostRegistry.js +162 -88
  66. package/dist/BoostRegistry.js.map +1 -0
  67. package/dist/Budgets/Budget.cjs +2 -1
  68. package/dist/Budgets/Budget.cjs.map +1 -0
  69. package/dist/Budgets/Budget.d.ts +1 -1
  70. package/dist/Budgets/Budget.d.ts.map +1 -1
  71. package/dist/Budgets/Budget.js +15 -13
  72. package/dist/Budgets/Budget.js.map +1 -0
  73. package/dist/Budgets/ManagedBudget.cjs +2 -1
  74. package/dist/Budgets/ManagedBudget.cjs.map +1 -0
  75. package/dist/Budgets/ManagedBudget.d.ts +78 -188
  76. package/dist/Budgets/ManagedBudget.d.ts.map +1 -1
  77. package/dist/Budgets/ManagedBudget.js +86 -286
  78. package/dist/Budgets/ManagedBudget.js.map +1 -0
  79. package/dist/Budgets/VestingBudget.d.ts +243 -87
  80. package/dist/Budgets/VestingBudget.d.ts.map +1 -1
  81. package/dist/Deployable/Contract.cjs +2 -1
  82. package/dist/Deployable/Contract.cjs.map +1 -0
  83. package/dist/Deployable/Contract.d.ts +4 -5
  84. package/dist/Deployable/Contract.d.ts.map +1 -1
  85. package/dist/Deployable/Contract.js +7 -8
  86. package/dist/Deployable/Contract.js.map +1 -0
  87. package/dist/Deployable/Deployable.cjs +1 -0
  88. package/dist/Deployable/Deployable.cjs.map +1 -0
  89. package/dist/Deployable/Deployable.d.ts +9 -3
  90. package/dist/Deployable/Deployable.d.ts.map +1 -1
  91. package/dist/Deployable/Deployable.js +10 -5
  92. package/dist/Deployable/Deployable.js.map +1 -0
  93. package/dist/Deployable/DeployableTarget.cjs +2 -1
  94. package/dist/Deployable/DeployableTarget.cjs.map +1 -0
  95. package/dist/Deployable/DeployableTarget.d.ts +16 -15
  96. package/dist/Deployable/DeployableTarget.d.ts.map +1 -1
  97. package/dist/Deployable/DeployableTarget.js +49 -42
  98. package/dist/Deployable/DeployableTarget.js.map +1 -0
  99. package/dist/Deployable/DeployableTargetWithRBAC.cjs +2 -0
  100. package/dist/Deployable/DeployableTargetWithRBAC.cjs.map +1 -0
  101. package/dist/Deployable/DeployableTargetWithRBAC.d.ts +179 -0
  102. package/dist/Deployable/DeployableTargetWithRBAC.d.ts.map +1 -0
  103. package/dist/Deployable/DeployableTargetWithRBAC.js +222 -0
  104. package/dist/Deployable/DeployableTargetWithRBAC.js.map +1 -0
  105. package/dist/EventAction-CIPqmAoP.js +1450 -0
  106. package/dist/EventAction-CIPqmAoP.js.map +1 -0
  107. package/dist/EventAction-d-oeqZQs.cjs +2 -0
  108. package/dist/EventAction-d-oeqZQs.cjs.map +1 -0
  109. package/dist/Incentive-Bp8Sez7M.js +298 -0
  110. package/dist/Incentive-Bp8Sez7M.js.map +1 -0
  111. package/dist/Incentive-Djnzseoj.cjs +2 -0
  112. package/dist/Incentive-Djnzseoj.cjs.map +1 -0
  113. package/dist/Incentives/AllowListIncentive.cjs +2 -1
  114. package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
  115. package/dist/Incentives/AllowListIncentive.d.ts +49 -19
  116. package/dist/Incentives/AllowListIncentive.d.ts.map +1 -1
  117. package/dist/Incentives/AllowListIncentive.js +50 -34
  118. package/dist/Incentives/AllowListIncentive.js.map +1 -0
  119. package/dist/Incentives/CGDAIncentive.cjs +2 -1
  120. package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
  121. package/dist/Incentives/CGDAIncentive.d.ts +118 -22
  122. package/dist/Incentives/CGDAIncentive.d.ts.map +1 -1
  123. package/dist/Incentives/CGDAIncentive.js +67 -42
  124. package/dist/Incentives/CGDAIncentive.js.map +1 -0
  125. package/dist/Incentives/ERC1155Incentive.d.ts +99 -38
  126. package/dist/Incentives/ERC1155Incentive.d.ts.map +1 -1
  127. package/dist/Incentives/ERC20Incentive.cjs +2 -1
  128. package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
  129. package/dist/Incentives/ERC20Incentive.d.ts +73 -29
  130. package/dist/Incentives/ERC20Incentive.d.ts.map +1 -1
  131. package/dist/Incentives/ERC20Incentive.js +71 -48
  132. package/dist/Incentives/ERC20Incentive.js.map +1 -0
  133. package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts +523 -0
  134. package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts.map +1 -0
  135. package/dist/Incentives/ERC20VariableIncentive.d.ts +65 -28
  136. package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -1
  137. package/dist/Incentives/Incentive.cjs +2 -1
  138. package/dist/Incentives/Incentive.cjs.map +1 -0
  139. package/dist/Incentives/Incentive.d.ts +4 -7
  140. package/dist/Incentives/Incentive.d.ts.map +1 -1
  141. package/dist/Incentives/Incentive.js +17 -278
  142. package/dist/Incentives/Incentive.js.map +1 -0
  143. package/dist/Incentives/PointsIncentive.cjs +2 -1
  144. package/dist/Incentives/PointsIncentive.cjs.map +1 -0
  145. package/dist/Incentives/PointsIncentive.d.ts +65 -21
  146. package/dist/Incentives/PointsIncentive.d.ts.map +1 -1
  147. package/dist/Incentives/PointsIncentive.js +57 -36
  148. package/dist/Incentives/PointsIncentive.js.map +1 -0
  149. package/dist/SimpleDenyList-BwfNjRsg.cjs +2 -0
  150. package/dist/SimpleDenyList-BwfNjRsg.cjs.map +1 -0
  151. package/dist/SimpleDenyList-Cn5WpNn0.js +132 -0
  152. package/dist/SimpleDenyList-Cn5WpNn0.js.map +1 -0
  153. package/dist/Validators/SignerValidator.cjs +2 -1
  154. package/dist/Validators/SignerValidator.cjs.map +1 -0
  155. package/dist/Validators/SignerValidator.d.ts +310 -17
  156. package/dist/Validators/SignerValidator.d.ts.map +1 -1
  157. package/dist/Validators/SignerValidator.js +165 -36
  158. package/dist/Validators/SignerValidator.js.map +1 -0
  159. package/dist/Validators/Validator.cjs +2 -1
  160. package/dist/Validators/Validator.cjs.map +1 -0
  161. package/dist/Validators/Validator.d.ts +2 -2
  162. package/dist/Validators/Validator.d.ts.map +1 -1
  163. package/dist/Validators/Validator.js +12 -10
  164. package/dist/Validators/Validator.js.map +1 -0
  165. package/dist/claiming.cjs +2 -0
  166. package/dist/claiming.cjs.map +1 -0
  167. package/dist/claiming.d.ts +43 -0
  168. package/dist/claiming.d.ts.map +1 -0
  169. package/dist/claiming.js +17 -0
  170. package/dist/claiming.js.map +1 -0
  171. package/dist/componentInterfaces-D09mhzxO.cjs +2 -0
  172. package/dist/componentInterfaces-D09mhzxO.cjs.map +1 -0
  173. package/dist/componentInterfaces-RXBMI5yH.js +14 -0
  174. package/dist/componentInterfaces-RXBMI5yH.js.map +1 -0
  175. package/dist/deployments-BM42vImE.js +43 -0
  176. package/dist/deployments-BM42vImE.js.map +1 -0
  177. package/dist/deployments-CMdF5uEC.cjs +2 -0
  178. package/dist/deployments-CMdF5uEC.cjs.map +1 -0
  179. package/dist/deployments.json +41 -0
  180. package/dist/errors.cjs +2 -1
  181. package/dist/errors.cjs.map +1 -0
  182. package/dist/errors.d.ts +403 -1
  183. package/dist/errors.d.ts.map +1 -1
  184. package/dist/errors.js +285 -39
  185. package/dist/errors.js.map +1 -0
  186. package/dist/generated-B0tk-c9b.cjs +3 -0
  187. package/dist/generated-B0tk-c9b.cjs.map +1 -0
  188. package/dist/{generated-x_abr3Yv.js → generated-B7VaSah4.js} +2058 -2541
  189. package/dist/generated-B7VaSah4.js.map +1 -0
  190. package/dist/index.cjs +2 -1
  191. package/dist/index.cjs.map +1 -0
  192. package/dist/index.d.ts +10 -9
  193. package/dist/index.d.ts.map +1 -1
  194. package/dist/index.js +143 -1353
  195. package/dist/index.js.map +1 -0
  196. package/dist/transfers.cjs +2 -0
  197. package/dist/transfers.cjs.map +1 -0
  198. package/dist/transfers.d.ts +198 -0
  199. package/dist/transfers.d.ts.map +1 -0
  200. package/dist/transfers.js +84 -0
  201. package/dist/transfers.js.map +1 -0
  202. package/dist/utils.cjs +2 -1
  203. package/dist/utils.cjs.map +1 -0
  204. package/dist/utils.d.ts +26 -1350
  205. package/dist/utils.d.ts.map +1 -1
  206. package/dist/utils.js +38 -636
  207. package/dist/utils.js.map +1 -0
  208. package/package.json +37 -11
  209. package/src/Actions/Action.test.ts +79 -0
  210. package/src/Actions/Action.ts +61 -0
  211. package/src/Actions/ContractAction.test.ts +197 -0
  212. package/src/Actions/ContractAction.ts +300 -0
  213. package/src/Actions/ERC721MintAction.test.ts +112 -0
  214. package/src/Actions/ERC721MintAction.ts +291 -0
  215. package/src/Actions/EventAction.test.ts +787 -0
  216. package/src/Actions/EventAction.ts +1214 -0
  217. package/src/AllowLists/AllowList.test.ts +64 -0
  218. package/src/AllowLists/AllowList.ts +62 -0
  219. package/src/AllowLists/OpenAllowList.test.ts +40 -0
  220. package/src/AllowLists/OpenAllowList.ts +45 -0
  221. package/src/AllowLists/SimpleAllowList.test.ts +52 -0
  222. package/src/AllowLists/SimpleAllowList.ts +262 -0
  223. package/src/AllowLists/SimpleDenyList.test.ts +52 -0
  224. package/src/AllowLists/SimpleDenyList.ts +250 -0
  225. package/src/Auth/Auth.ts +11 -0
  226. package/src/Auth/PassthroughAuth.test.ts +12 -0
  227. package/src/Auth/PassthroughAuth.ts +80 -0
  228. package/src/Boost.ts +309 -0
  229. package/src/BoostCore.test.ts +827 -0
  230. package/src/BoostCore.ts +1447 -0
  231. package/src/BoostRegistry.ts +543 -0
  232. package/src/Budgets/Budget.test.ts +27 -0
  233. package/src/Budgets/Budget.ts +60 -0
  234. package/src/Budgets/ManagedBudget.test.ts +217 -0
  235. package/src/Budgets/ManagedBudget.ts +534 -0
  236. package/src/Budgets/VestingBudget.test.ts +123 -0
  237. package/src/Budgets/VestingBudget.ts +530 -0
  238. package/src/Deployable/Contract.ts +228 -0
  239. package/src/Deployable/Deployable.ts +250 -0
  240. package/src/Deployable/DeployableTarget.ts +234 -0
  241. package/src/Deployable/DeployableTargetWithRBAC.ts +323 -0
  242. package/src/Incentives/AllowListIncentive.test.ts +143 -0
  243. package/src/Incentives/AllowListIncentive.ts +336 -0
  244. package/src/Incentives/CGDAIncentive.test.ts +132 -0
  245. package/src/Incentives/CGDAIncentive.ts +470 -0
  246. package/src/Incentives/ERC1155Incentive.test.ts +87 -0
  247. package/src/Incentives/ERC1155Incentive.ts +465 -0
  248. package/src/Incentives/ERC20Incentive.test.ts +130 -0
  249. package/src/Incentives/ERC20Incentive.ts +484 -0
  250. package/src/Incentives/ERC20VariableCriteriaIncentive.test.ts +184 -0
  251. package/src/Incentives/ERC20VariableCriteriaIncentive.ts +309 -0
  252. package/src/Incentives/ERC20VariableIncentive.test.ts +136 -0
  253. package/src/Incentives/ERC20VariableIncentive.ts +422 -0
  254. package/src/Incentives/Incentive.test.ts +92 -0
  255. package/src/Incentives/Incentive.ts +86 -0
  256. package/src/Incentives/PointsIncentive.test.ts +139 -0
  257. package/src/Incentives/PointsIncentive.ts +367 -0
  258. package/src/Validators/SignerValidator.test.ts +159 -0
  259. package/src/Validators/SignerValidator.ts +683 -0
  260. package/src/Validators/Validator.test.ts +21 -0
  261. package/src/Validators/Validator.ts +55 -0
  262. package/src/claiming.ts +56 -0
  263. package/src/errors.ts +844 -0
  264. package/src/index.test.ts +122 -0
  265. package/src/index.ts +58 -0
  266. package/src/transfers.ts +284 -0
  267. package/src/utils.test.ts +44 -0
  268. package/src/utils.ts +247 -0
  269. package/dist/Budgets/SimpleBudget.d.ts +0 -793
  270. package/dist/Budgets/SimpleBudget.d.ts.map +0 -1
  271. package/dist/generated-BaaleHW-.cjs +0 -2
@@ -0,0 +1,484 @@
1
+ import {
2
+ erc20IncentiveAbi,
3
+ readErc20IncentiveAsset,
4
+ readErc20IncentiveClaimed,
5
+ readErc20IncentiveClaims,
6
+ readErc20IncentiveCurrentReward,
7
+ readErc20IncentiveEntries,
8
+ readErc20IncentiveIsClaimable,
9
+ readErc20IncentiveLimit,
10
+ readErc20IncentiveOwner,
11
+ readErc20IncentiveReward,
12
+ readErc20IncentiveStrategy,
13
+ simulateErc20IncentiveClaim,
14
+ simulateErc20IncentiveClawback,
15
+ simulateErc20IncentiveDrawRaffle,
16
+ writeErc20IncentiveClaim,
17
+ writeErc20IncentiveClawback,
18
+ writeErc20IncentiveDrawRaffle,
19
+ } from '@boostxyz/evm';
20
+ import { bytecode } from '@boostxyz/evm/artifacts/contracts/incentives/ERC20Incentive.sol/ERC20Incentive.json';
21
+ import {
22
+ type Address,
23
+ type ContractEventName,
24
+ type Hex,
25
+ encodeAbiParameters,
26
+ } from 'viem';
27
+ import { ERC20Incentive as ERC20IncentiveBases } from '../../dist/deployments.json';
28
+ import type {
29
+ DeployableOptions,
30
+ GenericDeployableParams,
31
+ } from '../Deployable/Deployable';
32
+ import { DeployableTarget } from '../Deployable/DeployableTarget';
33
+ import {
34
+ type ClaimPayload,
35
+ type StrategyType,
36
+ prepareClaimPayload,
37
+ } from '../claiming';
38
+ import {
39
+ type GenericLog,
40
+ type ReadParams,
41
+ RegistryType,
42
+ type WriteParams,
43
+ } from '../utils';
44
+
45
+ export { erc20IncentiveAbi };
46
+
47
+ /**
48
+ * The object representation of a `ERC20Incentive.InitPayload`
49
+ *
50
+ * @export
51
+ * @interface ERC20IncentivePayload
52
+ * @typedef {ERC20IncentivePayload}
53
+ */
54
+ export interface ERC20IncentivePayload {
55
+ /**
56
+ * The address of the incentivized asset.
57
+ *
58
+ * @type {Address}
59
+ */
60
+ asset: Address;
61
+ /**
62
+ * The type of disbursement strategy for the incentive. `StrategyType.MINT` is not supported for `ERC20Incentives`
63
+ *
64
+ * @type {StrategyType}
65
+ */
66
+ strategy: StrategyType;
67
+ /**
68
+ * The amount of the asset to distribute.
69
+ *
70
+ * @type {bigint}
71
+ */
72
+ reward: bigint;
73
+ /**
74
+ * How many times can this incentive be claimed.
75
+ *
76
+ * @type {bigint}
77
+ */
78
+ limit: bigint;
79
+ }
80
+
81
+ /**
82
+ * A generic `viem.Log` event with support for `ERC20Incentive` event types.
83
+ *
84
+ * @export
85
+ * @typedef {ERC20IncentiveLog}
86
+ * @template {ContractEventName<typeof erc20IncentiveAbi>} [event=ContractEventName<
87
+ * typeof erc20IncentiveAbi
88
+ * >]
89
+ */
90
+ export type ERC20IncentiveLog<
91
+ event extends ContractEventName<typeof erc20IncentiveAbi> = ContractEventName<
92
+ typeof erc20IncentiveAbi
93
+ >,
94
+ > = GenericLog<typeof erc20IncentiveAbi, event>;
95
+
96
+ /**
97
+ * A simple ERC20 incentive implementation that allows claiming of tokens
98
+ *
99
+ * @export
100
+ * @class ERC20Incentive
101
+ * @typedef {ERC20Incentive}
102
+ * @extends {DeployableTarget<ERC20IncentivePayload>}
103
+ */
104
+ export class ERC20Incentive extends DeployableTarget<
105
+ ERC20IncentivePayload,
106
+ typeof erc20IncentiveAbi
107
+ > {
108
+ public override readonly abi = erc20IncentiveAbi;
109
+ /**
110
+ * @inheritdoc
111
+ *
112
+ * @public
113
+ * @static
114
+ * @type {Record<number, Address>}
115
+ */
116
+ public static override bases: Record<number, Address> = {
117
+ ...(ERC20IncentiveBases as Record<number, Address>),
118
+ };
119
+ /**
120
+ * @inheritdoc
121
+ *
122
+ * @public
123
+ * @static
124
+ * @type {RegistryType}
125
+ */
126
+ public static override registryType: RegistryType = RegistryType.INCENTIVE;
127
+
128
+ /**
129
+ * The owner of the incentive
130
+ *
131
+ * @public
132
+ * @async
133
+ * @param {?ReadParams} [params]
134
+ * @returns {Promise<Address>}
135
+ */
136
+ public async owner(params?: ReadParams<typeof erc20IncentiveAbi, 'owner'>) {
137
+ return await readErc20IncentiveOwner(this._config, {
138
+ address: this.assertValidAddress(),
139
+ args: [],
140
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
141
+ ...(params as any),
142
+ });
143
+ }
144
+
145
+ /**
146
+ * 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)`
147
+ *
148
+ * @public
149
+ * @async
150
+ * @param {?ReadParams} [params]
151
+ * @returns {Promise<bigint>} - The current reward
152
+ */
153
+ public async currentReward(
154
+ params?: ReadParams<typeof erc20IncentiveAbi, 'currentReward'>,
155
+ ) {
156
+ return await readErc20IncentiveCurrentReward(this._config, {
157
+ address: this.assertValidAddress(),
158
+ args: [],
159
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
160
+ ...(params as any),
161
+ });
162
+ }
163
+
164
+ /**
165
+ * The number of claims that have been made
166
+ *
167
+ * @public
168
+ * @async
169
+ * @param {?ReadParams} [params]
170
+ * @returns {Promise<bigint>}
171
+ */
172
+ public async claims(params?: ReadParams<typeof erc20IncentiveAbi, 'claims'>) {
173
+ return await readErc20IncentiveClaims(this._config, {
174
+ address: this.assertValidAddress(),
175
+ args: [],
176
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
177
+ ...(params as any),
178
+ });
179
+ }
180
+
181
+ /**
182
+ * A mapping of address to claim status
183
+ *
184
+ * @public
185
+ * @async
186
+ * @param {Address} address
187
+ * @param {?ReadParams} [params]
188
+ * @returns {Promise<boolean>}
189
+ */
190
+ public async claimed(
191
+ address: Address,
192
+ params?: ReadParams<typeof erc20IncentiveAbi, 'claimed'>,
193
+ ) {
194
+ return await readErc20IncentiveClaimed(this._config, {
195
+ address: this.assertValidAddress(),
196
+ args: [address],
197
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
198
+ ...(params as any),
199
+ });
200
+ }
201
+
202
+ /**
203
+ * The address of the ERC20-like token
204
+ *
205
+ * @public
206
+ * @async
207
+ * @param {?ReadParams} [params]
208
+ * @returns {Promise<Address>}
209
+ */
210
+ public async asset(params?: ReadParams<typeof erc20IncentiveAbi, 'asset'>) {
211
+ return await readErc20IncentiveAsset(this._config, {
212
+ address: this.assertValidAddress(),
213
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
214
+ ...(params as any),
215
+ });
216
+ }
217
+
218
+ /**
219
+ * The strategy for the incentive (MINT or POOL)
220
+ *
221
+ * @public
222
+ * @async
223
+ * @param {?ReadParams} [params]
224
+ * @returns {Promise<StrategyType>}
225
+ */
226
+ public strategy(
227
+ params?: ReadParams<typeof erc20IncentiveAbi, 'strategy'>,
228
+ ): Promise<StrategyType> {
229
+ return readErc20IncentiveStrategy(this._config, {
230
+ address: this.assertValidAddress(),
231
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
232
+ ...(params as any),
233
+ }) as Promise<StrategyType>;
234
+ }
235
+
236
+ /**
237
+ * The reward amount issued for each claim
238
+ *
239
+ * @public
240
+ * @async
241
+ * @param {?ReadParams} [params]
242
+ * @returns {Promise<bigint>}
243
+ */
244
+ public async reward(params?: ReadParams<typeof erc20IncentiveAbi, 'reward'>) {
245
+ return await readErc20IncentiveReward(this._config, {
246
+ address: this.assertValidAddress(),
247
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
248
+ ...(params as any),
249
+ });
250
+ }
251
+
252
+ /**
253
+ * The limit (max claims, or max entries for raffles)
254
+ *
255
+ * @public
256
+ * @async
257
+ * @param {?ReadParams} [params]
258
+ * @returns {Promise<bigint>}
259
+ */
260
+ public async limit(params?: ReadParams<typeof erc20IncentiveAbi, 'limit'>) {
261
+ return await readErc20IncentiveLimit(this._config, {
262
+ address: this.assertValidAddress(),
263
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
264
+ ...(params as any),
265
+ });
266
+ }
267
+
268
+ /**
269
+ * The set of addresses that have claimed a slot in the incentive raffle, accessed by bigint index.
270
+ *
271
+ * @public
272
+ * @async
273
+ * @param {bigint} i - Index of address
274
+ * @param {?ReadParams} [params]
275
+ * @returns {Promise<Address>}
276
+ */
277
+ public async entries(
278
+ i: bigint,
279
+ params?: ReadParams<typeof erc20IncentiveAbi, 'entries'>,
280
+ ) {
281
+ return await readErc20IncentiveEntries(this._config, {
282
+ address: this.assertValidAddress(),
283
+ args: [i],
284
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
285
+ ...(params as any),
286
+ });
287
+ }
288
+
289
+ /**
290
+ * Claim the incentive
291
+ *
292
+ * @public
293
+ * @async
294
+ * @param {ClaimPayload} payload
295
+ * @param {?WriteParams} [params]
296
+ * @returns {Promise<boolean>} - Returns true if successfully claimed
297
+ */
298
+ protected async claim(
299
+ payload: ClaimPayload,
300
+ params?: WriteParams<typeof erc20IncentiveAbi, 'claim'>,
301
+ ) {
302
+ return await this.awaitResult(this.claimRaw(payload, params));
303
+ }
304
+
305
+ /**
306
+ * Claim the incentive
307
+ *
308
+ * @public
309
+ * @async
310
+ * @param {ClaimPayload} payload
311
+ * @param {?WriteParams} [params]
312
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - Returns true if successfully claimed
313
+ */
314
+ protected async claimRaw(
315
+ payload: ClaimPayload,
316
+ params?: WriteParams<typeof erc20IncentiveAbi, 'claim'>,
317
+ ) {
318
+ const { request, result } = await simulateErc20IncentiveClaim(
319
+ this._config,
320
+ {
321
+ address: this.assertValidAddress(),
322
+ args: [prepareClaimPayload(payload)],
323
+ ...this.optionallyAttachAccount(),
324
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
325
+ ...(params as any),
326
+ },
327
+ );
328
+ const hash = await writeErc20IncentiveClaim(this._config, request);
329
+ return { hash, result };
330
+ }
331
+
332
+ /**
333
+ * Clawback assets from the incentive
334
+ *
335
+ * @public
336
+ * @async
337
+ * @param {ClaimPayload} payload
338
+ * @param {?WriteParams} [params]
339
+ * @returns {Promise<boolean>} - True if the assets were successfully clawbacked
340
+ */
341
+ public async clawback(
342
+ payload: ClaimPayload,
343
+ params?: WriteParams<typeof erc20IncentiveAbi, 'clawback'>,
344
+ ) {
345
+ return await this.awaitResult(this.clawbackRaw(payload, params));
346
+ }
347
+
348
+ /**
349
+ * Clawback assets from the incentive
350
+ *
351
+ * @public
352
+ * @async
353
+ * @param {ClaimPayload} payload
354
+ * @param {?WriteParams} [params]
355
+ * @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if the assets were successfully clawbacked
356
+ */
357
+ public async clawbackRaw(
358
+ payload: ClaimPayload,
359
+ params?: WriteParams<typeof erc20IncentiveAbi, 'clawback'>,
360
+ ) {
361
+ const { request, result } = await simulateErc20IncentiveClawback(
362
+ this._config,
363
+ {
364
+ address: this.assertValidAddress(),
365
+ args: [prepareClaimPayload(payload)],
366
+ ...this.optionallyAttachAccount(),
367
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
368
+ ...(params as any),
369
+ },
370
+ );
371
+ const hash = await writeErc20IncentiveClawback(this._config, request);
372
+ return { hash, result };
373
+ }
374
+
375
+ /**
376
+ * Check if an incentive is claimable. For the POOL strategy, the `bytes data` portion of the payload ignored. The recipient must not have already claimed the incentive.
377
+ *
378
+ * @public
379
+ * @async
380
+ * @param {ClaimPayload} payload
381
+ * @param {?ReadParams} [params]
382
+ * @returns {Promise<boolean>} = True if the incentive is claimable based on the data payload
383
+ */
384
+ public async isClaimable(
385
+ payload: ClaimPayload,
386
+ params?: ReadParams<typeof erc20IncentiveAbi, 'isClaimable'>,
387
+ ) {
388
+ return await readErc20IncentiveIsClaimable(this._config, {
389
+ address: this.assertValidAddress(),
390
+ args: [prepareClaimPayload(payload)],
391
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
392
+ ...(params as any),
393
+ });
394
+ }
395
+
396
+ /**
397
+ * Draw a winner from the raffle. Only callable by owner. Only valid when the strategy is set to `Strategy.RAFFLE`
398
+ *
399
+ * @public
400
+ * @async
401
+ * @param {?WriteParams} [params]
402
+ * @returns {Promise<void>}
403
+ */
404
+ public async drawRaffle(
405
+ params?: WriteParams<typeof erc20IncentiveAbi, 'drawRaffle'>,
406
+ ) {
407
+ return await this.awaitResult(this.drawRaffleRaw(params));
408
+ }
409
+
410
+ /**
411
+ * Draw a winner from the raffle. Only callable by owner. Only valid when the strategy is set to `Strategy.RAFFLE`
412
+ *
413
+ * @public
414
+ * @async
415
+ * @param {?WriteParams} [params]
416
+ * @returns {Promise<{ hash: `0x${string}`; result: void; }>}
417
+ */
418
+ public async drawRaffleRaw(
419
+ params?: WriteParams<typeof erc20IncentiveAbi, 'drawRaffle'>,
420
+ ) {
421
+ const { request, result } = await simulateErc20IncentiveDrawRaffle(
422
+ this._config,
423
+ {
424
+ address: this.assertValidAddress(),
425
+ ...this.optionallyAttachAccount(),
426
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
427
+ ...(params as any),
428
+ },
429
+ );
430
+ const hash = await writeErc20IncentiveDrawRaffle(this._config, request);
431
+ return { hash, result };
432
+ }
433
+
434
+ /**
435
+ * @inheritdoc
436
+ *
437
+ * @public
438
+ * @param {?ERC20IncentivePayload} [_payload]
439
+ * @param {?DeployableOptions} [_options]
440
+ * @returns {GenericDeployableParams}
441
+ */
442
+ public override buildParameters(
443
+ _payload?: ERC20IncentivePayload,
444
+ _options?: DeployableOptions,
445
+ ): GenericDeployableParams {
446
+ const [payload, options] = this.validateDeploymentConfig(
447
+ _payload,
448
+ _options,
449
+ );
450
+ return {
451
+ abi: erc20IncentiveAbi,
452
+ bytecode: bytecode as Hex,
453
+ args: [prepareERC20IncentivePayload(payload)],
454
+ ...this.optionallyAttachAccount(options.account),
455
+ };
456
+ }
457
+ }
458
+
459
+ /**
460
+ * Given a {@link ERC20IncentivePayload}, properly encode a `ERC20Incentive.InitPayload` for use with {@link ERC20Incentive} initialization.
461
+ *
462
+ * @param {ERC20IncentivePayload} param0
463
+ * @param {Address} param0.asset - The address of the incentivized asset.
464
+ * @param {StrategyType} param0.strategy - The type of disbursement strategy for the incentive. `StrategyType.MINT` is not supported for `ERC20Incentives`
465
+ * @param {bigint} param0.reward - The amount of the asset to distribute.
466
+ * @param {bigint} param0.limit - How many times can this incentive be claimed.
467
+ * @returns {Hex}
468
+ */
469
+ export function prepareERC20IncentivePayload({
470
+ asset,
471
+ strategy,
472
+ reward,
473
+ limit,
474
+ }: ERC20IncentivePayload) {
475
+ return encodeAbiParameters(
476
+ [
477
+ { type: 'address', name: 'asset' },
478
+ { type: 'uint8', name: 'strategy' },
479
+ { type: 'uint256', name: 'reward' },
480
+ { type: 'uint256', name: 'limit' },
481
+ ],
482
+ [asset, strategy, reward, limit],
483
+ );
484
+ }
@@ -0,0 +1,184 @@
1
+ import { Mock } from 'node:test';
2
+ import { selectors as eventSelectors } from '@boostxyz/signatures/events';
3
+ import { selectors as funcSelectors } from '@boostxyz/signatures/functions';
4
+ import type { MockERC20 } from '@boostxyz/test/MockERC20';
5
+ import type { MockERC721 } from '@boostxyz/test/MockERC721';
6
+ import { accounts } from '@boostxyz/test/accounts';
7
+ import {
8
+ type BudgetFixtures,
9
+ type Fixtures,
10
+ defaultOptions,
11
+ deployFixtures,
12
+ freshBoost,
13
+ fundBudget,
14
+ fundErc20,
15
+ fundErc721,
16
+ } from '@boostxyz/test/helpers';
17
+ import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
18
+ import { type Hex, isAddress, parseEther } from 'viem';
19
+ import { beforeAll, beforeEach, describe, expect, test } from 'vitest';
20
+ import { SignatureType } from '../Actions/EventAction';
21
+ import type { Boost } from '../Boost';
22
+ import type {
23
+ ERC20VariableCriteriaIncentive,
24
+ ERC20VariableCriteriaIncentivePayload,
25
+ IncentiveCriteria,
26
+ } from './ERC20VariableCriteriaIncentive';
27
+
28
+ /**
29
+ * A basic ERC721 mint scalar criteria for testing
30
+ *
31
+ * @param {MockERC721} erc721 - The ERC721 contract
32
+ * @returns {IncentiveCriteria} - Returns a basic incentive criteria
33
+ */
34
+ export function basicErc721TransferScalarCriteria(
35
+ erc721: MockERC721,
36
+ ): IncentiveCriteria {
37
+ return {
38
+ criteriaType: SignatureType.FUNC,
39
+ signature: funcSelectors['transferFrom(address,address,uint256)'] as Hex, // Function selector for mint
40
+ fieldIndex: 2, // Field where the scalar value resides
41
+ targetContract: erc721.assertValidAddress(),
42
+ };
43
+ }
44
+
45
+ /**
46
+ * A basic ERC721 mint scalar criteria for testing
47
+ *
48
+ * @param {MockERC721} erc721 - The ERC721 contract
49
+ * @returns {IncentiveCriteria} - Returns a basic incentive criteria
50
+ */
51
+ export function basicErc721MintScalarCriteria(
52
+ erc721: MockERC721,
53
+ ): IncentiveCriteria {
54
+ return {
55
+ criteriaType: SignatureType.EVENT,
56
+ signature: eventSelectors[
57
+ 'Transfer(address indexed,address indexed,uint256 indexed)'
58
+ ] as Hex, // Function selector for mint
59
+ fieldIndex: 2, // Field where the scalar value resides
60
+ targetContract: erc721.assertValidAddress(),
61
+ };
62
+ }
63
+
64
+ /**
65
+ * A basic ERC721 mint scalar payload for testing
66
+ *
67
+ * @param {MockERC721} erc721 - The ERC721 contract
68
+ * @returns {ERC20VariableCriteriaIncentivePayload} - Returns a full variable criteria incentive payload
69
+ */
70
+ export function basicErc721TransferScalarPayload(
71
+ erc721: MockERC721,
72
+ ): ERC20VariableCriteriaIncentivePayload {
73
+ return {
74
+ asset: erc721.assertValidAddress(),
75
+ reward: 1n,
76
+ limit: 1n,
77
+ criteria: basicErc721TransferScalarCriteria(erc721),
78
+ };
79
+ }
80
+
81
+ let fixtures: Fixtures,
82
+ erc20: MockERC20,
83
+ erc721: MockERC721,
84
+ erc20Incentive: ERC20VariableCriteriaIncentive,
85
+ budgets: BudgetFixtures,
86
+ boost: Boost;
87
+
88
+ describe('ERC20VariableCriteriaIncentive', () => {
89
+ beforeAll(async () => {
90
+ fixtures = await loadFixture(deployFixtures(defaultOptions));
91
+ });
92
+
93
+ beforeEach(async () => {
94
+ budgets = await loadFixture(fundBudget(defaultOptions, fixtures));
95
+ erc20 = await loadFixture(fundErc20(defaultOptions));
96
+ erc721 = await loadFixture(fundErc721(defaultOptions));
97
+ erc20Incentive = fixtures.core.ERC20VariableCriteriaIncentive({
98
+ asset: budgets.erc20.assertValidAddress(),
99
+ reward: 1n,
100
+ limit: 1n,
101
+ criteria: basicErc721TransferScalarCriteria(erc721),
102
+ });
103
+
104
+ boost = await freshBoost(fixtures, {
105
+ budget: budgets.budget,
106
+ incentives: [erc20Incentive],
107
+ });
108
+ expect(isAddress(boost.incentives[0]!.assertValidAddress())).toBe(true);
109
+ });
110
+
111
+ describe('getIncentiveCriteria', () => {
112
+ test('should fetch incentive criteria successfully', async () => {
113
+ const incentive = boost.incentives[0] as ERC20VariableCriteriaIncentive;
114
+ const criteria = await incentive.getIncentiveCriteria();
115
+ expect(criteria).toMatchObject({
116
+ criteriaType: SignatureType.FUNC,
117
+ signature: expect.any(String),
118
+ fieldIndex: expect.any(Number),
119
+ targetContract: expect.any(String),
120
+ });
121
+ });
122
+ });
123
+
124
+ describe('getIncentiveScalar', () => {
125
+ test('should return a valid scalar for function-based criteria', async () => {
126
+ const recipient = accounts[1].account;
127
+
128
+ const { hash } = await erc721.transferFromRaw(
129
+ accounts[0].account,
130
+ recipient,
131
+ 1n,
132
+ );
133
+ const scalar = await erc20Incentive.getIncentiveScalar({ hash });
134
+
135
+ expect(scalar).toBe(1n);
136
+ });
137
+
138
+ test('should return a valid scalar for event-based criteria', async () => {
139
+ erc20Incentive = fixtures.core.ERC20VariableCriteriaIncentive({
140
+ asset: budgets.erc20.assertValidAddress(),
141
+ reward: 1n,
142
+ limit: 1n,
143
+ criteria: basicErc721MintScalarCriteria(erc721),
144
+ });
145
+
146
+ boost = await freshBoost(fixtures, {
147
+ budget: budgets.budget,
148
+ incentives: [erc20Incentive],
149
+ });
150
+ const recipient = accounts[1].account;
151
+ const { hash } = await erc721.transferFromRaw(
152
+ accounts[0].account,
153
+ recipient,
154
+ 1n,
155
+ );
156
+ const scalar = await erc20Incentive.getIncentiveScalar({ hash });
157
+
158
+ expect(scalar).toBe(1n);
159
+ });
160
+
161
+ test('should throw NoMatchingLogsError for event criteria with no matching logs', async () => {
162
+ const recipient = accounts[1].account;
163
+
164
+ const { hash } = await erc20.mintRaw(recipient, parseEther('100'));
165
+
166
+ try {
167
+ await erc20Incentive.getIncentiveScalar({ hash });
168
+ } catch (e) {
169
+ expect((e as Error).name).toBe('DecodedArgsError');
170
+ }
171
+ });
172
+
173
+ test('should throw DecodedArgsError for invalid function-based data', async () => {
174
+ const recipient = accounts[1].account;
175
+ const { hash } = await erc20.mintRaw(recipient, parseEther('100'));
176
+
177
+ try {
178
+ await erc20Incentive.getIncentiveScalar({ hash });
179
+ } catch (e) {
180
+ expect((e as Error).name).toBe('DecodedArgsError');
181
+ }
182
+ });
183
+ });
184
+ });