1#![allow(dead_code)]
2use anyhow::Result;
3use ethers::{abi::Abi, contract::Contract, core::types::Address, providers::Middleware};
4use std::sync::Arc;
5
6pub fn build_default<M: Middleware>(client: impl Into<Arc<M>>) -> Result<Contract<M>> {
7 let address = "7Af14ADc8Aea70f063c7eA3B2C1AD0D7A59C4bFf";
8 build_contract_string(address, client)
9}
10
11pub fn build_kovan<M: Middleware>(client: impl Into<Arc<M>>) -> Result<Contract<M>> {
12 let address = "8316F9a27e6F632a54D1E1F21aF347D4E0Cc38Dd";
13 build_contract_string(address, client)
14}
15
16pub fn build_goerli<M: Middleware>(client: impl Into<Arc<M>>) -> Result<Contract<M>> {
17 let address = "6aaEd1985a0e011ca82BB5Df8ebd92063134fd7c";
18 build_contract_string(address, client)
19}
20
21fn build_contract_string<M: Middleware, T: ToString>(
22 address: T,
23 client: impl Into<Arc<M>>,
24) -> Result<Contract<M>> {
25 let hx = hex::decode(address.to_string()).unwrap();
26 let addr = Address::from_slice(hx.as_slice());
27 build_contract(addr, client)
28}
29
30fn build_contract<M: Middleware>(
31 address: Address,
32 client: impl Into<Arc<M>>,
33) -> Result<Contract<M>> {
34 let abi: Abi = serde_json::from_str(ABI)?;
35 Ok(Contract::new(address, abi, client))
36}
37
38const ABI: &str = r#"[{
39 "anonymous": false,
40 "inputs": [
41 {
42 "indexed": false,
43 "internalType": "string",
44 "name": "",
45 "type": "string"
46 },
47 {
48 "indexed": false,
49 "internalType": "uint256",
50 "name": "",
51 "type": "uint256"
52 }
53 ],
54 "name": "LogNote",
55 "type": "event"
56 },
57 {
58 "anonymous": false,
59 "inputs": [
60 {
61 "indexed": false,
62 "internalType": "uint256",
63 "name": "inputAmount",
64 "type": "uint256"
65 },
66 {
67 "indexed": false,
68 "internalType": "address",
69 "name": "inputERC20",
70 "type": "address"
71 },
72 {
73 "indexed": false,
74 "internalType": "uint256",
75 "name": "hurdleBuyAmtMin",
76 "type": "uint256"
77 },
78 {
79 "indexed": false,
80 "internalType": "address",
81 "name": "targetERC20",
82 "type": "address"
83 },
84 {
85 "indexed": true,
86 "internalType": "bytes32",
87 "name": "pair",
88 "type": "bytes32"
89 },
90 {
91 "indexed": false,
92 "internalType": "uint256",
93 "name": "realizedFill",
94 "type": "uint256"
95 },
96 {
97 "indexed": false,
98 "internalType": "address",
99 "name": "recipient",
100 "type": "address"
101 }
102 ],
103 "name": "LogSwap",
104 "type": "event"
105 },
106 {
107 "stateMutability": "payable",
108 "type": "fallback"
109 },
110 {
111 "inputs": [],
112 "name": "RubiconMarketAddress",
113 "outputs": [
114 {
115 "internalType": "address",
116 "name": "",
117 "type": "address"
118 }
119 ],
120 "stateMutability": "view",
121 "type": "function"
122 },
123 {
124 "inputs": [
125 {
126 "internalType": "uint256",
127 "name": "buy_amt",
128 "type": "uint256"
129 },
130 {
131 "internalType": "contract ERC20",
132 "name": "pay_gem",
133 "type": "address"
134 },
135 {
136 "internalType": "uint256",
137 "name": "max_fill_amount",
138 "type": "uint256"
139 }
140 ],
141 "name": "buyAllAmountForETH",
142 "outputs": [
143 {
144 "internalType": "uint256",
145 "name": "fill",
146 "type": "uint256"
147 }
148 ],
149 "stateMutability": "nonpayable",
150 "type": "function"
151 },
152 {
153 "inputs": [
154 {
155 "internalType": "contract ERC20",
156 "name": "buy_gem",
157 "type": "address"
158 },
159 {
160 "internalType": "uint256",
161 "name": "buy_amt",
162 "type": "uint256"
163 },
164 {
165 "internalType": "uint256",
166 "name": "max_fill_amount",
167 "type": "uint256"
168 },
169 {
170 "internalType": "uint256",
171 "name": "expectedMarketFeeBPS",
172 "type": "uint256"
173 }
174 ],
175 "name": "buyAllAmountWithETH",
176 "outputs": [
177 {
178 "internalType": "uint256",
179 "name": "fill",
180 "type": "uint256"
181 }
182 ],
183 "stateMutability": "payable",
184 "type": "function"
185 },
186 {
187 "inputs": [
188 {
189 "internalType": "uint256",
190 "name": "id",
191 "type": "uint256"
192 }
193 ],
194 "name": "cancelForETH",
195 "outputs": [
196 {
197 "internalType": "bool",
198 "name": "outcome",
199 "type": "bool"
200 }
201 ],
202 "stateMutability": "nonpayable",
203 "type": "function"
204 },
205 {
206 "inputs": [
207 {
208 "internalType": "address",
209 "name": "user",
210 "type": "address"
211 },
212 {
213 "internalType": "address[]",
214 "name": "targetBathTokens",
215 "type": "address[]"
216 },
217 {
218 "internalType": "address",
219 "name": "token",
220 "type": "address"
221 }
222 ],
223 "name": "checkClaimAllUserBonusTokens",
224 "outputs": [
225 {
226 "internalType": "uint256",
227 "name": "earnedAcrossPools",
228 "type": "uint256"
229 }
230 ],
231 "stateMutability": "view",
232 "type": "function"
233 },
234 {
235 "inputs": [
236 {
237 "internalType": "uint256",
238 "name": "amount",
239 "type": "uint256"
240 },
241 {
242 "internalType": "address",
243 "name": "targetPool",
244 "type": "address"
245 }
246 ],
247 "name": "depositWithETH",
248 "outputs": [
249 {
250 "internalType": "uint256",
251 "name": "newShares",
252 "type": "uint256"
253 }
254 ],
255 "stateMutability": "payable",
256 "type": "function"
257 },
258 {
259 "inputs": [
260 {
261 "internalType": "address",
262 "name": "asset",
263 "type": "address"
264 },
265 {
266 "internalType": "address",
267 "name": "quote",
268 "type": "address"
269 }
270 ],
271 "name": "getBestOfferAndInfo",
272 "outputs": [
273 {
274 "internalType": "uint256",
275 "name": "",
276 "type": "uint256"
277 },
278 {
279 "internalType": "uint256",
280 "name": "",
281 "type": "uint256"
282 },
283 {
284 "internalType": "contract ERC20",
285 "name": "",
286 "type": "address"
287 },
288 {
289 "internalType": "uint256",
290 "name": "",
291 "type": "uint256"
292 },
293 {
294 "internalType": "contract ERC20",
295 "name": "",
296 "type": "address"
297 }
298 ],
299 "stateMutability": "view",
300 "type": "function"
301 },
302 {
303 "inputs": [
304 {
305 "internalType": "contract ERC20",
306 "name": "asset",
307 "type": "address"
308 },
309 {
310 "internalType": "contract ERC20",
311 "name": "quote",
312 "type": "address"
313 },
314 {
315 "internalType": "uint256",
316 "name": "topNOrders",
317 "type": "uint256"
318 }
319 ],
320 "name": "getBookFromPair",
321 "outputs": [
322 {
323 "internalType": "uint256[3][]",
324 "name": "",
325 "type": "uint256[3][]"
326 },
327 {
328 "internalType": "uint256[3][]",
329 "name": "",
330 "type": "uint256[3][]"
331 },
332 {
333 "internalType": "uint256",
334 "name": "",
335 "type": "uint256"
336 }
337 ],
338 "stateMutability": "view",
339 "type": "function"
340 },
341 {
342 "inputs": [
343 {
344 "internalType": "uint256",
345 "name": "pay_amt",
346 "type": "uint256"
347 },
348 {
349 "internalType": "uint256",
350 "name": "buy_amt_min",
351 "type": "uint256"
352 },
353 {
354 "internalType": "address[]",
355 "name": "route",
356 "type": "address[]"
357 },
358 {
359 "internalType": "uint256",
360 "name": "expectedMarketFeeBPS",
361 "type": "uint256"
362 }
363 ],
364 "name": "getExpectedSwapFill",
365 "outputs": [
366 {
367 "internalType": "uint256",
368 "name": "fill_amt",
369 "type": "uint256"
370 }
371 ],
372 "stateMutability": "view",
373 "type": "function"
374 },
375 {
376 "inputs": [
377 {
378 "internalType": "contract ERC20",
379 "name": "buy_gem",
380 "type": "address"
381 },
382 {
383 "internalType": "contract ERC20",
384 "name": "pay_gem",
385 "type": "address"
386 },
387 {
388 "internalType": "uint256",
389 "name": "max_fill_amount",
390 "type": "uint256"
391 }
392 ],
393 "name": "maxBuyAllAmount",
394 "outputs": [
395 {
396 "internalType": "uint256",
397 "name": "fill",
398 "type": "uint256"
399 }
400 ],
401 "stateMutability": "nonpayable",
402 "type": "function"
403 },
404 {
405 "inputs": [
406 {
407 "internalType": "contract ERC20",
408 "name": "pay_gem",
409 "type": "address"
410 },
411 {
412 "internalType": "contract ERC20",
413 "name": "buy_gem",
414 "type": "address"
415 },
416 {
417 "internalType": "uint256",
418 "name": "min_fill_amount",
419 "type": "uint256"
420 }
421 ],
422 "name": "maxSellAllAmount",
423 "outputs": [
424 {
425 "internalType": "uint256",
426 "name": "fill",
427 "type": "uint256"
428 }
429 ],
430 "stateMutability": "nonpayable",
431 "type": "function"
432 },
433 {
434 "inputs": [
435 {
436 "internalType": "uint256",
437 "name": "pay_amt",
438 "type": "uint256"
439 },
440 {
441 "internalType": "contract ERC20",
442 "name": "pay_gem",
443 "type": "address"
444 },
445 {
446 "internalType": "uint256",
447 "name": "buy_amt",
448 "type": "uint256"
449 },
450 {
451 "internalType": "uint256",
452 "name": "pos",
453 "type": "uint256"
454 }
455 ],
456 "name": "offerForETH",
457 "outputs": [
458 {
459 "internalType": "uint256",
460 "name": "",
461 "type": "uint256"
462 }
463 ],
464 "stateMutability": "nonpayable",
465 "type": "function"
466 },
467 {
468 "inputs": [
469 {
470 "internalType": "uint256",
471 "name": "pay_amt",
472 "type": "uint256"
473 },
474 {
475 "internalType": "uint256",
476 "name": "buy_amt",
477 "type": "uint256"
478 },
479 {
480 "internalType": "contract ERC20",
481 "name": "buy_gem",
482 "type": "address"
483 },
484 {
485 "internalType": "uint256",
486 "name": "pos",
487 "type": "uint256"
488 }
489 ],
490 "name": "offerWithETH",
491 "outputs": [
492 {
493 "internalType": "uint256",
494 "name": "",
495 "type": "uint256"
496 }
497 ],
498 "stateMutability": "payable",
499 "type": "function"
500 },
501 {
502 "inputs": [
503 {
504 "internalType": "address",
505 "name": "_theTrap",
506 "type": "address"
507 },
508 {
509 "internalType": "address payable",
510 "name": "_weth",
511 "type": "address"
512 }
513 ],
514 "name": "startErUp",
515 "outputs": [],
516 "stateMutability": "nonpayable",
517 "type": "function"
518 },
519 {
520 "inputs": [],
521 "name": "started",
522 "outputs": [
523 {
524 "internalType": "bool",
525 "name": "",
526 "type": "bool"
527 }
528 ],
529 "stateMutability": "view",
530 "type": "function"
531 },
532 {
533 "inputs": [
534 {
535 "internalType": "uint256",
536 "name": "pay_amt",
537 "type": "uint256"
538 },
539 {
540 "internalType": "uint256",
541 "name": "buy_amt_min",
542 "type": "uint256"
543 },
544 {
545 "internalType": "address[]",
546 "name": "route",
547 "type": "address[]"
548 },
549 {
550 "internalType": "uint256",
551 "name": "expectedMarketFeeBPS",
552 "type": "uint256"
553 }
554 ],
555 "name": "swap",
556 "outputs": [
557 {
558 "internalType": "uint256",
559 "name": "",
560 "type": "uint256"
561 }
562 ],
563 "stateMutability": "nonpayable",
564 "type": "function"
565 },
566 {
567 "inputs": [
568 {
569 "internalType": "uint256",
570 "name": "pay_amt",
571 "type": "uint256"
572 },
573 {
574 "internalType": "uint256",
575 "name": "buy_amt_min",
576 "type": "uint256"
577 },
578 {
579 "internalType": "address[]",
580 "name": "route",
581 "type": "address[]"
582 },
583 {
584 "internalType": "uint256",
585 "name": "expectedMarketFeeBPS",
586 "type": "uint256"
587 }
588 ],
589 "name": "swapForETH",
590 "outputs": [
591 {
592 "internalType": "uint256",
593 "name": "fill",
594 "type": "uint256"
595 }
596 ],
597 "stateMutability": "payable",
598 "type": "function"
599 },
600 {
601 "inputs": [
602 {
603 "internalType": "uint256",
604 "name": "pay_amt",
605 "type": "uint256"
606 },
607 {
608 "internalType": "uint256",
609 "name": "buy_amt_min",
610 "type": "uint256"
611 },
612 {
613 "internalType": "address[]",
614 "name": "route",
615 "type": "address[]"
616 },
617 {
618 "internalType": "uint256",
619 "name": "expectedMarketFeeBPS",
620 "type": "uint256"
621 }
622 ],
623 "name": "swapWithETH",
624 "outputs": [
625 {
626 "internalType": "uint256",
627 "name": "",
628 "type": "uint256"
629 }
630 ],
631 "stateMutability": "payable",
632 "type": "function"
633 },
634 {
635 "inputs": [
636 {
637 "internalType": "address",
638 "name": "",
639 "type": "address"
640 },
641 {
642 "internalType": "uint256",
643 "name": "",
644 "type": "uint256"
645 }
646 ],
647 "name": "userNativeAssetOrders",
648 "outputs": [
649 {
650 "internalType": "uint256",
651 "name": "",
652 "type": "uint256"
653 }
654 ],
655 "stateMutability": "view",
656 "type": "function"
657 },
658 {
659 "inputs": [],
660 "name": "wethAddress",
661 "outputs": [
662 {
663 "internalType": "address payable",
664 "name": "",
665 "type": "address"
666 }
667 ],
668 "stateMutability": "view",
669 "type": "function"
670 },
671 {
672 "inputs": [
673 {
674 "internalType": "uint256",
675 "name": "shares",
676 "type": "uint256"
677 },
678 {
679 "internalType": "address",
680 "name": "targetPool",
681 "type": "address"
682 }
683 ],
684 "name": "withdrawForETH",
685 "outputs": [
686 {
687 "internalType": "uint256",
688 "name": "withdrawnWETH",
689 "type": "uint256"
690 }
691 ],
692 "stateMutability": "payable",
693 "type": "function"
694 },
695 {
696 "stateMutability": "payable",
697 "type": "receive"
698 }
699]"#;