@boostxyz/sdk 0.0.0-alpha.3 → 0.0.0-alpha.6

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 (176) 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 +15 -13
  6. package/dist/Actions/Action.js.map +1 -0
  7. package/dist/Actions/EventAction.cjs +1 -0
  8. package/dist/Actions/EventAction.cjs.map +1 -0
  9. package/dist/Actions/EventAction.js +1 -0
  10. package/dist/Actions/EventAction.js.map +1 -0
  11. package/dist/AllowLists/AllowList.cjs +2 -1
  12. package/dist/AllowLists/AllowList.cjs.map +1 -0
  13. package/dist/AllowLists/AllowList.d.ts +1 -2
  14. package/dist/AllowLists/AllowList.d.ts.map +1 -1
  15. package/dist/AllowLists/AllowList.js +16 -14
  16. package/dist/AllowLists/AllowList.js.map +1 -0
  17. package/dist/AllowLists/SimpleAllowList.cjs +1 -0
  18. package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
  19. package/dist/AllowLists/SimpleAllowList.js +1 -0
  20. package/dist/AllowLists/SimpleAllowList.js.map +1 -0
  21. package/dist/AllowLists/SimpleDenyList.cjs +1 -0
  22. package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
  23. package/dist/AllowLists/SimpleDenyList.js +1 -0
  24. package/dist/AllowLists/SimpleDenyList.js.map +1 -0
  25. package/dist/Auth/Auth.cjs +1 -0
  26. package/dist/Auth/Auth.cjs.map +1 -0
  27. package/dist/Auth/Auth.js +1 -0
  28. package/dist/Auth/Auth.js.map +1 -0
  29. package/dist/Auth/PassthroughAuth.cjs +1 -0
  30. package/dist/Auth/PassthroughAuth.cjs.map +1 -0
  31. package/dist/Auth/PassthroughAuth.js +1 -0
  32. package/dist/Auth/PassthroughAuth.js.map +1 -0
  33. package/dist/Boost.cjs +1 -0
  34. package/dist/Boost.cjs.map +1 -0
  35. package/dist/Boost.js +1 -0
  36. package/dist/Boost.js.map +1 -0
  37. package/dist/BoostCore.cjs +1 -0
  38. package/dist/BoostCore.cjs.map +1 -0
  39. package/dist/BoostCore.js +1 -0
  40. package/dist/BoostCore.js.map +1 -0
  41. package/dist/BoostRegistry.cjs +1 -0
  42. package/dist/BoostRegistry.cjs.map +1 -0
  43. package/dist/BoostRegistry.js +1 -0
  44. package/dist/BoostRegistry.js.map +1 -0
  45. package/dist/Budgets/Budget.cjs +2 -1
  46. package/dist/Budgets/Budget.cjs.map +1 -0
  47. package/dist/Budgets/Budget.d.ts +1 -1
  48. package/dist/Budgets/Budget.d.ts.map +1 -1
  49. package/dist/Budgets/Budget.js +14 -12
  50. package/dist/Budgets/Budget.js.map +1 -0
  51. package/dist/Budgets/ManagedBudget.cjs +1 -0
  52. package/dist/Budgets/ManagedBudget.cjs.map +1 -0
  53. package/dist/Budgets/ManagedBudget.js +1 -0
  54. package/dist/Budgets/ManagedBudget.js.map +1 -0
  55. package/dist/Deployable/Contract.cjs +1 -0
  56. package/dist/Deployable/Contract.cjs.map +1 -0
  57. package/dist/Deployable/Contract.js +1 -0
  58. package/dist/Deployable/Contract.js.map +1 -0
  59. package/dist/Deployable/Deployable.cjs +1 -0
  60. package/dist/Deployable/Deployable.cjs.map +1 -0
  61. package/dist/Deployable/Deployable.js +1 -0
  62. package/dist/Deployable/Deployable.js.map +1 -0
  63. package/dist/Deployable/DeployableTarget.cjs +1 -0
  64. package/dist/Deployable/DeployableTarget.cjs.map +1 -0
  65. package/dist/Deployable/DeployableTarget.js +1 -0
  66. package/dist/Deployable/DeployableTarget.js.map +1 -0
  67. package/dist/Incentives/AllowListIncentive.cjs +1 -0
  68. package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
  69. package/dist/Incentives/AllowListIncentive.js +1 -0
  70. package/dist/Incentives/AllowListIncentive.js.map +1 -0
  71. package/dist/Incentives/CGDAIncentive.cjs +1 -0
  72. package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
  73. package/dist/Incentives/CGDAIncentive.js +1 -0
  74. package/dist/Incentives/CGDAIncentive.js.map +1 -0
  75. package/dist/Incentives/ERC20Incentive.cjs +1 -0
  76. package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
  77. package/dist/Incentives/ERC20Incentive.js +1 -0
  78. package/dist/Incentives/ERC20Incentive.js.map +1 -0
  79. package/dist/Incentives/Incentive.cjs +2 -1
  80. package/dist/Incentives/Incentive.cjs.map +1 -0
  81. package/dist/Incentives/Incentive.d.ts +1 -4
  82. package/dist/Incentives/Incentive.d.ts.map +1 -1
  83. package/dist/Incentives/Incentive.js +39 -36
  84. package/dist/Incentives/Incentive.js.map +1 -0
  85. package/dist/Incentives/PointsIncentive.cjs +1 -0
  86. package/dist/Incentives/PointsIncentive.cjs.map +1 -0
  87. package/dist/Incentives/PointsIncentive.js +1 -0
  88. package/dist/Incentives/PointsIncentive.js.map +1 -0
  89. package/dist/Validators/SignerValidator.cjs +1 -0
  90. package/dist/Validators/SignerValidator.cjs.map +1 -0
  91. package/dist/Validators/SignerValidator.js +1 -0
  92. package/dist/Validators/SignerValidator.js.map +1 -0
  93. package/dist/Validators/Validator.cjs +2 -1
  94. package/dist/Validators/Validator.cjs.map +1 -0
  95. package/dist/Validators/Validator.d.ts +1 -1
  96. package/dist/Validators/Validator.d.ts.map +1 -1
  97. package/dist/Validators/Validator.js +9 -7
  98. package/dist/Validators/Validator.js.map +1 -0
  99. package/dist/componentInterfaces-CKCBwG16.cjs +2 -0
  100. package/dist/componentInterfaces-CKCBwG16.cjs.map +1 -0
  101. package/dist/componentInterfaces-DYkaxBda.js +13 -0
  102. package/dist/componentInterfaces-DYkaxBda.js.map +1 -0
  103. package/dist/errors.cjs +1 -0
  104. package/dist/errors.cjs.map +1 -0
  105. package/dist/errors.js +1 -0
  106. package/dist/errors.js.map +1 -0
  107. package/dist/generated-Cd-Fe7W7.cjs +1 -0
  108. package/dist/generated-Cd-Fe7W7.cjs.map +1 -0
  109. package/dist/generated-DGpIVcv5.js +1 -0
  110. package/dist/generated-DGpIVcv5.js.map +1 -0
  111. package/dist/index.cjs +1 -0
  112. package/dist/index.cjs.map +1 -0
  113. package/dist/index.js +1 -0
  114. package/dist/index.js.map +1 -0
  115. package/dist/utils.cjs +1 -0
  116. package/dist/utils.cjs.map +1 -0
  117. package/dist/utils.d.ts +1 -1
  118. package/dist/utils.d.ts.map +1 -1
  119. package/dist/utils.js +1 -0
  120. package/dist/utils.js.map +1 -0
  121. package/package.json +5 -3
  122. package/src/Actions/Action.test.ts +77 -0
  123. package/src/Actions/Action.ts +61 -0
  124. package/src/Actions/ContractAction.test.ts +199 -0
  125. package/src/Actions/ContractAction.ts +238 -0
  126. package/src/Actions/ERC721MintAction.test.ts +112 -0
  127. package/src/Actions/ERC721MintAction.ts +238 -0
  128. package/src/Actions/EventAction.test.ts +182 -0
  129. package/src/Actions/EventAction.ts +382 -0
  130. package/src/AllowLists/AllowList.test.ts +64 -0
  131. package/src/AllowLists/AllowList.ts +60 -0
  132. package/src/AllowLists/SimpleAllowList.test.ts +52 -0
  133. package/src/AllowLists/SimpleAllowList.ts +240 -0
  134. package/src/AllowLists/SimpleDenyList.test.ts +52 -0
  135. package/src/AllowLists/SimpleDenyList.ts +289 -0
  136. package/src/Auth/Auth.ts +11 -0
  137. package/src/Auth/PassthroughAuth.test.ts +12 -0
  138. package/src/Auth/PassthroughAuth.ts +80 -0
  139. package/src/Boost.ts +155 -0
  140. package/src/BoostCore.test.ts +846 -0
  141. package/src/BoostCore.ts +1192 -0
  142. package/src/BoostRegistry.ts +449 -0
  143. package/src/Budgets/Budget.test.ts +27 -0
  144. package/src/Budgets/Budget.ts +61 -0
  145. package/src/Budgets/ManagedBudget.test.ts +154 -0
  146. package/src/Budgets/ManagedBudget.ts +743 -0
  147. package/src/Budgets/SimpleBudget.test.ts +152 -0
  148. package/src/Budgets/SimpleBudget.ts +521 -0
  149. package/src/Budgets/VestingBudget.test.ts +123 -0
  150. package/src/Budgets/VestingBudget.ts +532 -0
  151. package/src/Deployable/Contract.ts +229 -0
  152. package/src/Deployable/Deployable.ts +244 -0
  153. package/src/Deployable/DeployableTarget.ts +210 -0
  154. package/src/Incentives/AllowListIncentive.test.ts +146 -0
  155. package/src/Incentives/AllowListIncentive.ts +290 -0
  156. package/src/Incentives/CGDAIncentive.test.ts +136 -0
  157. package/src/Incentives/CGDAIncentive.ts +364 -0
  158. package/src/Incentives/ERC1155Incentive.test.ts +98 -0
  159. package/src/Incentives/ERC1155Incentive.ts +384 -0
  160. package/src/Incentives/ERC20Incentive.test.ts +141 -0
  161. package/src/Incentives/ERC20Incentive.ts +417 -0
  162. package/src/Incentives/ERC20VariableIncentive.test.ts +156 -0
  163. package/src/Incentives/ERC20VariableIncentive.ts +368 -0
  164. package/src/Incentives/Incentive.test.ts +92 -0
  165. package/src/Incentives/Incentive.ts +85 -0
  166. package/src/Incentives/PointsIncentive.test.ts +142 -0
  167. package/src/Incentives/PointsIncentive.ts +303 -0
  168. package/src/Validators/SignerValidator.test.ts +163 -0
  169. package/src/Validators/SignerValidator.ts +272 -0
  170. package/src/Validators/Validator.test.ts +21 -0
  171. package/src/Validators/Validator.ts +55 -0
  172. package/src/errors.ts +524 -0
  173. package/src/index.test.ts +40 -0
  174. package/src/index.ts +50 -0
  175. package/src/utils.test.ts +44 -0
  176. package/src/utils.ts +2247 -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 awaitResult(this._config, hashPromise, waitParams);
228
+ }
229
+ }
@@ -0,0 +1,244 @@
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
+ *
144
+ * @public
145
+ * @async
146
+ * @param {?Payload} [_payload]
147
+ * @param {?DeployableOptions} [_options]
148
+ * @param {?Omit<WaitForTransactionReceiptParameters, 'hash'>} [waitParams] - See [viem.WaitForTransactionReceipt](https://v1.viem.sh/docs/actions/public/waitForTransactionReceipt.html#waitfortransactionreceipt)
149
+ * @returns {unknown}
150
+ */
151
+ public async deploy(
152
+ _payload?: Payload,
153
+ _options?: DeployableOptions,
154
+ waitParams?: Omit<WaitForTransactionReceiptParameters, 'hash'>,
155
+ ) {
156
+ const config = _options?.config || this._config;
157
+ const address = await getDeployedContractAddress(
158
+ config,
159
+ this.deployRaw(_payload, _options),
160
+ waitParams,
161
+ );
162
+ this._address = address;
163
+ return this;
164
+ }
165
+
166
+ /**
167
+ * The lower level contract deployment function that does not await for the transaction receipt.
168
+ *
169
+ * @public
170
+ * @async
171
+ * @param {?Payload} [_payload]
172
+ * @param {?DeployableOptions} [_options]
173
+ * @returns {Promise<Hash>}
174
+ * @throws {@link DeployableAlreadyDeployedError}
175
+ * @throws {@link DeployableWagmiConfigurationRequiredError}
176
+ * @throws {@link DeployableMissingPayloadError}
177
+ */
178
+ public async deployRaw(
179
+ _payload?: Payload,
180
+ _options?: DeployableOptions,
181
+ ): Promise<Hash> {
182
+ if (this.address) throw new DeployableAlreadyDeployedError(this.address);
183
+ const [payload, options] = this.validateDeploymentConfig(
184
+ _payload,
185
+ _options,
186
+ );
187
+ return await deployContract(options.config, {
188
+ ...this.buildParameters(payload),
189
+ ...this.optionallyAttachAccount(options.account),
190
+ });
191
+ }
192
+
193
+ /**
194
+ * Internal function to attach the connected account to write methods to avoid manually passing in an account each call.
195
+ *
196
+ * @protected
197
+ * @param {?Account} [account]
198
+ * @returns {({ account: Account; } | { account?: undefined; })}
199
+ */
200
+ protected optionallyAttachAccount(account?: Account) {
201
+ if (account) return { account };
202
+ return this._account ? { account: this._account } : {};
203
+ }
204
+
205
+ /**
206
+ * Base parameter constructor, should return a partial `viem.deployContract` parameters shape including abi, bytecode, and arguments, if any.
207
+ * Expected to be overridden by protocol contracts.
208
+ *
209
+ * @public
210
+ * @param {?Payload} [_payload]
211
+ * @param {?DeployableOptions} [_options]
212
+ * @returns {GenericDeployableParams}
213
+ */
214
+ public buildParameters(
215
+ _payload?: Payload,
216
+ _options?: DeployableOptions,
217
+ ): GenericDeployableParams {
218
+ throw new DeployableBuildParametersUnspecifiedError();
219
+ }
220
+
221
+ /**
222
+ * Internal method used to ensure that a Wagmi configuration and payload are always present when deploying.
223
+ *
224
+ * @protected
225
+ * @template [P=Payload]
226
+ * @param {?P} [_payload]
227
+ * @param {?DeployableOptions} [_options]
228
+ * @returns {[P, DeployableOptions]}
229
+ * @throws {@link DeployableWagmiConfigurationRequiredError}
230
+ * @throws {@link DeployableMissingPayloadError}
231
+ */
232
+ protected validateDeploymentConfig<P = Payload>(
233
+ _payload?: P,
234
+ _options?: DeployableOptions,
235
+ ) {
236
+ const options = _options || {
237
+ config: this._config,
238
+ account: this._account,
239
+ };
240
+ if (!options) throw new DeployableWagmiConfigurationRequiredError();
241
+ const payload = _payload || this._payload;
242
+ return [payload, options] as [P, DeployableOptions];
243
+ }
244
+ }
@@ -0,0 +1,210 @@
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
+ zeroAddress,
14
+ } from 'viem';
15
+ import {
16
+ DeployableAlreadyDeployedError,
17
+ DeployableMissingPayloadError,
18
+ } from '../errors';
19
+ import { type ReadParams, RegistryType } from '../utils';
20
+ import {
21
+ Deployable,
22
+ type DeployableOptions,
23
+ type DeployablePayloadOrAddress,
24
+ } from './Deployable';
25
+
26
+ /**
27
+ * A base class representing a generic base Boost Protocol target contract, extended by Actions, AllowLists, Budgets, Incentives, and Validators.
28
+ *
29
+ * @export
30
+ * @class DeployableTarget
31
+ * @typedef {DeployableTarget}
32
+ * @template [Payload=unknown]
33
+ * @extends {Deployable<Payload>}
34
+ */
35
+ export class DeployableTarget<
36
+ Payload,
37
+ ContractAbi extends Abi,
38
+ > extends Deployable<Payload, ContractAbi> {
39
+ /**
40
+ * A static property representing the address of the base implementation on chain, used when cloning base contracts.
41
+ *
42
+ * @static
43
+ * @readonly
44
+ * @type {Address}
45
+ */
46
+ static readonly base: Address = zeroAddress;
47
+ /**
48
+ * The target's registry type.
49
+ *
50
+ * @static
51
+ * @readonly
52
+ * @type {RegistryType}
53
+ */
54
+ static readonly registryType: RegistryType = RegistryType.ACTION;
55
+ /**
56
+ * 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.
57
+ *
58
+ * @readonly
59
+ * @type {boolean}
60
+ */
61
+ readonly isBase: boolean = true;
62
+
63
+ /**
64
+ * Creates an instance of DeployableTarget.
65
+ *
66
+ * @constructor
67
+ * @param {DeployableOptions} options
68
+ * @param {DeployablePayloadOrAddress<Payload>} payload - Either a given implementation's initialization payload, or an address to an existing on chain target.
69
+ * @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.
70
+ */
71
+ constructor(
72
+ options: DeployableOptions,
73
+ payload: DeployablePayloadOrAddress<Payload>,
74
+ isBase?: boolean,
75
+ ) {
76
+ super(options, payload);
77
+ if (isBase !== undefined) this.isBase = isBase;
78
+ }
79
+
80
+ /**
81
+ * A getter that will return the base implementation's static address
82
+ *
83
+ * @public
84
+ * @readonly
85
+ * @type {Address}
86
+ */
87
+ public get base(): Address {
88
+ return (this.constructor as typeof DeployableTarget).base;
89
+ }
90
+
91
+ /**
92
+ * A getter that returns the registry type of the base implementation
93
+ *
94
+ * @public
95
+ * @readonly
96
+ * @type {RegistryType}
97
+ */
98
+ public get registryType(): RegistryType {
99
+ return (this.constructor as typeof DeployableTarget).registryType;
100
+ }
101
+
102
+ /**
103
+ * @inheritdoc
104
+ *
105
+ * @public
106
+ * @async
107
+ * @param {?Payload} [payload]
108
+ * @param {?DeployableOptions} [options]
109
+ * @param {?Omit<WaitForTransactionReceiptParameters, 'hash'>} [waitParams]
110
+ * @returns {unknown}
111
+ */
112
+ public override async deploy(
113
+ payload?: Payload,
114
+ options?: DeployableOptions,
115
+ waitParams?: Omit<WaitForTransactionReceiptParameters, 'hash'>,
116
+ ) {
117
+ await super.deploy(payload, options, waitParams);
118
+ this.assertValidAddress();
119
+ return this;
120
+ }
121
+
122
+ /**
123
+ * @inheritdoc
124
+ *
125
+ * @public
126
+ * @async
127
+ * @param {?Payload} [_payload]
128
+ * @param {?DeployableOptions} [_options]
129
+ * @returns {Promise<Hash>}
130
+ */
131
+ public override async deployRaw(
132
+ _payload?: Payload,
133
+ _options?: DeployableOptions,
134
+ ): Promise<Hash> {
135
+ if (this.address) throw new DeployableAlreadyDeployedError(this.address);
136
+ const payload = _payload || this._payload;
137
+ const config = _options?.config || this._config;
138
+ const { args, ...deployment } = this.buildParameters(payload);
139
+ return await deployContract(config, {
140
+ ...deployment,
141
+ ...this.optionallyAttachAccount(_options?.account),
142
+ // Deployable targets don't construct with arguments, they initialize with encoded payloads
143
+ args: [],
144
+ });
145
+ }
146
+
147
+ /**
148
+ * Check if the contract supports the given interface
149
+ *
150
+ * @public
151
+ * @async
152
+ * @param {Hex} interfaceId - The interface identifier
153
+ * @param {?ReadParams<typeof contractActionAbi, 'supportsInterface'>} [params]
154
+ * @returns {unknown} - True if the contract supports the interface
155
+ */
156
+ public async supportsInterface(
157
+ interfaceId: Hex,
158
+ params?: ReadParams<typeof aCloneableAbi, 'supportsInterface'>,
159
+ ) {
160
+ return readACloneableSupportsInterface(this._config, {
161
+ address: this.assertValidAddress(),
162
+ ...this.optionallyAttachAccount(),
163
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
164
+ ...(params as any),
165
+ args: [interfaceId],
166
+ });
167
+ }
168
+
169
+ /**
170
+ * Return a cloneable's unique identifier for downstream consumers to differentiate various targets
171
+ * All implementations must override this function
172
+ *
173
+ * @public
174
+ * @async
175
+ * @param {?ReadParams<typeof contractActionAbi, 'getComponentInterface'>} [params]
176
+ * @returns {unknown}
177
+ */
178
+ public async getComponentInterface(
179
+ params?: ReadParams<typeof aCloneableAbi, 'getComponentInterface'>,
180
+ ) {
181
+ return readACloneableGetComponentInterface(this._config, {
182
+ address: this.assertValidAddress(),
183
+ ...this.optionallyAttachAccount(),
184
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
185
+ ...(params as any),
186
+ args: [],
187
+ });
188
+ }
189
+
190
+ /**
191
+ * @inheritdoc
192
+ *
193
+ * @protected
194
+ * @template [P=Payload]
195
+ * @param {?P} [_payload]
196
+ * @param {?DeployableOptions} [_options]
197
+ * @returns {[P, DeployableOptions]}
198
+ */
199
+ protected override validateDeploymentConfig<P = Payload>(
200
+ _payload?: P,
201
+ _options?: DeployableOptions,
202
+ ) {
203
+ const payload = _payload || this._payload;
204
+ if (!payload) throw new DeployableMissingPayloadError();
205
+ return super.validateDeploymentConfig(payload, _options) as [
206
+ P,
207
+ DeployableOptions,
208
+ ];
209
+ }
210
+ }