Line data Source code
1 : import 'package:walletkit_dart/walletkit_dart.dart';
2 :
3 0 : final uniswap_v2_factory_abi = ContractABI.fromAbi('''[
4 : {
5 : "inputs": [
6 : {
7 : "internalType": "address",
8 : "name": "_feeToSetter",
9 : "type": "address"
10 : },
11 : {
12 : "internalType": "address",
13 : "name": "_WZENIQ",
14 : "type": "address"
15 : }
16 : ],
17 : "stateMutability": "nonpayable",
18 : "type": "constructor"
19 : },
20 : {
21 : "anonymous": false,
22 : "inputs": [
23 : {
24 : "indexed": true,
25 : "internalType": "address",
26 : "name": "token0",
27 : "type": "address"
28 : },
29 : {
30 : "indexed": true,
31 : "internalType": "address",
32 : "name": "token1",
33 : "type": "address"
34 : },
35 : {
36 : "indexed": false,
37 : "internalType": "address",
38 : "name": "pair",
39 : "type": "address"
40 : },
41 : {
42 : "indexed": false,
43 : "internalType": "uint256",
44 : "name": "",
45 : "type": "uint256"
46 : }
47 : ],
48 : "name": "PairCreated",
49 : "type": "event"
50 : },
51 : {
52 : "inputs": [],
53 : "name": "WZENIQ",
54 : "outputs": [
55 : {
56 : "internalType": "address",
57 : "name": "",
58 : "type": "address"
59 : }
60 : ],
61 : "stateMutability": "view",
62 : "type": "function"
63 : },
64 : {
65 : "inputs": [
66 : {
67 : "internalType": "uint256",
68 : "name": "",
69 : "type": "uint256"
70 : }
71 : ],
72 : "name": "allPairs",
73 : "outputs": [
74 : {
75 : "internalType": "address",
76 : "name": "",
77 : "type": "address"
78 : }
79 : ],
80 : "stateMutability": "view",
81 : "type": "function"
82 : },
83 : {
84 : "inputs": [],
85 : "name": "allPairsLength",
86 : "outputs": [
87 : {
88 : "internalType": "uint256",
89 : "name": "",
90 : "type": "uint256"
91 : }
92 : ],
93 : "stateMutability": "view",
94 : "type": "function"
95 : },
96 : {
97 : "inputs": [
98 : {
99 : "internalType": "address",
100 : "name": "tokenA",
101 : "type": "address"
102 : },
103 : {
104 : "internalType": "address",
105 : "name": "tokenB",
106 : "type": "address"
107 : }
108 : ],
109 : "name": "createPair",
110 : "outputs": [
111 : {
112 : "internalType": "address",
113 : "name": "pair",
114 : "type": "address"
115 : }
116 : ],
117 : "stateMutability": "nonpayable",
118 : "type": "function"
119 : },
120 : {
121 : "inputs": [],
122 : "name": "feeTo",
123 : "outputs": [
124 : {
125 : "internalType": "address",
126 : "name": "",
127 : "type": "address"
128 : }
129 : ],
130 : "stateMutability": "view",
131 : "type": "function"
132 : },
133 : {
134 : "inputs": [],
135 : "name": "feeToSetter",
136 : "outputs": [
137 : {
138 : "internalType": "address",
139 : "name": "",
140 : "type": "address"
141 : }
142 : ],
143 : "stateMutability": "view",
144 : "type": "function"
145 : },
146 : {
147 : "inputs": [
148 : {
149 : "internalType": "address",
150 : "name": "",
151 : "type": "address"
152 : },
153 : {
154 : "internalType": "address",
155 : "name": "",
156 : "type": "address"
157 : }
158 : ],
159 : "name": "getPair",
160 : "outputs": [
161 : {
162 : "internalType": "address",
163 : "name": "",
164 : "type": "address"
165 : }
166 : ],
167 : "stateMutability": "view",
168 : "type": "function"
169 : },
170 : {
171 : "inputs": [
172 : {
173 : "internalType": "address",
174 : "name": "_feeTo",
175 : "type": "address"
176 : }
177 : ],
178 : "name": "setFeeTo",
179 : "outputs": [],
180 : "stateMutability": "nonpayable",
181 : "type": "function"
182 : },
183 : {
184 : "inputs": [
185 : {
186 : "internalType": "address",
187 : "name": "_feeToSetter",
188 : "type": "address"
189 : }
190 : ],
191 : "name": "setFeeToSetter",
192 : "outputs": [],
193 : "stateMutability": "nonpayable",
194 : "type": "function"
195 : }
196 : ]
197 : ''');
198 :
199 : class UniswapV2Factory extends InternalContract {
200 0 : UniswapV2Factory({
201 : required super.contractAddress,
202 : required super.rpc,
203 0 : }) : super(abi: uniswap_v2_factory_abi);
204 :
205 0 : Future<String> getPair({
206 : required String tokenA,
207 : required String tokenB,
208 : }) async {
209 0 : final function = abi.getFunction('getPair')!;
210 :
211 0 : final result = await readSafe(
212 0 : function: function.addValues(values: [tokenA, tokenB]),
213 : );
214 :
215 0 : return result.outputs.first.value as String;
216 : }
217 :
218 0 : Future<BigInt> allPairsLength() async {
219 0 : final function = abi.getFunction("allPairsLength")!;
220 0 : final result = await readSafe(
221 0 : function: function.addValues(values: []),
222 : );
223 0 : return result.outputs.first.value as BigInt;
224 : }
225 :
226 0 : Future<String> allPairs(BigInt index) async {
227 0 : final function = abi.getFunction("allPairs")!;
228 0 : final result = await readSafe(
229 0 : function: function.addValues(values: [index]),
230 : );
231 0 : return result.outputs.first.value as String;
232 : }
233 : }
|