@gitmyabi-stg/reusd 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/ERC1967Proxy.d.ts +144 -0
- package/contracts/ERC1967Proxy.js +180 -0
- package/contracts/ERC1967Proxy.ts +209 -0
- package/contracts/ShareToken.d.ts +1242 -0
- package/contracts/ShareToken.js +1385 -0
- package/contracts/ShareToken.ts +1657 -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
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# @gitmyabi-stg/reusd
|
|
2
|
+
|
|
3
|
+
Auto-generated TypeScript type bindings for **reUSD**
|
|
4
|
+
|
|
5
|
+
- **Build ID**: `etherscan-reusd-5086bf35-1780061737832`
|
|
6
|
+
- **Build Number**: 1
|
|
7
|
+
- **Commit**: `21cd24d`
|
|
8
|
+
- **Branch**: `etherscan`
|
|
9
|
+
- **Target**: `ethers-v6`
|
|
10
|
+
- **Contracts**: 2
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @gitmyabi-stg/reusd@0.0.1
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### Class-based API (TypeChain-like)
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { createPublicClient, createWalletClient, http } from 'viem';
|
|
24
|
+
import { mainnet } from 'viem/chains';
|
|
25
|
+
import { YourContract } from '@gitmyabi-stg/reusd';
|
|
26
|
+
|
|
27
|
+
const publicClient = createPublicClient({ chain: mainnet, transport: http() });
|
|
28
|
+
const walletClient = createWalletClient({ chain: mainnet, transport: http() });
|
|
29
|
+
|
|
30
|
+
// Create contract instance
|
|
31
|
+
const contract = new YourContract('0x...', { publicClient, walletClient });
|
|
32
|
+
|
|
33
|
+
// Read functions - call directly like TypeChain!
|
|
34
|
+
const result = await contract.yourMethod(param1, param2);
|
|
35
|
+
|
|
36
|
+
// Write functions - also call directly!
|
|
37
|
+
const hash = await contract.transfer('0x...', 1000n);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### With viem directly
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { createPublicClient, http } from 'viem';
|
|
44
|
+
import { mainnet } from 'viem/chains';
|
|
45
|
+
import { YourContractAbi } from '@gitmyabi-stg/reusd';
|
|
46
|
+
|
|
47
|
+
const client = createPublicClient({
|
|
48
|
+
chain: mainnet,
|
|
49
|
+
transport: http(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Fully typed contract read
|
|
53
|
+
const result = await client.readContract({
|
|
54
|
+
address: '0x...',
|
|
55
|
+
abi: YourContractAbi,
|
|
56
|
+
functionName: 'yourMethod',
|
|
57
|
+
args: [param1, param2],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Fully typed contract write
|
|
61
|
+
const hash = await client.writeContract({
|
|
62
|
+
address: '0x...',
|
|
63
|
+
abi: YourContractAbi,
|
|
64
|
+
functionName: 'yourMethod',
|
|
65
|
+
args: [param1, param2],
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### With wagmi
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { useReadContract, useWriteContract } from 'wagmi';
|
|
73
|
+
import { YourContractAbi } from '@gitmyabi-stg/reusd';
|
|
74
|
+
|
|
75
|
+
function MyComponent() {
|
|
76
|
+
const { data } = useReadContract({
|
|
77
|
+
address: '0x...',
|
|
78
|
+
abi: YourContractAbi,
|
|
79
|
+
functionName: 'yourMethod',
|
|
80
|
+
args: [param1, param2],
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const { writeContract } = useWriteContract();
|
|
84
|
+
|
|
85
|
+
const handleWrite = () => {
|
|
86
|
+
writeContract({
|
|
87
|
+
address: '0x...',
|
|
88
|
+
abi: YourContractAbi,
|
|
89
|
+
functionName: 'yourMethod',
|
|
90
|
+
args: [param1, param2],
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
return <button onClick={handleWrite}>Call Contract</button>;
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Type Safety
|
|
99
|
+
|
|
100
|
+
This package provides full TypeScript type safety for all contract methods, events, and parameters using viem's type system. All ABIs are exported as `const` assertions for maximum type inference.
|
|
101
|
+
|
|
102
|
+
## Generated Contracts
|
|
103
|
+
|
|
104
|
+
This package includes type bindings for 2 contract(s) generated from ABI artifacts.
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
Apache License 2.0
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { Address, PublicClient, WalletClient } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* ERC1967Proxy ABI
|
|
4
|
+
*
|
|
5
|
+
* This ABI is typed using viem's type system for full type safety.
|
|
6
|
+
*/
|
|
7
|
+
export declare const ERC1967ProxyAbi: readonly [{
|
|
8
|
+
readonly inputs: readonly [{
|
|
9
|
+
readonly internalType: "address";
|
|
10
|
+
readonly name: "implementation";
|
|
11
|
+
readonly type: "address";
|
|
12
|
+
}, {
|
|
13
|
+
readonly internalType: "bytes";
|
|
14
|
+
readonly name: "_data";
|
|
15
|
+
readonly type: "bytes";
|
|
16
|
+
}];
|
|
17
|
+
readonly stateMutability: "payable";
|
|
18
|
+
readonly type: "constructor";
|
|
19
|
+
}, {
|
|
20
|
+
readonly inputs: readonly [{
|
|
21
|
+
readonly internalType: "address";
|
|
22
|
+
readonly name: "target";
|
|
23
|
+
readonly type: "address";
|
|
24
|
+
}];
|
|
25
|
+
readonly name: "AddressEmptyCode";
|
|
26
|
+
readonly type: "error";
|
|
27
|
+
}, {
|
|
28
|
+
readonly inputs: readonly [{
|
|
29
|
+
readonly internalType: "address";
|
|
30
|
+
readonly name: "implementation";
|
|
31
|
+
readonly type: "address";
|
|
32
|
+
}];
|
|
33
|
+
readonly name: "ERC1967InvalidImplementation";
|
|
34
|
+
readonly type: "error";
|
|
35
|
+
}, {
|
|
36
|
+
readonly inputs: readonly [];
|
|
37
|
+
readonly name: "ERC1967NonPayable";
|
|
38
|
+
readonly type: "error";
|
|
39
|
+
}, {
|
|
40
|
+
readonly inputs: readonly [];
|
|
41
|
+
readonly name: "FailedInnerCall";
|
|
42
|
+
readonly type: "error";
|
|
43
|
+
}, {
|
|
44
|
+
readonly anonymous: false;
|
|
45
|
+
readonly inputs: readonly [{
|
|
46
|
+
readonly indexed: true;
|
|
47
|
+
readonly internalType: "address";
|
|
48
|
+
readonly name: "implementation";
|
|
49
|
+
readonly type: "address";
|
|
50
|
+
}];
|
|
51
|
+
readonly name: "Upgraded";
|
|
52
|
+
readonly type: "event";
|
|
53
|
+
}, {
|
|
54
|
+
readonly stateMutability: "payable";
|
|
55
|
+
readonly type: "fallback";
|
|
56
|
+
}];
|
|
57
|
+
/**
|
|
58
|
+
* Type-safe ABI for ERC1967Proxy
|
|
59
|
+
*/
|
|
60
|
+
export type ERC1967ProxyAbi = typeof ERC1967ProxyAbi;
|
|
61
|
+
/**
|
|
62
|
+
* Contract instance type for ERC1967Proxy
|
|
63
|
+
*/
|
|
64
|
+
export type ERC1967ProxyContract = any;
|
|
65
|
+
/**
|
|
66
|
+
* ERC1967Proxy Contract Class
|
|
67
|
+
*
|
|
68
|
+
* Provides a class-based API similar to TypeChain for interacting with the contract.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* import { createPublicClient, createWalletClient, http } from 'viem';
|
|
73
|
+
* import { mainnet } from 'viem/chains';
|
|
74
|
+
* import { ERC1967Proxy } from 'ERC1967Proxy';
|
|
75
|
+
*
|
|
76
|
+
* const publicClient = createPublicClient({ chain: mainnet, transport: http() });
|
|
77
|
+
* const walletClient = createWalletClient({ chain: mainnet, transport: http() });
|
|
78
|
+
*
|
|
79
|
+
* const contract = new ERC1967Proxy('0x...', { publicClient, walletClient });
|
|
80
|
+
*
|
|
81
|
+
* // Read functions
|
|
82
|
+
* const result = await contract.balanceOf('0x...');
|
|
83
|
+
*
|
|
84
|
+
* // Write functions
|
|
85
|
+
* const hash = await contract.transfer('0x...', 1000n);
|
|
86
|
+
*
|
|
87
|
+
* // Simulate transactions (dry-run)
|
|
88
|
+
* const simulation = await contract.simulate.transfer('0x...', 1000n);
|
|
89
|
+
* console.log('Gas estimate:', simulation.request.gas);
|
|
90
|
+
*
|
|
91
|
+
* // Watch events
|
|
92
|
+
* const unwatch = contract.watch.Transfer((event) => {
|
|
93
|
+
* console.log('Transfer event:', event);
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare class ERC1967Proxy {
|
|
98
|
+
private contract;
|
|
99
|
+
private contractAddress;
|
|
100
|
+
private publicClient;
|
|
101
|
+
constructor(address: Address, clients: {
|
|
102
|
+
publicClient: PublicClient;
|
|
103
|
+
walletClient?: WalletClient;
|
|
104
|
+
});
|
|
105
|
+
/**
|
|
106
|
+
* Get the contract address
|
|
107
|
+
*/
|
|
108
|
+
get address(): Address;
|
|
109
|
+
/**
|
|
110
|
+
* Get the underlying viem contract instance.
|
|
111
|
+
*/
|
|
112
|
+
getContract(): ERC1967ProxyContract;
|
|
113
|
+
/**
|
|
114
|
+
* Simulate contract write operations (dry-run without sending transaction)
|
|
115
|
+
*
|
|
116
|
+
* Note: This contract has no write functions, so simulate returns an empty object.
|
|
117
|
+
*/
|
|
118
|
+
get simulate(): {};
|
|
119
|
+
/**
|
|
120
|
+
* Watch contract events
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* // Watch all Transfer events
|
|
124
|
+
* const unwatch = contract.watch.Transfer((event) => {
|
|
125
|
+
* console.log('Transfer:', event);
|
|
126
|
+
* });
|
|
127
|
+
*
|
|
128
|
+
* // Stop watching
|
|
129
|
+
* unwatch();
|
|
130
|
+
*/
|
|
131
|
+
get watch(): {
|
|
132
|
+
/**
|
|
133
|
+
* Watch Upgraded events
|
|
134
|
+
* @param callback Function to call when event is emitted
|
|
135
|
+
* @param filter Optional filter for indexed parameters
|
|
136
|
+
* @returns Unwatch function to stop listening
|
|
137
|
+
*/
|
|
138
|
+
Upgraded: (callback: (event: {
|
|
139
|
+
implementation: `0x${string}`;
|
|
140
|
+
}) => void, filter?: {
|
|
141
|
+
implementation?: `0x${string}` | `0x${string}`[] | null;
|
|
142
|
+
}) => () => void;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERC1967Proxy = exports.ERC1967ProxyAbi = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
/**
|
|
6
|
+
* ERC1967Proxy ABI
|
|
7
|
+
*
|
|
8
|
+
* This ABI is typed using viem's type system for full type safety.
|
|
9
|
+
*/
|
|
10
|
+
exports.ERC1967ProxyAbi = [
|
|
11
|
+
{
|
|
12
|
+
"inputs": [
|
|
13
|
+
{
|
|
14
|
+
"internalType": "address",
|
|
15
|
+
"name": "implementation",
|
|
16
|
+
"type": "address"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"internalType": "bytes",
|
|
20
|
+
"name": "_data",
|
|
21
|
+
"type": "bytes"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"stateMutability": "payable",
|
|
25
|
+
"type": "constructor"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"inputs": [
|
|
29
|
+
{
|
|
30
|
+
"internalType": "address",
|
|
31
|
+
"name": "target",
|
|
32
|
+
"type": "address"
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"name": "AddressEmptyCode",
|
|
36
|
+
"type": "error"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"inputs": [
|
|
40
|
+
{
|
|
41
|
+
"internalType": "address",
|
|
42
|
+
"name": "implementation",
|
|
43
|
+
"type": "address"
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"name": "ERC1967InvalidImplementation",
|
|
47
|
+
"type": "error"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"inputs": [],
|
|
51
|
+
"name": "ERC1967NonPayable",
|
|
52
|
+
"type": "error"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"inputs": [],
|
|
56
|
+
"name": "FailedInnerCall",
|
|
57
|
+
"type": "error"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"anonymous": false,
|
|
61
|
+
"inputs": [
|
|
62
|
+
{
|
|
63
|
+
"indexed": true,
|
|
64
|
+
"internalType": "address",
|
|
65
|
+
"name": "implementation",
|
|
66
|
+
"type": "address"
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"name": "Upgraded",
|
|
70
|
+
"type": "event"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"stateMutability": "payable",
|
|
74
|
+
"type": "fallback"
|
|
75
|
+
}
|
|
76
|
+
];
|
|
77
|
+
/**
|
|
78
|
+
* ERC1967Proxy Contract Class
|
|
79
|
+
*
|
|
80
|
+
* Provides a class-based API similar to TypeChain for interacting with the contract.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* import { createPublicClient, createWalletClient, http } from 'viem';
|
|
85
|
+
* import { mainnet } from 'viem/chains';
|
|
86
|
+
* import { ERC1967Proxy } from 'ERC1967Proxy';
|
|
87
|
+
*
|
|
88
|
+
* const publicClient = createPublicClient({ chain: mainnet, transport: http() });
|
|
89
|
+
* const walletClient = createWalletClient({ chain: mainnet, transport: http() });
|
|
90
|
+
*
|
|
91
|
+
* const contract = new ERC1967Proxy('0x...', { publicClient, walletClient });
|
|
92
|
+
*
|
|
93
|
+
* // Read functions
|
|
94
|
+
* const result = await contract.balanceOf('0x...');
|
|
95
|
+
*
|
|
96
|
+
* // Write functions
|
|
97
|
+
* const hash = await contract.transfer('0x...', 1000n);
|
|
98
|
+
*
|
|
99
|
+
* // Simulate transactions (dry-run)
|
|
100
|
+
* const simulation = await contract.simulate.transfer('0x...', 1000n);
|
|
101
|
+
* console.log('Gas estimate:', simulation.request.gas);
|
|
102
|
+
*
|
|
103
|
+
* // Watch events
|
|
104
|
+
* const unwatch = contract.watch.Transfer((event) => {
|
|
105
|
+
* console.log('Transfer event:', event);
|
|
106
|
+
* });
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
class ERC1967Proxy {
|
|
110
|
+
constructor(address, clients) {
|
|
111
|
+
this.contractAddress = address;
|
|
112
|
+
this.publicClient = clients.publicClient;
|
|
113
|
+
this.contract = (0, viem_1.getContract)({
|
|
114
|
+
address,
|
|
115
|
+
abi: exports.ERC1967ProxyAbi,
|
|
116
|
+
client: {
|
|
117
|
+
public: clients.publicClient,
|
|
118
|
+
wallet: clients.walletClient,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get the contract address
|
|
124
|
+
*/
|
|
125
|
+
get address() {
|
|
126
|
+
return this.contractAddress;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get the underlying viem contract instance.
|
|
130
|
+
*/
|
|
131
|
+
getContract() {
|
|
132
|
+
return this.contract;
|
|
133
|
+
}
|
|
134
|
+
// No read functions
|
|
135
|
+
// No write functions
|
|
136
|
+
/**
|
|
137
|
+
* Simulate contract write operations (dry-run without sending transaction)
|
|
138
|
+
*
|
|
139
|
+
* Note: This contract has no write functions, so simulate returns an empty object.
|
|
140
|
+
*/
|
|
141
|
+
get simulate() {
|
|
142
|
+
return {};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Watch contract events
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* // Watch all Transfer events
|
|
149
|
+
* const unwatch = contract.watch.Transfer((event) => {
|
|
150
|
+
* console.log('Transfer:', event);
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* // Stop watching
|
|
154
|
+
* unwatch();
|
|
155
|
+
*/
|
|
156
|
+
get watch() {
|
|
157
|
+
return {
|
|
158
|
+
/**
|
|
159
|
+
* Watch Upgraded events
|
|
160
|
+
* @param callback Function to call when event is emitted
|
|
161
|
+
* @param filter Optional filter for indexed parameters
|
|
162
|
+
* @returns Unwatch function to stop listening
|
|
163
|
+
*/
|
|
164
|
+
Upgraded: (callback, filter) => {
|
|
165
|
+
return this.publicClient.watchContractEvent({
|
|
166
|
+
address: this.contractAddress,
|
|
167
|
+
abi: exports.ERC1967ProxyAbi,
|
|
168
|
+
eventName: 'Upgraded',
|
|
169
|
+
args: filter,
|
|
170
|
+
onLogs: (logs) => {
|
|
171
|
+
logs.forEach((log) => {
|
|
172
|
+
callback(log.args);
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
exports.ERC1967Proxy = ERC1967Proxy;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { Abi, Address, PublicClient, WalletClient, GetContractReturnType } from 'viem';
|
|
2
|
+
import { getContract } from 'viem';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ERC1967Proxy ABI
|
|
6
|
+
*
|
|
7
|
+
* This ABI is typed using viem's type system for full type safety.
|
|
8
|
+
*/
|
|
9
|
+
export const ERC1967ProxyAbi = [
|
|
10
|
+
{
|
|
11
|
+
"inputs": [
|
|
12
|
+
{
|
|
13
|
+
"internalType": "address",
|
|
14
|
+
"name": "implementation",
|
|
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
|
+
"inputs": [
|
|
28
|
+
{
|
|
29
|
+
"internalType": "address",
|
|
30
|
+
"name": "target",
|
|
31
|
+
"type": "address"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"name": "AddressEmptyCode",
|
|
35
|
+
"type": "error"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"inputs": [
|
|
39
|
+
{
|
|
40
|
+
"internalType": "address",
|
|
41
|
+
"name": "implementation",
|
|
42
|
+
"type": "address"
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"name": "ERC1967InvalidImplementation",
|
|
46
|
+
"type": "error"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"inputs": [],
|
|
50
|
+
"name": "ERC1967NonPayable",
|
|
51
|
+
"type": "error"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"inputs": [],
|
|
55
|
+
"name": "FailedInnerCall",
|
|
56
|
+
"type": "error"
|
|
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
|
+
] as const satisfies Abi;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Type-safe ABI for ERC1967Proxy
|
|
79
|
+
*/
|
|
80
|
+
export type ERC1967ProxyAbi = typeof ERC1967ProxyAbi;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Contract instance type for ERC1967Proxy
|
|
84
|
+
*/
|
|
85
|
+
// Use any for contract type to avoid complex viem type issues
|
|
86
|
+
// The runtime behavior is type-safe through viem's ABI typing
|
|
87
|
+
export type ERC1967ProxyContract = any;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* ERC1967Proxy Contract Class
|
|
91
|
+
*
|
|
92
|
+
* Provides a class-based API similar to TypeChain for interacting with the contract.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* import { createPublicClient, createWalletClient, http } from 'viem';
|
|
97
|
+
* import { mainnet } from 'viem/chains';
|
|
98
|
+
* import { ERC1967Proxy } from 'ERC1967Proxy';
|
|
99
|
+
*
|
|
100
|
+
* const publicClient = createPublicClient({ chain: mainnet, transport: http() });
|
|
101
|
+
* const walletClient = createWalletClient({ chain: mainnet, transport: http() });
|
|
102
|
+
*
|
|
103
|
+
* const contract = new ERC1967Proxy('0x...', { publicClient, walletClient });
|
|
104
|
+
*
|
|
105
|
+
* // Read functions
|
|
106
|
+
* const result = await contract.balanceOf('0x...');
|
|
107
|
+
*
|
|
108
|
+
* // Write functions
|
|
109
|
+
* const hash = await contract.transfer('0x...', 1000n);
|
|
110
|
+
*
|
|
111
|
+
* // Simulate transactions (dry-run)
|
|
112
|
+
* const simulation = await contract.simulate.transfer('0x...', 1000n);
|
|
113
|
+
* console.log('Gas estimate:', simulation.request.gas);
|
|
114
|
+
*
|
|
115
|
+
* // Watch events
|
|
116
|
+
* const unwatch = contract.watch.Transfer((event) => {
|
|
117
|
+
* console.log('Transfer event:', event);
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export class ERC1967Proxy {
|
|
122
|
+
private contract: ERC1967ProxyContract;
|
|
123
|
+
private contractAddress: Address;
|
|
124
|
+
private publicClient: PublicClient;
|
|
125
|
+
|
|
126
|
+
constructor(
|
|
127
|
+
address: Address,
|
|
128
|
+
clients: {
|
|
129
|
+
publicClient: PublicClient;
|
|
130
|
+
walletClient?: WalletClient;
|
|
131
|
+
}
|
|
132
|
+
) {
|
|
133
|
+
this.contractAddress = address;
|
|
134
|
+
this.publicClient = clients.publicClient;
|
|
135
|
+
this.contract = getContract({
|
|
136
|
+
address,
|
|
137
|
+
abi: ERC1967ProxyAbi,
|
|
138
|
+
client: {
|
|
139
|
+
public: clients.publicClient,
|
|
140
|
+
wallet: clients.walletClient,
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Get the contract address
|
|
147
|
+
*/
|
|
148
|
+
get address(): Address {
|
|
149
|
+
return this.contractAddress;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Get the underlying viem contract instance.
|
|
154
|
+
*/
|
|
155
|
+
getContract(): ERC1967ProxyContract {
|
|
156
|
+
return this.contract;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// No read functions
|
|
160
|
+
|
|
161
|
+
// No write functions
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Simulate contract write operations (dry-run without sending transaction)
|
|
167
|
+
*
|
|
168
|
+
* Note: This contract has no write functions, so simulate returns an empty object.
|
|
169
|
+
*/
|
|
170
|
+
get simulate() {
|
|
171
|
+
return {};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Watch contract events
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* // Watch all Transfer events
|
|
179
|
+
* const unwatch = contract.watch.Transfer((event) => {
|
|
180
|
+
* console.log('Transfer:', event);
|
|
181
|
+
* });
|
|
182
|
+
*
|
|
183
|
+
* // Stop watching
|
|
184
|
+
* unwatch();
|
|
185
|
+
*/
|
|
186
|
+
get watch() {
|
|
187
|
+
return {
|
|
188
|
+
/**
|
|
189
|
+
* Watch Upgraded events
|
|
190
|
+
* @param callback Function to call when event is emitted
|
|
191
|
+
* @param filter Optional filter for indexed parameters
|
|
192
|
+
* @returns Unwatch function to stop listening
|
|
193
|
+
*/
|
|
194
|
+
Upgraded: (callback: (event: { implementation: `0x${string}` }) => void, filter?: { implementation?: `0x${string}` | `0x${string}`[] | null }) => {
|
|
195
|
+
return this.publicClient.watchContractEvent({
|
|
196
|
+
address: this.contractAddress,
|
|
197
|
+
abi: ERC1967ProxyAbi,
|
|
198
|
+
eventName: 'Upgraded',
|
|
199
|
+
args: filter as any,
|
|
200
|
+
onLogs: (logs: any[]) => {
|
|
201
|
+
logs.forEach((log: any) => {
|
|
202
|
+
callback(log.args as any);
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
}) as () => void;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
}
|