-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJpycExchangeV3.sol
650 lines (640 loc) · 23.5 KB
/
JpycExchangeV3.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IErc20 {
function decimals() external pure returns(uint8);
function balanceOf(address) external view returns(uint256);
function transfer(address, uint256) external returns(bool);
function approve(address, uint256) external returns(bool);
function transferFrom(address, address, uint256) external returns(bool);
}
interface IExchangeV1forV2Wrapper {
function quote(uint256) external view returns(uint256);
function swap(uint256, address) external;
}
interface IQuickSwapRouter {
function getAmountsOut(uint256, address[] calldata) external view returns(uint256[] memory);
function swapExactTokensForTokens(uint256, uint256, address[] calldata, address, uint256) external returns(uint256[] memory);
}
struct UniswapExactInputSingle {
address _0;
address _1;
uint24 _2;
address _3;
uint256 _4;
uint256 _5;
uint256 _6;
uint160 _7;
}
interface IUniswapQuoter {
function quoteExactInputSingle(address, address, uint24, uint256, uint160) external returns(uint256);
}
interface IUniswapRouter {
function exactInputSingle(UniswapExactInputSingle calldata) external returns(uint256);
}
interface ICurvePool {
function get_dy(int128, int128, uint256) external view returns(uint256);
function exchange(int128, int128, uint256, uint256) external returns(uint256);
}
struct JarvisV2Mint {
uint256 _0;
uint256 _1;
uint256 _2;
address _3;
}
interface IJarvisV2Pool {
function getMintTradeInfo(uint256) external view returns(uint256, uint256);
function getRedeemTradeInfo(uint256) external view returns(uint256, uint256);
function mint(JarvisV2Mint calldata) external returns(uint256, uint256);
function redeem(JarvisV2Mint calldata) external returns(uint256, uint256);
}
contract JpycExchangeV3 {
IErc20 internal constant jpycv1 = IErc20(0x6AE7Dfc73E0dDE2aa99ac063DcF7e8A63265108c);
IErc20 internal constant jpycv2 = IErc20(0x431D5dfF03120AFA4bDf332c61A6e1766eF37BDB);
IErc20 internal constant jjpy = IErc20(0x8343091F2499FD4b6174A46D067A920a3b851FF9);
IErc20 internal constant usdc = IErc20(0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174);
IExchangeV1forV2Wrapper internal constant exchangeV1forV2 = IExchangeV1forV2Wrapper(0xdc65838a5D3Bb48505F346f2112f677cd780F73b);
IQuickSwapRouter internal constant routerQuickSwap = IQuickSwapRouter(0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff);
IUniswapQuoter internal constant quoterUniswap = IUniswapQuoter(0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6);
IUniswapRouter internal constant routerUniswap = IUniswapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564);
ICurvePool internal constant poolCurveV1 = ICurvePool(0xE8dCeA7Fb2Baf7a9F4d9af608F06d78a687F8d9A);
ICurvePool internal constant poolCurveV2 = ICurvePool(0xaA91CDD7abb47F821Cf07a2d38Cc8668DEAf1bdc);
IJarvisV2Pool internal constant poolJarvisV2 = IJarvisV2Pool(0xAEc757BF73cc1f4609a1459205835Dd40b4e3F29);
mapping(address => mapping(address => function(uint256, uint256) returns(uint256))) internal rate;
mapping(address => mapping(address => function(uint256, uint256))) internal exchange;
struct Calculation {
uint256 amountIn;
uint256 amountOut;
uint256 amountOutDelta;
}
constructor() {
jpycv1.approve(address(exchangeV1forV2), type(uint256).max);
jpycv1.approve(address(routerQuickSwap), type(uint256).max);
jpycv1.approve(address(routerUniswap), type(uint256).max);
jpycv1.approve(address(poolCurveV1), type(uint256).max);
jpycv2.approve(address(routerQuickSwap), type(uint256).max);
jpycv2.approve(address(routerUniswap), type(uint256).max);
jpycv2.approve(address(poolCurveV2), type(uint256).max);
jjpy.approve(address(routerUniswap), type(uint256).max);
jjpy.approve(address(poolCurveV1), type(uint256).max);
jjpy.approve(address(poolCurveV2), type(uint256).max);
jjpy.approve(address(poolJarvisV2), type(uint256).max);
usdc.approve(address(routerQuickSwap), type(uint256).max);
usdc.approve(address(routerUniswap), type(uint256).max);
usdc.approve(address(poolJarvisV2), type(uint256).max);
rate[address(jpycv1)][address(jpycv2)] = rateCombinedJpycV1ToJpycV2;
rate[address(jpycv1)][address(usdc)] = rateCombinedJpycV1ToUsdc;
rate[address(jpycv2)][address(jpycv1)] = rateCombinedJpycV2ToJpycV1;
rate[address(jpycv2)][address(usdc)] = rateCombinedJpycV2ToUsdc;
rate[address(usdc)][address(jpycv1)] = rateCombinedUsdcToJpycV1;
rate[address(usdc)][address(jpycv2)] = rateCombinedUsdcToJpycV2;
exchange[address(jpycv1)][address(jpycv2)] = exchangeCombinedJpycV1ToJpycV2;
exchange[address(jpycv1)][address(usdc)] = exchangeCombinedJpycV1ToUsdc;
exchange[address(jpycv2)][address(jpycv1)] = exchangeCombinedJpycV2ToJpycV1;
exchange[address(jpycv2)][address(usdc)] = exchangeCombinedJpycV2ToUsdc;
exchange[address(usdc)][address(jpycv1)] = exchangeCombinedUsdcToJpycV1;
exchange[address(usdc)][address(jpycv2)] = exchangeCombinedUsdcToJpycV2;
}
function quote(address tokenIn, address tokenOut, uint256 amount, uint256 precision) public returns(uint256[] memory, uint256) {
function(uint256, uint256) returns(uint256) f;
uint256 amountDelta;
uint256 amountCumulative;
uint256 index;
Calculation[5] memory calculation;
uint256[] memory amountIn;
uint256 amountOut;
f = rate[tokenIn][tokenOut];
assembly {
if eq(f, 0) {
revert(mload(0x40), 0)
}
}
amountDelta = amount / precision;
amountCumulative = 0;
for(uint256 i = 0; i < 5; i++) {
calculation[i].amountIn = 0;
calculation[i].amountOut = 0;
calculation[i].amountOutDelta = f(i, amountDelta);
}
for(uint256 i = 0; i < precision; i++) {
if(i == precision - 1) {
if(amountDelta != amount - amountCumulative) {
amountDelta = amount - amountCumulative;
for(uint256 j = 0; j < 5; j++) {
calculation[j].amountOutDelta = f(j, calculation[j].amountIn + amountDelta) - calculation[j].amountOut;
}
}
}
index = 0;
for(uint256 j = 1; j < 5; j++) {
if(calculation[j].amountOutDelta > calculation[index].amountOutDelta) {
index = j;
}
}
calculation[index].amountIn += amountDelta;
calculation[index].amountOut += calculation[index].amountOutDelta;
if(i < precision - 1) {
calculation[index].amountOutDelta = f(index, calculation[index].amountIn + amountDelta) - calculation[index].amountOut;
amountCumulative += amountDelta;
}
}
amountIn = new uint256[](5);
amountOut = 0;
for(uint256 i = 0; i < 5; i++) {
amountIn[i] = calculation[i].amountIn;
amountOut += calculation[i].amountOut;
}
return (amountIn, amountOut);
}
function swap(address tokenIn, address tokenOut, uint256[] memory amount, uint256 minimum) public {
function(uint256, uint256) f;
uint256 amountIn;
uint256 amountOut;
f = exchange[tokenIn][tokenOut];
assembly {
if eq(f, 0) {
revert(mload(0x40), 0)
}
}
amountIn = 0;
for(uint256 i = 0; i < amount.length; i++) {
amountIn += amount[i];
}
IErc20(tokenIn).transferFrom(msg.sender, address(this), amountIn);
for(uint256 i = 0; i < amount.length; i++) {
if(amount[i] > 0) {
f(i, amount[i]);
}
}
amountOut = IErc20(tokenOut).balanceOf(address(this));
require(amountOut >= minimum);
IErc20(tokenOut).transfer(msg.sender, amountOut);
}
function rateCombinedJpycV1ToJpycV2(uint256 route, uint256 amount) internal returns(uint256) {
if(route == 0) {
return rateJpycV1ToJpycV2(0, amount);
}
if(route == 1) {
return rateUsdcToJpycV2(1, rateJpycV1ToUsdc(1, amount));
}
if(route == 2) {
return rateJjpyToJpycV2(0, rateJpycV1ToJjpy(0, amount));
}
return 0;
}
function exchangeCombinedJpycV1ToJpycV2(uint256 route, uint256 amount) internal {
if(route == 0) {
exchangeJpycV1ToJpycV2(0, amount);
return;
}
if(route == 1) {
exchangeJpycV1ToUsdc(1, amount);
exchangeUsdcToJpycV2(1, usdc.balanceOf(address(this)));
return;
}
if(route == 2) {
exchangeJpycV1ToJjpy(0, amount);
exchangeJjpyToJpycV2(0, jjpy.balanceOf(address(this)));
return;
}
revert();
}
function rateCombinedJpycV2ToJpycV1(uint256 route, uint256 amount) internal returns(uint256) {
if(route == 0) {
return rateUsdcToJpycV1(1, rateJpycV2ToUsdc(1, amount));
}
if(route == 1) {
return rateJjpyToJpycV1(0, rateJpycV2ToJjpy(0, amount));
}
return 0;
}
function exchangeCombinedJpycV2ToJpycV1(uint256 route, uint256 amount) internal {
if(route == 0) {
exchangeJpycV2ToUsdc(1, amount);
exchangeUsdcToJpycV1(1, usdc.balanceOf(address(this)));
return;
}
if(route == 1) {
exchangeJpycV2ToJjpy(0, amount);
exchangeJjpyToJpycV1(0, jjpy.balanceOf(address(this)));
return;
}
revert();
}
function rateCombinedJpycV1ToUsdc(uint256 route, uint256 amount) internal returns(uint256) {
if(route == 0) {
return rateJpycV1ToUsdc(0, amount);
}
if(route == 1) {
return rateJpycV1ToUsdc(1, amount);
}
if(route == 2) {
return rateJpycV2ToUsdc(1, rateJpycV1ToJpycV2(0, amount));
}
if(route == 3) {
return rateJjpyToUsdc(0, rateJpycV1ToJjpy(0, amount));
}
if(route == 4) {
return rateJjpyToUsdc(0, rateJpycV2ToJjpy(0, rateJpycV1ToJpycV2(0, amount)));
}
return 0;
}
function exchangeCombinedJpycV1ToUsdc(uint256 route, uint256 amount) internal {
if(route == 0) {
exchangeJpycV1ToUsdc(0, amount);
return;
}
if(route == 1) {
exchangeJpycV1ToUsdc(1, amount);
return;
}
if(route == 2) {
exchangeJpycV1ToJpycV2(0, amount);
exchangeJpycV2ToUsdc(1, jpycv2.balanceOf(address(this)));
return;
}
if(route == 3) {
exchangeJpycV1ToJjpy(0, amount);
exchangeJjpyToUsdc(0, jjpy.balanceOf(address(this)));
return;
}
if(route == 4) {
exchangeJpycV1ToJpycV2(0, amount);
exchangeJpycV2ToJjpy(0, jpycv2.balanceOf(address(this)));
exchangeJjpyToUsdc(0, jjpy.balanceOf(address(this)));
return;
}
revert();
}
function rateCombinedUsdcToJpycV1(uint256 route, uint256 amount) internal returns(uint256) {
if(route == 0) {
return rateUsdcToJpycV1(0, amount);
}
if(route == 1) {
return rateUsdcToJpycV1(1, amount);
}
if(route == 2) {
return rateJjpyToJpycV1(0, rateUsdcToJjpy(0, amount));
}
return 0;
}
function exchangeCombinedUsdcToJpycV1(uint256 route, uint256 amount) internal {
if(route == 0) {
exchangeUsdcToJpycV1(0, amount);
return;
}
if(route == 1) {
exchangeUsdcToJpycV1(1, amount);
return;
}
if(route == 2) {
exchangeUsdcToJjpy(0, amount);
exchangeJjpyToJpycV1(0, jjpy.balanceOf(address(this)));
return;
}
revert();
}
function rateCombinedJpycV2ToUsdc(uint256 route, uint256 amount) internal returns(uint256) {
if(route == 0) {
return rateJpycV2ToUsdc(0, amount);
}
if(route == 1) {
return rateJpycV2ToUsdc(1, amount);
}
if(route == 2) {
return rateJjpyToUsdc(0, rateJpycV2ToJjpy(0, amount));
}
return 0;
}
function exchangeCombinedJpycV2ToUsdc(uint256 route, uint256 amount) internal {
if(route == 0) {
exchangeJpycV2ToUsdc(0, amount);
return;
}
if(route == 1) {
exchangeJpycV2ToUsdc(1, amount);
return;
}
if(route == 2) {
exchangeJpycV2ToJjpy(0, amount);
exchangeJjpyToUsdc(0, jjpy.balanceOf(address(this)));
return;
}
revert();
}
function rateCombinedUsdcToJpycV2(uint256 route, uint256 amount) internal returns(uint256) {
if(route == 0) {
return rateUsdcToJpycV2(0, amount);
}
if(route == 1) {
return rateUsdcToJpycV2(1, amount);
}
if(route == 2) {
return rateJpycV1ToJpycV2(0, rateUsdcToJpycV1(1, amount));
}
if(route == 3) {
return rateJjpyToJpycV2(0, rateUsdcToJjpy(0, amount));
}
if(route == 4) {
return rateJpycV1ToJpycV2(0, rateJjpyToJpycV1(0, rateUsdcToJjpy(0, amount)));
}
return 0;
}
function exchangeCombinedUsdcToJpycV2(uint256 route, uint256 amount) internal {
if(route == 0) {
exchangeUsdcToJpycV2(0, amount);
return;
}
if(route == 1) {
exchangeUsdcToJpycV2(1, amount);
return;
}
if(route == 2) {
exchangeUsdcToJpycV1(1, amount);
exchangeJpycV1ToJpycV2(0, jpycv1.balanceOf(address(this)));
return;
}
if(route == 3) {
exchangeUsdcToJjpy(0, amount);
exchangeJjpyToJpycV2(0, jjpy.balanceOf(address(this)));
return;
}
if(route == 4) {
exchangeUsdcToJjpy(0, amount);
exchangeJjpyToJpycV1(0, jjpy.balanceOf(address(this)));
exchangeJpycV1ToJpycV2(0, jpycv1.balanceOf(address(this)));
return;
}
revert();
}
function rateJpycV1ToJpycV2(uint256 route, uint256 amount) internal returns(uint256) {
if(amount == 0) {
return 0;
}
if(route == 0) {
try exchangeV1forV2.quote(amount) returns(uint256 a) {
return a;
}
catch {
}
}
return 0;
}
function exchangeJpycV1ToJpycV2(uint256 route, uint256 amount) internal {
if(route == 0) {
exchangeV1forV2.swap(amount, address(this));
return;
}
revert();
}
function rateJpycV1ToUsdc(uint256 route, uint256 amount) internal returns(uint256) {
if(amount == 0) {
return 0;
}
if(route == 0) {
try routerQuickSwap.getAmountsOut(amount, addressArray(address(jpycv1), address(usdc))) returns(uint256[] memory a) {
return a[1];
}
catch {
}
}
if(route == 1) {
try quoterUniswap.quoteExactInputSingle(address(jpycv1), address(usdc), 500, amount, 0) returns(uint256 a) {
return a;
}
catch {
}
}
return 0;
}
function exchangeJpycV1ToUsdc(uint256 route, uint256 amount) internal {
if(route == 0) {
routerQuickSwap.swapExactTokensForTokens(amount, 0, addressArray(address(jpycv1), address(usdc)), address(this), block.timestamp);
return;
}
if(route == 1) {
routerUniswap.exactInputSingle(UniswapExactInputSingle(address(jpycv1), address(usdc), 500, address(this), block.timestamp, amount, 0, 0));
return;
}
revert();
}
function rateUsdcToJpycV1(uint256 route, uint256 amount) internal returns(uint256) {
if(amount == 0) {
return 0;
}
if(route == 0) {
try routerQuickSwap.getAmountsOut(amount, addressArray(address(usdc), address(jpycv1))) returns(uint256[] memory a) {
return a[1];
}
catch {
}
}
if(route == 1) {
try quoterUniswap.quoteExactInputSingle(address(usdc), address(jpycv1), 500, amount, 0) returns(uint256 a) {
return a;
}
catch {
}
}
return 0;
}
function exchangeUsdcToJpycV1(uint256 route, uint256 amount) internal {
if(route == 0) {
routerQuickSwap.swapExactTokensForTokens(amount, 0, addressArray(address(usdc), address(jpycv1)), address(this), block.timestamp);
return;
}
if(route == 1) {
routerUniswap.exactInputSingle(UniswapExactInputSingle(address(usdc), address(jpycv1), 500, address(this), block.timestamp, amount, 0, 0));
return;
}
revert();
}
function rateJjpyToJpycV1(uint256 route, uint256 amount) internal returns(uint256) {
if(amount == 0) {
return 0;
}
if(route == 0) {
try poolCurveV1.get_dy(0, 1, amount) returns(uint256 a) {
return a;
}
catch {
}
}
return 0;
}
function exchangeJjpyToJpycV1(uint256 route, uint256 amount) internal {
if(route == 0) {
poolCurveV1.exchange(0, 1, amount, 0);
return;
}
revert();
}
function rateJpycV1ToJjpy(uint256 route, uint256 amount) internal returns(uint256) {
if(amount == 0) {
return 0;
}
if(route == 0) {
try poolCurveV1.get_dy(1, 0, amount) returns(uint256 a) {
return a;
}
catch {
}
}
return 0;
}
function exchangeJpycV1ToJjpy(uint256 route, uint256 amount) internal {
if(route == 0) {
poolCurveV1.exchange(1, 0, amount, 0);
return;
}
revert();
}
function rateUsdcToJjpy(uint256 route, uint256 amount) internal returns(uint256) {
if(amount == 0) {
return 0;
}
if(route == 0) {
try poolJarvisV2.getMintTradeInfo(amount) returns(uint256 a, uint256) {
return a;
}
catch {
}
}
return 0;
}
function exchangeUsdcToJjpy(uint256 route, uint256 amount) internal {
if(route == 0) {
poolJarvisV2.mint(JarvisV2Mint(0, amount, block.timestamp, address(this)));
return;
}
revert();
}
function rateJjpyToUsdc(uint256 route, uint256 amount) internal returns(uint256) {
if(amount == 0) {
return 0;
}
if(route == 0) {
try poolJarvisV2.getRedeemTradeInfo(amount) returns(uint256 a, uint256) {
return a;
}
catch {
}
}
return 0;
}
function exchangeJjpyToUsdc(uint256 route, uint256 amount) internal {
if(route == 0) {
poolJarvisV2.redeem(JarvisV2Mint(amount, 0, block.timestamp, address(this)));
return;
}
revert();
}
function rateJpycV2ToUsdc(uint256 route, uint256 amount) internal returns(uint256) {
if(amount == 0) {
return 0;
}
if(route == 0) {
try routerQuickSwap.getAmountsOut(amount, addressArray(address(jpycv2), address(usdc))) returns(uint256[] memory a) {
return a[1];
}
catch {
}
}
if(route == 1) {
try quoterUniswap.quoteExactInputSingle(address(jpycv2), address(usdc), 500, amount, 0) returns(uint256 a) {
return a;
}
catch {
}
}
return 0;
}
function exchangeJpycV2ToUsdc(uint256 route, uint256 amount) internal {
if(route == 0) {
routerQuickSwap.swapExactTokensForTokens(amount, 0, addressArray(address(jpycv2), address(usdc)), address(this), block.timestamp);
return;
}
if(route == 1) {
routerUniswap.exactInputSingle(UniswapExactInputSingle(address(jpycv2), address(usdc), 500, address(this), block.timestamp, amount, 0, 0));
return;
}
revert();
}
function rateUsdcToJpycV2(uint256 route, uint256 amount) internal returns(uint256) {
if(amount == 0) {
return 0;
}
if(route == 0) {
try routerQuickSwap.getAmountsOut(amount, addressArray(address(usdc), address(jpycv2))) returns(uint256[] memory a) {
return a[1];
}
catch {
}
}
if(route == 1) {
try quoterUniswap.quoteExactInputSingle(address(usdc), address(jpycv2), 500, amount, 0) returns(uint256 a) {
return a;
}
catch {
}
}
return 0;
}
function exchangeUsdcToJpycV2(uint256 route, uint256 amount) internal {
if(route == 0) {
routerQuickSwap.swapExactTokensForTokens(amount, 0, addressArray(address(usdc), address(jpycv2)), address(this), block.timestamp);
return;
}
if(route == 1) {
routerUniswap.exactInputSingle(UniswapExactInputSingle(address(usdc), address(jpycv2), 500, address(this), block.timestamp, amount, 0, 0));
return;
}
revert();
}
function rateJjpyToJpycV2(uint256 route, uint256 amount) internal returns(uint256) {
if(amount == 0) {
return 0;
}
if(route == 0) {
try poolCurveV2.get_dy(0, 1, amount) returns(uint256 a) {
return a;
}
catch {
}
}
return 0;
}
function exchangeJjpyToJpycV2(uint256 route, uint256 amount) internal {
if(route == 0) {
poolCurveV2.exchange(0, 1, amount, 0);
return;
}
revert();
}
function rateJpycV2ToJjpy(uint256 route, uint256 amount) internal returns(uint256) {
if(amount == 0) {
return 0;
}
if(route == 0) {
try poolCurveV2.get_dy(1, 0, amount) returns(uint256 a) {
return a;
}
catch {
}
}
return 0;
}
function exchangeJpycV2ToJjpy(uint256 route, uint256 amount) internal {
if(route == 0) {
poolCurveV2.exchange(1, 0, amount, 0);
return;
}
revert();
}
function addressArray(address _0, address _1) internal pure returns(address[] memory) {
address[] memory a;
a = new address[](2);
a[0] = _0;
a[1] = _1;
return a;
}
}