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