@gitmyabi-stg/crclon 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,251 @@
1
+ import type { Abi, Address, PublicClient, WalletClient, GetContractReturnType } from 'viem';
2
+ import { getContract } from 'viem';
3
+
4
+ /**
5
+ * BeaconProxy ABI
6
+ *
7
+ * This ABI is typed using viem's type system for full type safety.
8
+ */
9
+ export const BeaconProxyAbi = [
10
+ {
11
+ "inputs": [
12
+ {
13
+ "internalType": "address",
14
+ "name": "beacon",
15
+ "type": "address"
16
+ },
17
+ {
18
+ "internalType": "bytes",
19
+ "name": "data",
20
+ "type": "bytes"
21
+ }
22
+ ],
23
+ "stateMutability": "payable",
24
+ "type": "constructor"
25
+ },
26
+ {
27
+ "anonymous": false,
28
+ "inputs": [
29
+ {
30
+ "indexed": false,
31
+ "internalType": "address",
32
+ "name": "previousAdmin",
33
+ "type": "address"
34
+ },
35
+ {
36
+ "indexed": false,
37
+ "internalType": "address",
38
+ "name": "newAdmin",
39
+ "type": "address"
40
+ }
41
+ ],
42
+ "name": "AdminChanged",
43
+ "type": "event"
44
+ },
45
+ {
46
+ "anonymous": false,
47
+ "inputs": [
48
+ {
49
+ "indexed": true,
50
+ "internalType": "address",
51
+ "name": "beacon",
52
+ "type": "address"
53
+ }
54
+ ],
55
+ "name": "BeaconUpgraded",
56
+ "type": "event"
57
+ },
58
+ {
59
+ "anonymous": false,
60
+ "inputs": [
61
+ {
62
+ "indexed": true,
63
+ "internalType": "address",
64
+ "name": "implementation",
65
+ "type": "address"
66
+ }
67
+ ],
68
+ "name": "Upgraded",
69
+ "type": "event"
70
+ },
71
+ {
72
+ "stateMutability": "payable",
73
+ "type": "fallback"
74
+ },
75
+ {
76
+ "stateMutability": "payable",
77
+ "type": "receive"
78
+ }
79
+ ] as const satisfies Abi;
80
+
81
+ /**
82
+ * Type-safe ABI for BeaconProxy
83
+ */
84
+ export type BeaconProxyAbi = typeof BeaconProxyAbi;
85
+
86
+ /**
87
+ * Contract instance type for BeaconProxy
88
+ */
89
+ // Use any for contract type to avoid complex viem type issues
90
+ // The runtime behavior is type-safe through viem's ABI typing
91
+ export type BeaconProxyContract = any;
92
+
93
+ /**
94
+ * BeaconProxy Contract Class
95
+ *
96
+ * Provides a class-based API similar to TypeChain for interacting with the contract.
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * import { createPublicClient, createWalletClient, http } from 'viem';
101
+ * import { mainnet } from 'viem/chains';
102
+ * import { BeaconProxy } from 'BeaconProxy';
103
+ *
104
+ * const publicClient = createPublicClient({ chain: mainnet, transport: http() });
105
+ * const walletClient = createWalletClient({ chain: mainnet, transport: http() });
106
+ *
107
+ * const contract = new BeaconProxy('0x...', { publicClient, walletClient });
108
+ *
109
+ * // Read functions
110
+ * const result = await contract.balanceOf('0x...');
111
+ *
112
+ * // Write functions
113
+ * const hash = await contract.transfer('0x...', 1000n);
114
+ *
115
+ * // Simulate transactions (dry-run)
116
+ * const simulation = await contract.simulate.transfer('0x...', 1000n);
117
+ * console.log('Gas estimate:', simulation.request.gas);
118
+ *
119
+ * // Watch events
120
+ * const unwatch = contract.watch.Transfer((event) => {
121
+ * console.log('Transfer event:', event);
122
+ * });
123
+ * ```
124
+ */
125
+ export class BeaconProxy {
126
+ private contract: BeaconProxyContract;
127
+ private contractAddress: Address;
128
+ private publicClient: PublicClient;
129
+
130
+ constructor(
131
+ address: Address,
132
+ clients: {
133
+ publicClient: PublicClient;
134
+ walletClient?: WalletClient;
135
+ }
136
+ ) {
137
+ this.contractAddress = address;
138
+ this.publicClient = clients.publicClient;
139
+ this.contract = getContract({
140
+ address,
141
+ abi: BeaconProxyAbi,
142
+ client: {
143
+ public: clients.publicClient,
144
+ wallet: clients.walletClient,
145
+ },
146
+ });
147
+ }
148
+
149
+ /**
150
+ * Get the contract address
151
+ */
152
+ get address(): Address {
153
+ return this.contractAddress;
154
+ }
155
+
156
+ /**
157
+ * Get the underlying viem contract instance.
158
+ */
159
+ getContract(): BeaconProxyContract {
160
+ return this.contract;
161
+ }
162
+
163
+ // No read functions
164
+
165
+ // No write functions
166
+
167
+
168
+
169
+ /**
170
+ * Simulate contract write operations (dry-run without sending transaction)
171
+ *
172
+ * Note: This contract has no write functions, so simulate returns an empty object.
173
+ */
174
+ get simulate() {
175
+ return {};
176
+ }
177
+
178
+ /**
179
+ * Watch contract events
180
+ *
181
+ * @example
182
+ * // Watch all Transfer events
183
+ * const unwatch = contract.watch.Transfer((event) => {
184
+ * console.log('Transfer:', event);
185
+ * });
186
+ *
187
+ * // Stop watching
188
+ * unwatch();
189
+ */
190
+ get watch() {
191
+ return {
192
+ /**
193
+ * Watch AdminChanged events
194
+ * @param callback Function to call when event is emitted
195
+ * @param filter Optional filter for indexed parameters
196
+ * @returns Unwatch function to stop listening
197
+ */
198
+ AdminChanged: (callback: (event: { previousAdmin: `0x${string}`; newAdmin: `0x${string}` }) => void) => {
199
+ return this.publicClient.watchContractEvent({
200
+ address: this.contractAddress,
201
+ abi: BeaconProxyAbi,
202
+ eventName: 'AdminChanged',
203
+
204
+ onLogs: (logs: any[]) => {
205
+ logs.forEach((log: any) => {
206
+ callback(log.args as any);
207
+ });
208
+ },
209
+ }) as () => void;
210
+ },
211
+ /**
212
+ * Watch BeaconUpgraded events
213
+ * @param callback Function to call when event is emitted
214
+ * @param filter Optional filter for indexed parameters
215
+ * @returns Unwatch function to stop listening
216
+ */
217
+ BeaconUpgraded: (callback: (event: { beacon: `0x${string}` }) => void, filter?: { beacon?: `0x${string}` | `0x${string}`[] | null }) => {
218
+ return this.publicClient.watchContractEvent({
219
+ address: this.contractAddress,
220
+ abi: BeaconProxyAbi,
221
+ eventName: 'BeaconUpgraded',
222
+ args: filter as any,
223
+ onLogs: (logs: any[]) => {
224
+ logs.forEach((log: any) => {
225
+ callback(log.args as any);
226
+ });
227
+ },
228
+ }) as () => void;
229
+ },
230
+ /**
231
+ * Watch Upgraded events
232
+ * @param callback Function to call when event is emitted
233
+ * @param filter Optional filter for indexed parameters
234
+ * @returns Unwatch function to stop listening
235
+ */
236
+ Upgraded: (callback: (event: { implementation: `0x${string}` }) => void, filter?: { implementation?: `0x${string}` | `0x${string}`[] | null }) => {
237
+ return this.publicClient.watchContractEvent({
238
+ address: this.contractAddress,
239
+ abi: BeaconProxyAbi,
240
+ eventName: 'Upgraded',
241
+ args: filter as any,
242
+ onLogs: (logs: any[]) => {
243
+ logs.forEach((log: any) => {
244
+ callback(log.args as any);
245
+ });
246
+ },
247
+ }) as () => void;
248
+ }
249
+ };
250
+ }
251
+ }