@gitmyabi-stg/xusd 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.
- package/README.md +108 -0
- package/contracts/FiatTokenProxy.d.ts +311 -0
- package/contracts/FiatTokenProxy.js +328 -0
- package/contracts/FiatTokenProxy.ts +428 -0
- package/contracts/FiatTokenV1.d.ts +1622 -0
- package/contracts/FiatTokenV1.js +1659 -0
- package/contracts/FiatTokenV1.ts +2163 -0
- package/contracts/index.d.ts +4 -0
- package/contracts/index.js +10 -0
- package/contracts/index.ts +5 -0
- package/index.d.ts +1 -0
- package/index.js +19 -0
- package/package.json +43 -0
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import type { Abi, Address, PublicClient, WalletClient, GetContractReturnType } from 'viem';
|
|
2
|
+
import { getContract } from 'viem';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* FiatTokenProxy ABI
|
|
6
|
+
*
|
|
7
|
+
* This ABI is typed using viem's type system for full type safety.
|
|
8
|
+
*/
|
|
9
|
+
export const FiatTokenProxyAbi = [
|
|
10
|
+
{
|
|
11
|
+
"constant": false,
|
|
12
|
+
"inputs": [
|
|
13
|
+
{
|
|
14
|
+
"name": "newImplementation",
|
|
15
|
+
"type": "address"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"name": "upgradeTo",
|
|
19
|
+
"outputs": [],
|
|
20
|
+
"payable": false,
|
|
21
|
+
"stateMutability": "nonpayable",
|
|
22
|
+
"type": "function"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"constant": false,
|
|
26
|
+
"inputs": [
|
|
27
|
+
{
|
|
28
|
+
"name": "newImplementation",
|
|
29
|
+
"type": "address"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "data",
|
|
33
|
+
"type": "bytes"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"name": "upgradeToAndCall",
|
|
37
|
+
"outputs": [],
|
|
38
|
+
"payable": true,
|
|
39
|
+
"stateMutability": "payable",
|
|
40
|
+
"type": "function"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"constant": true,
|
|
44
|
+
"inputs": [],
|
|
45
|
+
"name": "implementation",
|
|
46
|
+
"outputs": [
|
|
47
|
+
{
|
|
48
|
+
"name": "",
|
|
49
|
+
"type": "address"
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
"payable": false,
|
|
53
|
+
"stateMutability": "view",
|
|
54
|
+
"type": "function"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"constant": false,
|
|
58
|
+
"inputs": [
|
|
59
|
+
{
|
|
60
|
+
"name": "newAdmin",
|
|
61
|
+
"type": "address"
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
"name": "changeAdmin",
|
|
65
|
+
"outputs": [],
|
|
66
|
+
"payable": false,
|
|
67
|
+
"stateMutability": "nonpayable",
|
|
68
|
+
"type": "function"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"constant": true,
|
|
72
|
+
"inputs": [],
|
|
73
|
+
"name": "admin",
|
|
74
|
+
"outputs": [
|
|
75
|
+
{
|
|
76
|
+
"name": "",
|
|
77
|
+
"type": "address"
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
"payable": false,
|
|
81
|
+
"stateMutability": "view",
|
|
82
|
+
"type": "function"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"inputs": [
|
|
86
|
+
{
|
|
87
|
+
"name": "_implementation",
|
|
88
|
+
"type": "address"
|
|
89
|
+
}
|
|
90
|
+
],
|
|
91
|
+
"payable": false,
|
|
92
|
+
"stateMutability": "nonpayable",
|
|
93
|
+
"type": "constructor"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"payable": true,
|
|
97
|
+
"stateMutability": "payable",
|
|
98
|
+
"type": "fallback"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"anonymous": false,
|
|
102
|
+
"inputs": [
|
|
103
|
+
{
|
|
104
|
+
"indexed": false,
|
|
105
|
+
"name": "previousAdmin",
|
|
106
|
+
"type": "address"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"indexed": false,
|
|
110
|
+
"name": "newAdmin",
|
|
111
|
+
"type": "address"
|
|
112
|
+
}
|
|
113
|
+
],
|
|
114
|
+
"name": "AdminChanged",
|
|
115
|
+
"type": "event"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"anonymous": false,
|
|
119
|
+
"inputs": [
|
|
120
|
+
{
|
|
121
|
+
"indexed": false,
|
|
122
|
+
"name": "implementation",
|
|
123
|
+
"type": "address"
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
"name": "Upgraded",
|
|
127
|
+
"type": "event"
|
|
128
|
+
}
|
|
129
|
+
] as const satisfies Abi;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Type-safe ABI for FiatTokenProxy
|
|
133
|
+
*/
|
|
134
|
+
export type FiatTokenProxyAbi = typeof FiatTokenProxyAbi;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Contract instance type for FiatTokenProxy
|
|
138
|
+
*/
|
|
139
|
+
// Use any for contract type to avoid complex viem type issues
|
|
140
|
+
// The runtime behavior is type-safe through viem's ABI typing
|
|
141
|
+
export type FiatTokenProxyContract = any;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* FiatTokenProxy Contract Class
|
|
145
|
+
*
|
|
146
|
+
* Provides a class-based API similar to TypeChain for interacting with the contract.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* import { createPublicClient, createWalletClient, http } from 'viem';
|
|
151
|
+
* import { mainnet } from 'viem/chains';
|
|
152
|
+
* import { FiatTokenProxy } from 'FiatTokenProxy';
|
|
153
|
+
*
|
|
154
|
+
* const publicClient = createPublicClient({ chain: mainnet, transport: http() });
|
|
155
|
+
* const walletClient = createWalletClient({ chain: mainnet, transport: http() });
|
|
156
|
+
*
|
|
157
|
+
* const contract = new FiatTokenProxy('0x...', { publicClient, walletClient });
|
|
158
|
+
*
|
|
159
|
+
* // Read functions
|
|
160
|
+
* const result = await contract.balanceOf('0x...');
|
|
161
|
+
*
|
|
162
|
+
* // Write functions
|
|
163
|
+
* const hash = await contract.transfer('0x...', 1000n);
|
|
164
|
+
*
|
|
165
|
+
* // Simulate transactions (dry-run)
|
|
166
|
+
* const simulation = await contract.simulate.transfer('0x...', 1000n);
|
|
167
|
+
* console.log('Gas estimate:', simulation.request.gas);
|
|
168
|
+
*
|
|
169
|
+
* // Watch events
|
|
170
|
+
* const unwatch = contract.watch.Transfer((event) => {
|
|
171
|
+
* console.log('Transfer event:', event);
|
|
172
|
+
* });
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
export class FiatTokenProxy {
|
|
176
|
+
private contract: FiatTokenProxyContract;
|
|
177
|
+
private contractAddress: Address;
|
|
178
|
+
private publicClient: PublicClient;
|
|
179
|
+
|
|
180
|
+
constructor(
|
|
181
|
+
address: Address,
|
|
182
|
+
clients: {
|
|
183
|
+
publicClient: PublicClient;
|
|
184
|
+
walletClient?: WalletClient;
|
|
185
|
+
}
|
|
186
|
+
) {
|
|
187
|
+
this.contractAddress = address;
|
|
188
|
+
this.publicClient = clients.publicClient;
|
|
189
|
+
this.contract = getContract({
|
|
190
|
+
address,
|
|
191
|
+
abi: FiatTokenProxyAbi,
|
|
192
|
+
client: {
|
|
193
|
+
public: clients.publicClient,
|
|
194
|
+
wallet: clients.walletClient,
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Get the contract address
|
|
201
|
+
*/
|
|
202
|
+
get address(): Address {
|
|
203
|
+
return this.contractAddress;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Get the underlying viem contract instance.
|
|
208
|
+
*/
|
|
209
|
+
getContract(): FiatTokenProxyContract {
|
|
210
|
+
return this.contract;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* implementation
|
|
215
|
+
* view
|
|
216
|
+
*/
|
|
217
|
+
async implementation(): Promise<`0x${string}`> {
|
|
218
|
+
return this.contract.read.implementation() as Promise<`0x${string}`>;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* admin
|
|
223
|
+
* view
|
|
224
|
+
*/
|
|
225
|
+
async admin(): Promise<`0x${string}`> {
|
|
226
|
+
return this.contract.read.admin() as Promise<`0x${string}`>;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* upgradeTo
|
|
231
|
+
* nonpayable
|
|
232
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
233
|
+
*/
|
|
234
|
+
async upgradeTo(newImplementation: `0x${string}`, options?: {
|
|
235
|
+
accessList?: import('viem').AccessList;
|
|
236
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
237
|
+
chain?: import('viem').Chain | null;
|
|
238
|
+
dataSuffix?: `0x${string}`;
|
|
239
|
+
gas?: bigint;
|
|
240
|
+
gasPrice?: bigint;
|
|
241
|
+
maxFeePerGas?: bigint;
|
|
242
|
+
maxPriorityFeePerGas?: bigint;
|
|
243
|
+
nonce?: number;
|
|
244
|
+
value?: bigint;
|
|
245
|
+
}): Promise<`0x${string}`> {
|
|
246
|
+
if (!this.contract.write) {
|
|
247
|
+
throw new Error('Wallet client is required for write operations');
|
|
248
|
+
}
|
|
249
|
+
return this.contract.write.upgradeTo([newImplementation] as const, options) as Promise<`0x${string}`>;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* upgradeToAndCall
|
|
254
|
+
* payable
|
|
255
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
256
|
+
*/
|
|
257
|
+
async upgradeToAndCall(newImplementation: `0x${string}`, data: `0x${string}`, options?: {
|
|
258
|
+
accessList?: import('viem').AccessList;
|
|
259
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
260
|
+
chain?: import('viem').Chain | null;
|
|
261
|
+
dataSuffix?: `0x${string}`;
|
|
262
|
+
gas?: bigint;
|
|
263
|
+
gasPrice?: bigint;
|
|
264
|
+
maxFeePerGas?: bigint;
|
|
265
|
+
maxPriorityFeePerGas?: bigint;
|
|
266
|
+
nonce?: number;
|
|
267
|
+
value?: bigint;
|
|
268
|
+
}): Promise<`0x${string}`> {
|
|
269
|
+
if (!this.contract.write) {
|
|
270
|
+
throw new Error('Wallet client is required for write operations');
|
|
271
|
+
}
|
|
272
|
+
return this.contract.write.upgradeToAndCall([newImplementation, data] as const, options) as Promise<`0x${string}`>;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* changeAdmin
|
|
277
|
+
* nonpayable
|
|
278
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
279
|
+
*/
|
|
280
|
+
async changeAdmin(newAdmin: `0x${string}`, options?: {
|
|
281
|
+
accessList?: import('viem').AccessList;
|
|
282
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
283
|
+
chain?: import('viem').Chain | null;
|
|
284
|
+
dataSuffix?: `0x${string}`;
|
|
285
|
+
gas?: bigint;
|
|
286
|
+
gasPrice?: bigint;
|
|
287
|
+
maxFeePerGas?: bigint;
|
|
288
|
+
maxPriorityFeePerGas?: bigint;
|
|
289
|
+
nonce?: number;
|
|
290
|
+
value?: bigint;
|
|
291
|
+
}): Promise<`0x${string}`> {
|
|
292
|
+
if (!this.contract.write) {
|
|
293
|
+
throw new Error('Wallet client is required for write operations');
|
|
294
|
+
}
|
|
295
|
+
return this.contract.write.changeAdmin([newAdmin] as const, options) as Promise<`0x${string}`>;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Simulate contract write operations (dry-run without sending transaction)
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* const result = await contract.simulate.transfer('0x...', 1000n);
|
|
305
|
+
* console.log('Gas estimate:', result.request.gas);
|
|
306
|
+
* console.log('Would succeed:', result.result);
|
|
307
|
+
*/
|
|
308
|
+
get simulate() {
|
|
309
|
+
const contract = this.contract;
|
|
310
|
+
if (!contract.simulate) {
|
|
311
|
+
throw new Error('Public client is required for simulation');
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
/**
|
|
315
|
+
* Simulate upgradeTo
|
|
316
|
+
* Returns gas estimate and result without sending transaction
|
|
317
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
318
|
+
*/
|
|
319
|
+
async upgradeTo(newImplementation: `0x${string}`, options?: {
|
|
320
|
+
accessList?: import('viem').AccessList;
|
|
321
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
322
|
+
chain?: import('viem').Chain | null;
|
|
323
|
+
dataSuffix?: `0x${string}`;
|
|
324
|
+
gas?: bigint;
|
|
325
|
+
gasPrice?: bigint;
|
|
326
|
+
maxFeePerGas?: bigint;
|
|
327
|
+
maxPriorityFeePerGas?: bigint;
|
|
328
|
+
nonce?: number;
|
|
329
|
+
value?: bigint;
|
|
330
|
+
}): Promise<void> {
|
|
331
|
+
return contract.simulate.upgradeTo([newImplementation] as const, options) as Promise<void>;
|
|
332
|
+
},
|
|
333
|
+
/**
|
|
334
|
+
* Simulate upgradeToAndCall
|
|
335
|
+
* Returns gas estimate and result without sending transaction
|
|
336
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
337
|
+
*/
|
|
338
|
+
async upgradeToAndCall(newImplementation: `0x${string}`, data: `0x${string}`, options?: {
|
|
339
|
+
accessList?: import('viem').AccessList;
|
|
340
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
341
|
+
chain?: import('viem').Chain | null;
|
|
342
|
+
dataSuffix?: `0x${string}`;
|
|
343
|
+
gas?: bigint;
|
|
344
|
+
gasPrice?: bigint;
|
|
345
|
+
maxFeePerGas?: bigint;
|
|
346
|
+
maxPriorityFeePerGas?: bigint;
|
|
347
|
+
nonce?: number;
|
|
348
|
+
value?: bigint;
|
|
349
|
+
}): Promise<void> {
|
|
350
|
+
return contract.simulate.upgradeToAndCall([newImplementation, data] as const, options) as Promise<void>;
|
|
351
|
+
},
|
|
352
|
+
/**
|
|
353
|
+
* Simulate changeAdmin
|
|
354
|
+
* Returns gas estimate and result without sending transaction
|
|
355
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
356
|
+
*/
|
|
357
|
+
async changeAdmin(newAdmin: `0x${string}`, options?: {
|
|
358
|
+
accessList?: import('viem').AccessList;
|
|
359
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
360
|
+
chain?: import('viem').Chain | null;
|
|
361
|
+
dataSuffix?: `0x${string}`;
|
|
362
|
+
gas?: bigint;
|
|
363
|
+
gasPrice?: bigint;
|
|
364
|
+
maxFeePerGas?: bigint;
|
|
365
|
+
maxPriorityFeePerGas?: bigint;
|
|
366
|
+
nonce?: number;
|
|
367
|
+
value?: bigint;
|
|
368
|
+
}): Promise<void> {
|
|
369
|
+
return contract.simulate.changeAdmin([newAdmin] as const, options) as Promise<void>;
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Watch contract events
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* // Watch all Transfer events
|
|
379
|
+
* const unwatch = contract.watch.Transfer((event) => {
|
|
380
|
+
* console.log('Transfer:', event);
|
|
381
|
+
* });
|
|
382
|
+
*
|
|
383
|
+
* // Stop watching
|
|
384
|
+
* unwatch();
|
|
385
|
+
*/
|
|
386
|
+
get watch() {
|
|
387
|
+
return {
|
|
388
|
+
/**
|
|
389
|
+
* Watch AdminChanged events
|
|
390
|
+
* @param callback Function to call when event is emitted
|
|
391
|
+
* @param filter Optional filter for indexed parameters
|
|
392
|
+
* @returns Unwatch function to stop listening
|
|
393
|
+
*/
|
|
394
|
+
AdminChanged: (callback: (event: { previousAdmin: `0x${string}`; newAdmin: `0x${string}` }) => void) => {
|
|
395
|
+
return this.publicClient.watchContractEvent({
|
|
396
|
+
address: this.contractAddress,
|
|
397
|
+
abi: FiatTokenProxyAbi,
|
|
398
|
+
eventName: 'AdminChanged',
|
|
399
|
+
|
|
400
|
+
onLogs: (logs: any[]) => {
|
|
401
|
+
logs.forEach((log: any) => {
|
|
402
|
+
callback(log.args as any);
|
|
403
|
+
});
|
|
404
|
+
},
|
|
405
|
+
}) as () => void;
|
|
406
|
+
},
|
|
407
|
+
/**
|
|
408
|
+
* Watch Upgraded events
|
|
409
|
+
* @param callback Function to call when event is emitted
|
|
410
|
+
* @param filter Optional filter for indexed parameters
|
|
411
|
+
* @returns Unwatch function to stop listening
|
|
412
|
+
*/
|
|
413
|
+
Upgraded: (callback: (event: { implementation: `0x${string}` }) => void) => {
|
|
414
|
+
return this.publicClient.watchContractEvent({
|
|
415
|
+
address: this.contractAddress,
|
|
416
|
+
abi: FiatTokenProxyAbi,
|
|
417
|
+
eventName: 'Upgraded',
|
|
418
|
+
|
|
419
|
+
onLogs: (logs: any[]) => {
|
|
420
|
+
logs.forEach((log: any) => {
|
|
421
|
+
callback(log.args as any);
|
|
422
|
+
});
|
|
423
|
+
},
|
|
424
|
+
}) as () => void;
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
}
|