This repository has been archived by the owner on Mar 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJpycArbitrage.html
163 lines (163 loc) · 4.64 KB
/
JpycArbitrage.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>JPYC Arbitrage</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script type="text/javascript">
const RpcPolygon = "https://polygon-rpc.com/";
const AddressJpyc = "0x6AE7Dfc73E0dDE2aa99ac063DcF7e8A63265108c";
function Get(url){
return new Promise(function(a, b){
let x = new XMLHttpRequest();
x.onload = function(){
if(x.status == 200){
a(x.response);
}else{
b(x.status);
}
};
x.onerror = function(){
b(null);
}
x.open("GET", url);
x.send();
});
}
function GetPolygonGasPrice(){
return new Promise(function(a, b){
Get("https://gasstation-mainnet.matic.network/").then(function(x){
a(Math.min(parseInt(JSON.parse(x).standard) + 1, 300) + "000000000");
}, function(x){
a("0");
});
});
}
function Approve(){
window.ethereum.request({method : "eth_requestAccounts"}).then(function(x){
window.ethereum.request({method : "wallet_switchEthereumChain", params : [{chainId : "0x89"}]}).then(function(x){
let w = new Web3(window.ethereum);
w.eth.getAccounts().then(function(a){
let abi = [
{
inputs : [
{
name : "",
type : "address"
},
{
name : "",
type : "uint256"
}
],
name : "approve",
outputs : [
{
name : "",
type : "bool"
}
],
type : "function"
}
];
let c = new w.eth.Contract(abi, AddressJpyc);
GetPolygonGasPrice().then(function(x){
c.methods.approve(document.getElementById("contract").value, w.utils.toBN("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")).send({from : a[0], gas : 100000, gasPrice : x}).then(function(x){
document.getElementById("output").innerText += "Transaction hash : " + x.transactionHash + "\n";
});
});
});
});
});
}
function Arbitrage(){
window.ethereum.request({method : "eth_requestAccounts"}).then(function(x){
window.ethereum.request({method : "wallet_switchEthereumChain", params : [{chainId : "0x89"}]}).then(function(x){
let w = new Web3(window.ethereum);
w.eth.getAccounts().then(function(a){
let abi = [
{
inputs : [
{
name : "amount",
type : "uint256"
},
{
name : "minimum",
type : "uint256"
},
{
name : "route",
type : "uint256"
},
{
name : "loop",
type : "uint256"
}
],
name : "arbitrage",
outputs : [],
type : "function"
}
];
let c = new w.eth.Contract(abi, document.getElementById("contract").value);
GetPolygonGasPrice().then(function(x){
c.methods.arbitrage(parseInt(document.getElementById("amount").value) + "000000000000000000", parseInt(document.getElementById("amount").value) + "000000000000000000", parseInt(document.getElementById("route").value), 5).send({from : a[0], gas : 3000000, gasPrice : x}).then(function(x){
document.getElementById("output").innerText += "Transaction hash : " + x.transactionHash + "\n";
});
});
});
});
});
}
function CheckArbitrage(){
let w = new Web3(RpcPolygon);
let abi = [
{
inputs : [
{
name : "amount",
type : "uint256"
}
],
name : "checkArbitrage",
outputs : [
{
name : "",
type : "uint256"
},
{
name : "",
type : "uint256"
}
],
type : "function"
}
];
let c = new w.eth.Contract(abi, document.getElementById("contract").value);
c.methods.checkArbitrage(parseInt(document.getElementById("amount").value) + "000000000000000000").call().then(function(x){
document.getElementById("output").innerText += "You will earn " + (parseInt(x[0]) / (10 ** 18) - parseInt(document.getElementById("amount").value)) + " JPYC with the route " + x[1] + "\n";
});
}
</script>
</head>
<body>
Contract address<br>
<input type="text" id="contract" value="0x4b861805a85abFc996A5ADa53acf48da2A4c4263"><br>
Amount<br>
<input type="text" id="amount" value="10000"><br>
Route (0 - 15)<br>
<input type="text" id="route" value="0"><br>
<form onsubmit="Approve();return false;">
<input type="submit" value="Approve the token">
</form>
<form onsubmit="Arbitrage();return false;">
<input type="submit" value="Arbitrage (JPYC <-> jJPY <-> USDC <-> JPYC)">
</form>
<form onsubmit="CheckArbitrage();return false;">
<input type="submit" value="Check arbitrage profit and route">
</form>
<hr>
<span id="output"></span>
</body>
</html>