@boostxyz/sdk 0.0.0-alpha.10

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 (242) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +7 -0
  3. package/dist/Actions/Action.cjs +2 -0
  4. package/dist/Actions/Action.cjs.map +1 -0
  5. package/dist/Actions/Action.d.ts +31 -0
  6. package/dist/Actions/Action.d.ts.map +1 -0
  7. package/dist/Actions/Action.js +29 -0
  8. package/dist/Actions/Action.js.map +1 -0
  9. package/dist/Actions/ContractAction.d.ts +370 -0
  10. package/dist/Actions/ContractAction.d.ts.map +1 -0
  11. package/dist/Actions/ERC721MintAction.d.ts +513 -0
  12. package/dist/Actions/ERC721MintAction.d.ts.map +1 -0
  13. package/dist/Actions/EventAction.cjs +2 -0
  14. package/dist/Actions/EventAction.cjs.map +1 -0
  15. package/dist/Actions/EventAction.d.ts +694 -0
  16. package/dist/Actions/EventAction.d.ts.map +1 -0
  17. package/dist/Actions/EventAction.js +491 -0
  18. package/dist/Actions/EventAction.js.map +1 -0
  19. package/dist/AllowLists/AllowList.cjs +2 -0
  20. package/dist/AllowLists/AllowList.cjs.map +1 -0
  21. package/dist/AllowLists/AllowList.d.ts +32 -0
  22. package/dist/AllowLists/AllowList.d.ts.map +1 -0
  23. package/dist/AllowLists/AllowList.js +30 -0
  24. package/dist/AllowLists/AllowList.js.map +1 -0
  25. package/dist/AllowLists/SimpleAllowList.cjs +2 -0
  26. package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
  27. package/dist/AllowLists/SimpleAllowList.d.ts +481 -0
  28. package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -0
  29. package/dist/AllowLists/SimpleAllowList.js +154 -0
  30. package/dist/AllowLists/SimpleAllowList.js.map +1 -0
  31. package/dist/AllowLists/SimpleDenyList.cjs +2 -0
  32. package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
  33. package/dist/AllowLists/SimpleDenyList.d.ts +335 -0
  34. package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -0
  35. package/dist/AllowLists/SimpleDenyList.js +115 -0
  36. package/dist/AllowLists/SimpleDenyList.js.map +1 -0
  37. package/dist/Auth/Auth.cjs +2 -0
  38. package/dist/Auth/Auth.cjs.map +1 -0
  39. package/dist/Auth/Auth.d.ts +10 -0
  40. package/dist/Auth/Auth.d.ts.map +1 -0
  41. package/dist/Auth/Auth.js +5 -0
  42. package/dist/Auth/Auth.js.map +1 -0
  43. package/dist/Auth/PassthroughAuth.cjs +2 -0
  44. package/dist/Auth/PassthroughAuth.cjs.map +1 -0
  45. package/dist/Auth/PassthroughAuth.d.ts +51 -0
  46. package/dist/Auth/PassthroughAuth.d.ts.map +1 -0
  47. package/dist/Auth/PassthroughAuth.js +39 -0
  48. package/dist/Auth/PassthroughAuth.js.map +1 -0
  49. package/dist/Boost.cjs +2 -0
  50. package/dist/Boost.cjs.map +1 -0
  51. package/dist/Boost.d.ts +234 -0
  52. package/dist/Boost.d.ts.map +1 -0
  53. package/dist/Boost.js +162 -0
  54. package/dist/Boost.js.map +1 -0
  55. package/dist/BoostCore.cjs +3 -0
  56. package/dist/BoostCore.cjs.map +1 -0
  57. package/dist/BoostCore.d.ts +498 -0
  58. package/dist/BoostCore.d.ts.map +1 -0
  59. package/dist/BoostCore.js +1153 -0
  60. package/dist/BoostCore.js.map +1 -0
  61. package/dist/BoostRegistry.cjs +2 -0
  62. package/dist/BoostRegistry.cjs.map +1 -0
  63. package/dist/BoostRegistry.d.ts +243 -0
  64. package/dist/BoostRegistry.d.ts.map +1 -0
  65. package/dist/BoostRegistry.js +262 -0
  66. package/dist/BoostRegistry.js.map +1 -0
  67. package/dist/Budgets/Budget.cjs +2 -0
  68. package/dist/Budgets/Budget.cjs.map +1 -0
  69. package/dist/Budgets/Budget.d.ts +31 -0
  70. package/dist/Budgets/Budget.d.ts.map +1 -0
  71. package/dist/Budgets/Budget.js +29 -0
  72. package/dist/Budgets/Budget.js.map +1 -0
  73. package/dist/Budgets/ManagedBudget.cjs +2 -0
  74. package/dist/Budgets/ManagedBudget.cjs.map +1 -0
  75. package/dist/Budgets/ManagedBudget.d.ts +1103 -0
  76. package/dist/Budgets/ManagedBudget.d.ts.map +1 -0
  77. package/dist/Budgets/ManagedBudget.js +516 -0
  78. package/dist/Budgets/ManagedBudget.js.map +1 -0
  79. package/dist/Budgets/SimpleBudget.d.ts +824 -0
  80. package/dist/Budgets/SimpleBudget.d.ts.map +1 -0
  81. package/dist/Budgets/VestingBudget.d.ts +778 -0
  82. package/dist/Budgets/VestingBudget.d.ts.map +1 -0
  83. package/dist/Deployable/Contract.cjs +2 -0
  84. package/dist/Deployable/Contract.cjs.map +1 -0
  85. package/dist/Deployable/Contract.d.ts +125 -0
  86. package/dist/Deployable/Contract.d.ts.map +1 -0
  87. package/dist/Deployable/Contract.js +150 -0
  88. package/dist/Deployable/Contract.js.map +1 -0
  89. package/dist/Deployable/Deployable.cjs +2 -0
  90. package/dist/Deployable/Deployable.cjs.map +1 -0
  91. package/dist/Deployable/Deployable.d.ts +161 -0
  92. package/dist/Deployable/Deployable.d.ts.map +1 -0
  93. package/dist/Deployable/Deployable.js +131 -0
  94. package/dist/Deployable/Deployable.js.map +1 -0
  95. package/dist/Deployable/DeployableTarget.cjs +2 -0
  96. package/dist/Deployable/DeployableTarget.cjs.map +1 -0
  97. package/dist/Deployable/DeployableTarget.d.ts +116 -0
  98. package/dist/Deployable/DeployableTarget.d.ts.map +1 -0
  99. package/dist/Deployable/DeployableTarget.js +132 -0
  100. package/dist/Deployable/DeployableTarget.js.map +1 -0
  101. package/dist/Incentives/AllowListIncentive.cjs +2 -0
  102. package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
  103. package/dist/Incentives/AllowListIncentive.d.ts +513 -0
  104. package/dist/Incentives/AllowListIncentive.d.ts.map +1 -0
  105. package/dist/Incentives/AllowListIncentive.js +201 -0
  106. package/dist/Incentives/AllowListIncentive.js.map +1 -0
  107. package/dist/Incentives/CGDAIncentive.cjs +2 -0
  108. package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
  109. package/dist/Incentives/CGDAIncentive.d.ts +644 -0
  110. package/dist/Incentives/CGDAIncentive.d.ts.map +1 -0
  111. package/dist/Incentives/CGDAIncentive.js +271 -0
  112. package/dist/Incentives/CGDAIncentive.js.map +1 -0
  113. package/dist/Incentives/ERC1155Incentive.d.ts +713 -0
  114. package/dist/Incentives/ERC1155Incentive.d.ts.map +1 -0
  115. package/dist/Incentives/ERC20Incentive.cjs +2 -0
  116. package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
  117. package/dist/Incentives/ERC20Incentive.d.ts +666 -0
  118. package/dist/Incentives/ERC20Incentive.d.ts.map +1 -0
  119. package/dist/Incentives/ERC20Incentive.js +312 -0
  120. package/dist/Incentives/ERC20Incentive.js.map +1 -0
  121. package/dist/Incentives/ERC20VariableIncentive.d.ts +582 -0
  122. package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -0
  123. package/dist/Incentives/Incentive.cjs +2 -0
  124. package/dist/Incentives/Incentive.cjs.map +1 -0
  125. package/dist/Incentives/Incentive.d.ts +36 -0
  126. package/dist/Incentives/Incentive.d.ts.map +1 -0
  127. package/dist/Incentives/Incentive.js +299 -0
  128. package/dist/Incentives/Incentive.js.map +1 -0
  129. package/dist/Incentives/PointsIncentive.cjs +2 -0
  130. package/dist/Incentives/PointsIncentive.cjs.map +1 -0
  131. package/dist/Incentives/PointsIncentive.d.ts +659 -0
  132. package/dist/Incentives/PointsIncentive.d.ts.map +1 -0
  133. package/dist/Incentives/PointsIncentive.js +215 -0
  134. package/dist/Incentives/PointsIncentive.js.map +1 -0
  135. package/dist/Validators/SignerValidator.cjs +2 -0
  136. package/dist/Validators/SignerValidator.cjs.map +1 -0
  137. package/dist/Validators/SignerValidator.d.ts +745 -0
  138. package/dist/Validators/SignerValidator.d.ts.map +1 -0
  139. package/dist/Validators/SignerValidator.js +293 -0
  140. package/dist/Validators/SignerValidator.js.map +1 -0
  141. package/dist/Validators/Validator.cjs +2 -0
  142. package/dist/Validators/Validator.cjs.map +1 -0
  143. package/dist/Validators/Validator.d.ts +31 -0
  144. package/dist/Validators/Validator.d.ts.map +1 -0
  145. package/dist/Validators/Validator.js +27 -0
  146. package/dist/Validators/Validator.js.map +1 -0
  147. package/dist/claiming.cjs +2 -0
  148. package/dist/claiming.cjs.map +1 -0
  149. package/dist/claiming.d.ts +43 -0
  150. package/dist/claiming.d.ts.map +1 -0
  151. package/dist/claiming.js +17 -0
  152. package/dist/claiming.js.map +1 -0
  153. package/dist/componentInterfaces-CKCBwG16.cjs +2 -0
  154. package/dist/componentInterfaces-CKCBwG16.cjs.map +1 -0
  155. package/dist/componentInterfaces-DYkaxBda.js +13 -0
  156. package/dist/componentInterfaces-DYkaxBda.js.map +1 -0
  157. package/dist/errors.cjs +2 -0
  158. package/dist/errors.cjs.map +1 -0
  159. package/dist/errors.d.ts +441 -0
  160. package/dist/errors.d.ts.map +1 -0
  161. package/dist/errors.js +262 -0
  162. package/dist/errors.js.map +1 -0
  163. package/dist/generated-BDeDiaCK.js +4625 -0
  164. package/dist/generated-BDeDiaCK.js.map +1 -0
  165. package/dist/generated-wKBNvm48.cjs +3 -0
  166. package/dist/generated-wKBNvm48.cjs.map +1 -0
  167. package/dist/index.cjs +2 -0
  168. package/dist/index.cjs.map +1 -0
  169. package/dist/index.d.ts +25 -0
  170. package/dist/index.d.ts.map +1 -0
  171. package/dist/index.js +113 -0
  172. package/dist/index.js.map +1 -0
  173. package/dist/transfers.cjs +2 -0
  174. package/dist/transfers.cjs.map +1 -0
  175. package/dist/transfers.d.ts +198 -0
  176. package/dist/transfers.d.ts.map +1 -0
  177. package/dist/transfers.js +84 -0
  178. package/dist/transfers.js.map +1 -0
  179. package/dist/utils.cjs +2 -0
  180. package/dist/utils.cjs.map +1 -0
  181. package/dist/utils.d.ts +116 -0
  182. package/dist/utils.d.ts.map +1 -0
  183. package/dist/utils.js +30 -0
  184. package/dist/utils.js.map +1 -0
  185. package/package.json +211 -0
  186. package/src/Actions/Action.test.ts +75 -0
  187. package/src/Actions/Action.ts +61 -0
  188. package/src/Actions/ContractAction.test.ts +197 -0
  189. package/src/Actions/ContractAction.ts +301 -0
  190. package/src/Actions/ERC721MintAction.test.ts +112 -0
  191. package/src/Actions/ERC721MintAction.ts +292 -0
  192. package/src/Actions/EventAction.test.ts +205 -0
  193. package/src/Actions/EventAction.ts +811 -0
  194. package/src/AllowLists/AllowList.test.ts +64 -0
  195. package/src/AllowLists/AllowList.ts +60 -0
  196. package/src/AllowLists/SimpleAllowList.test.ts +52 -0
  197. package/src/AllowLists/SimpleAllowList.ts +284 -0
  198. package/src/AllowLists/SimpleDenyList.test.ts +52 -0
  199. package/src/AllowLists/SimpleDenyList.ts +227 -0
  200. package/src/Auth/Auth.ts +11 -0
  201. package/src/Auth/PassthroughAuth.test.ts +12 -0
  202. package/src/Auth/PassthroughAuth.ts +80 -0
  203. package/src/Boost.ts +290 -0
  204. package/src/BoostCore.test.ts +773 -0
  205. package/src/BoostCore.ts +1261 -0
  206. package/src/BoostRegistry.ts +467 -0
  207. package/src/Budgets/Budget.test.ts +27 -0
  208. package/src/Budgets/Budget.ts +61 -0
  209. package/src/Budgets/ManagedBudget.test.ts +154 -0
  210. package/src/Budgets/ManagedBudget.ts +796 -0
  211. package/src/Budgets/SimpleBudget.test.ts +152 -0
  212. package/src/Budgets/SimpleBudget.ts +564 -0
  213. package/src/Budgets/VestingBudget.test.ts +123 -0
  214. package/src/Budgets/VestingBudget.ts +602 -0
  215. package/src/Deployable/Contract.ts +229 -0
  216. package/src/Deployable/Deployable.ts +250 -0
  217. package/src/Deployable/DeployableTarget.ts +223 -0
  218. package/src/Incentives/AllowListIncentive.test.ts +143 -0
  219. package/src/Incentives/AllowListIncentive.ts +334 -0
  220. package/src/Incentives/CGDAIncentive.test.ts +132 -0
  221. package/src/Incentives/CGDAIncentive.ts +468 -0
  222. package/src/Incentives/ERC1155Incentive.test.ts +87 -0
  223. package/src/Incentives/ERC1155Incentive.ts +466 -0
  224. package/src/Incentives/ERC20Incentive.test.ts +130 -0
  225. package/src/Incentives/ERC20Incentive.ts +482 -0
  226. package/src/Incentives/ERC20VariableIncentive.test.ts +136 -0
  227. package/src/Incentives/ERC20VariableIncentive.ts +420 -0
  228. package/src/Incentives/Incentive.test.ts +92 -0
  229. package/src/Incentives/Incentive.ts +85 -0
  230. package/src/Incentives/PointsIncentive.test.ts +139 -0
  231. package/src/Incentives/PointsIncentive.ts +365 -0
  232. package/src/Validators/SignerValidator.test.ts +159 -0
  233. package/src/Validators/SignerValidator.ts +681 -0
  234. package/src/Validators/Validator.test.ts +21 -0
  235. package/src/Validators/Validator.ts +55 -0
  236. package/src/claiming.ts +56 -0
  237. package/src/errors.ts +542 -0
  238. package/src/index.test.ts +40 -0
  239. package/src/index.ts +53 -0
  240. package/src/transfers.ts +284 -0
  241. package/src/utils.test.ts +44 -0
  242. package/src/utils.ts +198 -0
@@ -0,0 +1,229 @@
1
+ import { type Config, watchContractEvent } from '@wagmi/core';
2
+ import type { ExtractAbiEvent } from 'abitype';
3
+ import {
4
+ type Abi,
5
+ type Address,
6
+ type ContractEventName,
7
+ type GetLogsReturnType,
8
+ type WaitForTransactionReceiptParameters,
9
+ type WatchContractEventOnLogsParameter,
10
+ getAbiItem,
11
+ } from 'viem';
12
+ import { getLogs } from 'viem/actions';
13
+ import { ContractAddressRequiredError } from '../errors';
14
+ import {
15
+ type GetLogsParams,
16
+ type HashAndSimulatedResult,
17
+ type WatchParams,
18
+ awaitResult,
19
+ } from '../utils';
20
+
21
+ /**
22
+ * A basic Contract class to encapsulate configuration and a potential address
23
+ *
24
+ * @export
25
+ * @class Contract
26
+ * @typedef {Contract}
27
+ * @template {Abi} [ContractAbi=[]]
28
+ * @template {ContractEventName<ContractAbi>} [ContractEvent=any]
29
+ */
30
+ export class Contract<ContractAbi extends Abi> {
31
+ //@ts-expect-error this should always be set by implementing contract
32
+ public readonly abi: ContractAbi;
33
+ /**
34
+ * @see [Wagmi Configuration](https://wagmi.sh/core/api/createConfig)
35
+ * @protected
36
+ * @type {WagmiConfig}
37
+ */
38
+ protected _config: Config;
39
+ /**
40
+ * The internally managed address for this contract
41
+ *
42
+ * @protected
43
+ * @type {(Address | undefined)}
44
+ */
45
+ protected _address: Address | undefined;
46
+
47
+ /**
48
+ * Creates an instance of Contract.
49
+ *
50
+ * @constructor
51
+ * @param {Config} config
52
+ * @param {(Address | undefined)} address
53
+ */
54
+ constructor(config: Config, address: Address | undefined) {
55
+ this._config = config;
56
+ this._address = address;
57
+ }
58
+
59
+ /**
60
+ * A getter returning this contract's deployed address, if it exists.
61
+ *
62
+ * @public
63
+ * @readonly
64
+ * @type {*}
65
+ */
66
+ public get address() {
67
+ return this._address;
68
+ }
69
+
70
+ /**
71
+ * Will set this contract's address and return the instance for chaining. Does not verify that provided address is valid.
72
+ *
73
+ * @public
74
+ * @param {Address} address
75
+ * @returns {this}
76
+ */
77
+ public at(address: Address) {
78
+ this._address = address;
79
+ return this;
80
+ }
81
+
82
+ /**
83
+ * Will set this contract's internal [Wagmi Configuration](https://en.wikipedia.org/wiki/Factorial) and return the instance for chaining.
84
+ *
85
+ * @public
86
+ * @param {Config} config
87
+ * @returns {this}
88
+ */
89
+ public withConfig(config: Config) {
90
+ this._config = config;
91
+ return this;
92
+ }
93
+
94
+ /**
95
+ * Utility function to validate the existence of an address on this Contract.
96
+ *
97
+ * @public
98
+ * @returns {Address}
99
+ * @throws {@link ContractAddressRequiredError} if no address exists on this Contract instance
100
+ */
101
+ public assertValidAddress() {
102
+ const address = this.address;
103
+ if (!address) throw new ContractAddressRequiredError();
104
+ return address;
105
+ }
106
+
107
+ /**
108
+ * A typed wrapper for (viem.getLogs)[https://viem.sh/docs/actions/public/getLogs#getlogs].
109
+ * Accepts `eventName` and `eventNames` as optional parameters to narrow the returned log types.
110
+ * @example
111
+ * ```ts
112
+ * const logs = contract.getLogs({ eventName: 'EventName' })
113
+ * const logs = contract.getLogs({ eventNames: ['EventName'] })
114
+ *
115
+ * @public
116
+ * @async
117
+ * @template {ContractEvent} event
118
+ * @template {ExtractAbiEvent<
119
+ * ContractAbi,
120
+ * event
121
+ * >} [abiEvent=ExtractAbiEvent<ContractAbi, event>]
122
+ * @param {?Omit<
123
+ * GetLogsParams<ContractAbi, event, abiEvent, abiEvent[]>,
124
+ * 'event' | 'events'
125
+ * > & {
126
+ * eventName?: event;
127
+ * eventNames?: event[];
128
+ * }} [params]
129
+ * @returns {Promise<GetLogsReturnType<abiEvent, abiEvent[]>>}
130
+ */
131
+ public async getLogs<
132
+ event extends ContractEventName<ContractAbi>,
133
+ const abiEvent extends ExtractAbiEvent<
134
+ ContractAbi,
135
+ event
136
+ > = ExtractAbiEvent<ContractAbi, event>,
137
+ >(
138
+ params?: Omit<
139
+ GetLogsParams<ContractAbi, event, abiEvent, abiEvent[]>,
140
+ 'event' | 'events'
141
+ > & {
142
+ eventName?: event;
143
+ eventNames?: event[];
144
+ },
145
+ ): Promise<GetLogsReturnType<abiEvent, abiEvent[]>> {
146
+ return getLogs(this._config.getClient({ chainId: params?.chainId }), {
147
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wag
148
+ ...(params as any),
149
+ ...(params?.eventName
150
+ ? {
151
+ event: getAbiItem({
152
+ abi: this.abi,
153
+ name: params.eventName,
154
+ // biome-ignore lint/suspicious/noExplicitAny: awkward abi intersection issue
155
+ } as any),
156
+ }
157
+ : {}),
158
+ ...(params?.eventNames
159
+ ? {
160
+ events: params.eventNames.map((name) =>
161
+ getAbiItem({
162
+ abi: this.abi,
163
+ name,
164
+ // biome-ignore lint/suspicious/noExplicitAny: awkward abi intersection issue
165
+ } as any),
166
+ ),
167
+ }
168
+ : {}),
169
+ address: this.assertValidAddress(),
170
+ });
171
+ }
172
+
173
+ /**
174
+ * A typed wrapper for `wagmi.watchContractEvent`
175
+ *
176
+ * @public
177
+ * @async
178
+ * @template {ContractEvent} event
179
+ * @param {(
180
+ * log: WatchContractEventOnLogsParameter<ContractAbi, event, true>[number],
181
+ * ) => unknown} cb
182
+ * @param {?WatchParams<ContractAbi, event> & {
183
+ * eventName?: event;
184
+ * }} [params]
185
+ * @returns {unknown, params?: any) => unknown}
186
+ */
187
+ public async subscribe<event extends ContractEventName<ContractAbi>>(
188
+ cb: (
189
+ log: WatchContractEventOnLogsParameter<ContractAbi, event, true>[number],
190
+ ) => unknown,
191
+ params?: WatchParams<ContractAbi, event> & {
192
+ eventName?: event;
193
+ },
194
+ ) {
195
+ return watchContractEvent<
196
+ typeof this._config,
197
+ (typeof this._config)['chains'][number]['id'],
198
+ ContractAbi,
199
+ event
200
+ >(this._config, {
201
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
202
+ ...(params as any),
203
+ eventName: params?.eventName,
204
+ abi: this.abi,
205
+ address: this.assertValidAddress(),
206
+ onLogs: (logs) => {
207
+ for (let l of logs) {
208
+ cb(l);
209
+ }
210
+ },
211
+ });
212
+ }
213
+
214
+ /**
215
+ * @see {@link awaitResult}
216
+ * @protected
217
+ * @async
218
+ * @template [Result=unknown]
219
+ * @param {Promise<HashAndSimulatedResult<Result>>} hashPromise
220
+ * @param {?Omit<WaitForTransactionReceiptParameters, 'hash'>} [waitParams]
221
+ * @returns {unknown}
222
+ */
223
+ protected async awaitResult<Result = unknown>(
224
+ hashPromise: Promise<HashAndSimulatedResult<Result>>,
225
+ waitParams?: Omit<WaitForTransactionReceiptParameters, 'hash'>,
226
+ ) {
227
+ return await awaitResult(this._config, hashPromise, waitParams);
228
+ }
229
+ }
@@ -0,0 +1,250 @@
1
+ import { type Config, deployContract } from '@wagmi/core';
2
+ import type {
3
+ Abi,
4
+ Account,
5
+ Address,
6
+ ContractEventName,
7
+ Hash,
8
+ Hex,
9
+ WaitForTransactionReceiptParameters,
10
+ } from 'viem';
11
+ import {
12
+ DeployableAlreadyDeployedError,
13
+ DeployableBuildParametersUnspecifiedError,
14
+ DeployableMissingPayloadError,
15
+ DeployableWagmiConfigurationRequiredError,
16
+ } from '../errors';
17
+ import { getDeployedContractAddress } from '../utils';
18
+ import { Contract } from './Contract';
19
+
20
+ /**
21
+ * A base class representing a deployable contract, contains base implementations for deployment and initialization payload construction.
22
+ *
23
+ * @export
24
+ * @typedef {GenericDeployableParams}
25
+ */
26
+ export type GenericDeployableParams = Omit<
27
+ Parameters<typeof deployContract>[1],
28
+ 'args' | 'account'
29
+ > & {
30
+ args: [Hex, ...Array<Hex>];
31
+ account?: Account;
32
+ };
33
+
34
+ /**
35
+ * A generic type that encapsulates either an initialization payload for a contract, or a valid address for a previously deployed contract.
36
+ *
37
+ * @export
38
+ * @typedef {DeployablePayloadOrAddress}
39
+ * @template [Payload=unknown]
40
+ */
41
+ export type DeployablePayloadOrAddress<Payload = unknown> = Payload | Address;
42
+
43
+ /**
44
+ * Instantion options for the base deployable.
45
+ *
46
+ * @export
47
+ * @interface DeployableOptions
48
+ * @typedef {DeployableOptions}
49
+ */
50
+ export interface DeployableOptions {
51
+ /**
52
+ * [Wagmi Configuration](https://wagmi.sh/core/api/createConfig)
53
+ *
54
+ * @see {@link Config}
55
+ * @type {Config}
56
+ */
57
+ config: Config;
58
+ /**
59
+ * [Viem Local Account](https://viem.sh/docs/accounts/local), required if in a Node environment
60
+ *
61
+ * @see {@link Account}
62
+ * @type {?Account}
63
+ */
64
+ account?: Account;
65
+ }
66
+
67
+ /**
68
+ * A generic deployable contract that encapsulates common operations related to contract deployment
69
+ *
70
+ * @export
71
+ * @class Deployable
72
+ * @typedef {Deployable}
73
+ * @template [Payload=unknown]
74
+ * @template {Abi} [ContractAbi=[]]
75
+ * @template {ContractEventName<ContractAbi>} [ContractEvent=ContractEventName<ContractAbi>]
76
+ * @extends {Contract<ContractAbi, ContractEvent>}
77
+ */
78
+ export class Deployable<
79
+ Payload,
80
+ ContractAbi extends Abi,
81
+ > extends Contract<ContractAbi> {
82
+ /**
83
+ * The deployable payload used either for contract construction or initialization
84
+ *
85
+ * @protected
86
+ * @type {(Payload | undefined)}
87
+ */
88
+ protected _payload: Payload | undefined;
89
+ /**
90
+ * If it exists, [Viem Local Account](https://viem.sh/docs/accounts/local), if in a Node environment
91
+ *
92
+ * @protected
93
+ * @type {?Account}
94
+ */
95
+ protected _account?: Account;
96
+
97
+ /**
98
+ * Creates an instance of Deployable.
99
+ *
100
+ * @constructor
101
+ * @param {DeployableOptions} param0
102
+ * @param {?Account} [param0.account]
103
+ * @param {Config} param0.config
104
+ * @param {DeployablePayloadOrAddress<Payload>} payload
105
+ */
106
+ constructor(
107
+ { account, config }: DeployableOptions,
108
+ payload?: DeployablePayloadOrAddress<Payload>,
109
+ ) {
110
+ if (typeof payload === 'string') {
111
+ super(config, payload as Address);
112
+ } else {
113
+ super(config, undefined);
114
+ this._payload = payload as Payload;
115
+ }
116
+ if (account) this._account = account;
117
+ }
118
+
119
+ /**
120
+ * Returns the attached deployable payload, if it exists
121
+ *
122
+ * @readonly
123
+ * @type {Payload}
124
+ */
125
+ get payload() {
126
+ return this._payload;
127
+ }
128
+
129
+ /**
130
+ * Attaches a new payload for use with this deployable's initialization
131
+ *
132
+ * @public
133
+ * @param {Payload} payload
134
+ * @returns {this}
135
+ */
136
+ public withPayload(payload: Payload) {
137
+ this._payload = payload;
138
+ return this;
139
+ }
140
+
141
+ /**
142
+ * High level deployment function to deploy and await the contract address.
143
+ * This is mainly a convenience method to easily deploy a contract, but will not initialize a `Cloneable`,
144
+ * which makes it useless for Boost components.
145
+ * Obviously you can ignore the TS warnings and use this, but you shouldn't in most all cases.
146
+ *
147
+ * @public
148
+ * @async
149
+ * @param {?Payload} [_payload]
150
+ * @param {?DeployableOptions} [_options]
151
+ * @param {?Omit<WaitForTransactionReceiptParameters, 'hash'>} [waitParams] - See [viem.WaitForTransactionReceipt](https://v1.viem.sh/docs/actions/public/waitForTransactionReceipt.html#waitfortransactionreceipt)
152
+ * @returns {unknown}
153
+ */
154
+ protected async deploy(
155
+ _payload?: Payload,
156
+ _options?: DeployableOptions,
157
+ waitParams?: Omit<WaitForTransactionReceiptParameters, 'hash'>,
158
+ ) {
159
+ const config = _options?.config || this._config;
160
+ const address = await getDeployedContractAddress(
161
+ config,
162
+ this.deployRaw(_payload, _options),
163
+ waitParams,
164
+ );
165
+ this._address = address;
166
+ return this;
167
+ }
168
+
169
+ /**
170
+ * The lower level contract deployment function that does not await for the transaction receipt.
171
+ * This is mainly a convenience method to easily deploy a contract, but will not initialize a `Cloneable`,
172
+ * which makes it useless for Boost components.
173
+ * Obviously you can ignore the TS warnings and use this, but you shouldn't in most all cases.
174
+ *
175
+ * @public
176
+ * @async
177
+ * @param {?Payload} [_payload]
178
+ * @param {?DeployableOptions} [_options]
179
+ * @returns {Promise<Hash>}
180
+ * @throws {@link DeployableAlreadyDeployedError}
181
+ * @throws {@link DeployableWagmiConfigurationRequiredError}
182
+ * @throws {@link DeployableMissingPayloadError}
183
+ */
184
+ protected async deployRaw(
185
+ _payload?: Payload,
186
+ _options?: DeployableOptions,
187
+ ): Promise<Hash> {
188
+ if (this.address) throw new DeployableAlreadyDeployedError(this.address);
189
+ const [payload, options] = this.validateDeploymentConfig(
190
+ _payload,
191
+ _options,
192
+ );
193
+ return await deployContract(options.config, {
194
+ ...this.buildParameters(payload),
195
+ ...this.optionallyAttachAccount(options.account),
196
+ });
197
+ }
198
+
199
+ /**
200
+ * Internal function to attach the connected account to write methods to avoid manually passing in an account each call.
201
+ *
202
+ * @protected
203
+ * @param {?Account} [account]
204
+ * @returns {({ account: Account; } | { account?: undefined; })}
205
+ */
206
+ protected optionallyAttachAccount(account?: Account) {
207
+ if (account) return { account };
208
+ return this._account ? { account: this._account } : {};
209
+ }
210
+
211
+ /**
212
+ * Base parameter constructor, should return a partial `viem.deployContract` parameters shape including abi, bytecode, and arguments, if any.
213
+ * Expected to be overridden by protocol contracts.
214
+ *
215
+ * @public
216
+ * @param {?Payload} [_payload]
217
+ * @param {?DeployableOptions} [_options]
218
+ * @returns {GenericDeployableParams}
219
+ */
220
+ public buildParameters(
221
+ _payload?: Payload,
222
+ _options?: DeployableOptions,
223
+ ): GenericDeployableParams {
224
+ throw new DeployableBuildParametersUnspecifiedError();
225
+ }
226
+
227
+ /**
228
+ * Internal method used to ensure that a Wagmi configuration and payload are always present when deploying.
229
+ *
230
+ * @protected
231
+ * @template [P=Payload]
232
+ * @param {?P} [_payload]
233
+ * @param {?DeployableOptions} [_options]
234
+ * @returns {[P, DeployableOptions]}
235
+ * @throws {@link DeployableWagmiConfigurationRequiredError}
236
+ * @throws {@link DeployableMissingPayloadError}
237
+ */
238
+ protected validateDeploymentConfig<P = Payload>(
239
+ _payload?: P,
240
+ _options?: DeployableOptions,
241
+ ) {
242
+ const options = _options || {
243
+ config: this._config,
244
+ account: this._account,
245
+ };
246
+ if (!options) throw new DeployableWagmiConfigurationRequiredError();
247
+ const payload = _payload || this._payload;
248
+ return [payload, options] as [P, DeployableOptions];
249
+ }
250
+ }
@@ -0,0 +1,223 @@
1
+ import {
2
+ type aCloneableAbi,
3
+ readACloneableGetComponentInterface as readACloneableGetComponentInterface,
4
+ readACloneableSupportsInterface,
5
+ } from '@boostxyz/evm';
6
+ import { deployContract } from '@wagmi/core';
7
+ import {
8
+ type Abi,
9
+ type Address,
10
+ type Hash,
11
+ type Hex,
12
+ type WaitForTransactionReceiptParameters,
13
+ isAddress,
14
+ zeroAddress,
15
+ } from 'viem';
16
+ import {
17
+ DeployableAlreadyDeployedError,
18
+ DeployableMissingPayloadError,
19
+ } from '../errors';
20
+ import { type ReadParams, RegistryType } from '../utils';
21
+ import {
22
+ Deployable,
23
+ type DeployableOptions,
24
+ type DeployablePayloadOrAddress,
25
+ } from './Deployable';
26
+
27
+ /**
28
+ * A base class representing a generic base Boost Protocol target contract, extended by Actions, AllowLists, Budgets, Incentives, and Validators.
29
+ *
30
+ * @export
31
+ * @class DeployableTarget
32
+ * @typedef {DeployableTarget}
33
+ * @template [Payload=unknown]
34
+ * @extends {Deployable<Payload>}
35
+ */
36
+ export class DeployableTarget<
37
+ Payload,
38
+ ContractAbi extends Abi,
39
+ > extends Deployable<Payload, ContractAbi> {
40
+ /**
41
+ * A static property representing the address of the base implementation on chain, used when cloning base contracts.
42
+ *
43
+ * @static
44
+ * @readonly
45
+ * @type {Address}
46
+ */
47
+ static readonly base: Address = zeroAddress;
48
+ /**
49
+ * The target's registry type.
50
+ *
51
+ * @static
52
+ * @readonly
53
+ * @type {RegistryType}
54
+ */
55
+ static readonly registryType: RegistryType = RegistryType.ACTION;
56
+ /**
57
+ * A property asserting that the protocol should eiher clone and initialize a new target from the base implementation, or re-use an existing contract without initializing.
58
+ *
59
+ * @readonly
60
+ * @type {boolean}
61
+ */
62
+ protected _isBase = true;
63
+ get isBase() {
64
+ if (!!this.address && this.address !== this.base) return false;
65
+ return this._isBase;
66
+ }
67
+
68
+ /**
69
+ * Creates an instance of DeployableTarget.
70
+ *
71
+ * @constructor
72
+ * @param {DeployableOptions} options
73
+ * @param {DeployablePayloadOrAddress<Payload>} payload - Either a given implementation's initialization payload, or an address to an existing on chain target.
74
+ * @param {?boolean} [isBase] - A property asserting that the protocol should eiher clone and initialize a new target from the base implementation, or re-use an existing contract without initializing.
75
+ */
76
+ constructor(
77
+ options: DeployableOptions,
78
+ payload: DeployablePayloadOrAddress<Payload>,
79
+ isBase?: boolean,
80
+ ) {
81
+ super(options, payload);
82
+ // if supplying a custom address, safe enough to assume it is not a base address which makes reusing contracts like budgets easier
83
+ if (
84
+ typeof payload === 'string' &&
85
+ isAddress(payload) &&
86
+ payload !== this.base &&
87
+ payload !== zeroAddress
88
+ )
89
+ isBase = false;
90
+ if (isBase !== undefined) this._isBase = isBase;
91
+ }
92
+
93
+ /**
94
+ * A getter that will return the base implementation's static address
95
+ *
96
+ * @public
97
+ * @readonly
98
+ * @type {Address}
99
+ */
100
+ public get base(): Address {
101
+ return (this.constructor as typeof DeployableTarget).base;
102
+ }
103
+
104
+ /**
105
+ * A getter that returns the registry type of the base implementation
106
+ *
107
+ * @public
108
+ * @readonly
109
+ * @type {RegistryType}
110
+ */
111
+ public get registryType(): RegistryType {
112
+ return (this.constructor as typeof DeployableTarget).registryType;
113
+ }
114
+
115
+ /**
116
+ * @inheritdoc
117
+ *
118
+ * @public
119
+ * @async
120
+ * @param {?Payload} [payload]
121
+ * @param {?DeployableOptions} [options]
122
+ * @param {?Omit<WaitForTransactionReceiptParameters, 'hash'>} [waitParams]
123
+ * @returns {unknown}
124
+ */
125
+ protected override async deploy(
126
+ payload?: Payload,
127
+ options?: DeployableOptions,
128
+ waitParams?: Omit<WaitForTransactionReceiptParameters, 'hash'>,
129
+ ) {
130
+ await super.deploy(payload, options, waitParams);
131
+ this.assertValidAddress();
132
+ return this;
133
+ }
134
+
135
+ /**
136
+ * @inheritdoc
137
+ *
138
+ * @public
139
+ * @async
140
+ * @param {?Payload} [_payload]
141
+ * @param {?DeployableOptions} [_options]
142
+ * @returns {Promise<Hash>}
143
+ */
144
+ protected override async deployRaw(
145
+ _payload?: Payload,
146
+ _options?: DeployableOptions,
147
+ ): Promise<Hash> {
148
+ if (this.address) throw new DeployableAlreadyDeployedError(this.address);
149
+ const payload = _payload || this._payload;
150
+ const config = _options?.config || this._config;
151
+ const { args, ...deployment } = this.buildParameters(payload);
152
+ return await deployContract(config, {
153
+ ...deployment,
154
+ ...this.optionallyAttachAccount(_options?.account),
155
+ // Deployable targets don't construct with arguments, they initialize with encoded payloads
156
+ args: [],
157
+ });
158
+ }
159
+
160
+ /**
161
+ * Check if the contract supports the given interface
162
+ *
163
+ * @public
164
+ * @async
165
+ * @param {Hex} interfaceId - The interface identifier
166
+ * @param {?ReadParams<typeof contractActionAbi, 'supportsInterface'>} [params]
167
+ * @returns {unknown} - True if the contract supports the interface
168
+ */
169
+ public async supportsInterface(
170
+ interfaceId: Hex,
171
+ params?: ReadParams<typeof aCloneableAbi, 'supportsInterface'>,
172
+ ) {
173
+ return await readACloneableSupportsInterface(this._config, {
174
+ address: this.assertValidAddress(),
175
+ ...this.optionallyAttachAccount(),
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
+ args: [interfaceId],
179
+ });
180
+ }
181
+
182
+ /**
183
+ * Return a cloneable's unique identifier for downstream consumers to differentiate various targets
184
+ * All implementations must override this function
185
+ *
186
+ * @public
187
+ * @async
188
+ * @param {?ReadParams<typeof contractActionAbi, 'getComponentInterface'>} [params]
189
+ * @returns {unknown}
190
+ */
191
+ public async getComponentInterface(
192
+ params?: ReadParams<typeof aCloneableAbi, 'getComponentInterface'>,
193
+ ) {
194
+ return await readACloneableGetComponentInterface(this._config, {
195
+ address: this.assertValidAddress(),
196
+ ...this.optionallyAttachAccount(),
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
+ args: [],
200
+ });
201
+ }
202
+
203
+ /**
204
+ * @inheritdoc
205
+ *
206
+ * @protected
207
+ * @template [P=Payload]
208
+ * @param {?P} [_payload]
209
+ * @param {?DeployableOptions} [_options]
210
+ * @returns {[P, DeployableOptions]}
211
+ */
212
+ protected override validateDeploymentConfig<P = Payload>(
213
+ _payload?: P,
214
+ _options?: DeployableOptions,
215
+ ) {
216
+ const payload = _payload || this._payload;
217
+ if (!payload) throw new DeployableMissingPayloadError();
218
+ return super.validateDeploymentConfig(payload, _options) as [
219
+ P,
220
+ DeployableOptions,
221
+ ];
222
+ }
223
+ }