-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
300 lines (272 loc) · 16.2 KB
/
index.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
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
<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
<body data-new-gr-c-s-check-loaded="14.1062.0" data-gr-ext-installed="" data-new-gr-c-s-loaded="14.1062.0">
<h1>Check your Celer Refund Anon!</h1>
<p>You can check code <a href="https://github.com/SocketDotTech/celer-refund-ui">here</a> or view the page source.</p>
<hr>
<p>➡️ 1: Connect your wallet by clicking below. </p>
<div> <button class="connect" style="margin-left:25px">connect wallet</button> </div>
<p>
➡️ 2: Check your metamask that you are connected to the sending chain.
</p>
<p>
➡️ 3: Paste your transaction hash below. Only the hash, no explorer links.
</p>
<div>
<textarea style="height:15px;width:600px;margin-left:25px"></textarea>
<div>
<p> ➡️ 4: Clink on this button to check if refund is needed.</p>
<div> <button class="check" style="margin-left:25px; margin-bottom:25px">Check For Refund.</button></div>
<p>
➡️ 5: Check your metamask that you are connected to the sending chain.
</p>
<p> ➡️ 6: Click on the button below to claim the refund if refunded. </p>
<div> <button class="claim" style="margin-left:25px;margin-bottom:20px">Claim Refund.</button></div>
<hr>
<div>
Looking for gas on a new chain Anon! Go use <a href="https://bungee.exchange/refuel" target="_blank" >Refuel</a>.
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ethers/5.2.0/ethers.umd.min.js" integrity="sha512-YrJ7ZzmtmVJdwCwu6B91ThUGLfNjsTdHf1IdPf3J7AZQIpVDvahcBLWoKC1ebZ9RN6upm9ZheIFKSf7s7k/ZYQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type="text/javascript">
// CONSTANTS
const sendTopicLog = '0x89d8051e597ab4178a863a5190407b98abfeff406aa8db90c59af76612e58f01';
const celerSocketRefundUrl = 'https://celer-refund-api.socket.tech/api/v1/refund/trigger-withdraw';
const socketCelerImplAddresses = {
1: '0x3a23F943181408EAC424116Af7b7790c94Cb97a5',
56: '0x3a23F943181408EAC424116Af7b7790c94Cb97a5',
100: '0x3a23F943181408EAC424116Af7b7790c94Cb97a5',
42161: '0x3a23F943181408EAC424116Af7b7790c94Cb97a5',
250: '0x3a23F943181408EAC424116Af7b7790c94Cb97a5',
137: '0x3a23F943181408EAC424116Af7b7790c94Cb97a5',
10: '0x3a23F943181408EAC424116Af7b7790c94Cb97a5',
43114: '0x3a23F943181408EAC424116Af7b7790c94Cb97a5',
1313161554: '0x3a23F943181408EAC424116Af7b7790c94Cb97a5',
324: '0xaDdE7028e7ec226777e5dea5D53F6457C21ec7D6',
1101: '0x3a23F943181408EAC424116Af7b7790c94Cb97a5',
534352: '0x3a23F943181408EAC424116Af7b7790c94Cb97a5',
};
const celerRouteIds = {
1: 417,
56: 13,
100: -1,
42161: 19,
250: 12,
137: 23,
10: 18,
43114: 12,
1313161554: 5,
324: 386,
1101: 388,
534352: 385
};
// METAMASK CONNECTION
document.querySelector('.connect').onclick = async () => {
if (window.ethereum) { //check if Metamask is installed
try {
const address = await window.ethereum.enable(); //connect Metamask
const obj = {
connectedStatus: true,
status: "",
address: address
}
return obj;
} catch (error) {
return {
connectedStatus: false,
status: "🦊 Connect to Metamask using the button on the top right."
}
}
} else {
return alert('Please Install Metamask.')
}
}
// Check If the transaction is refunded or not.
document.querySelector('.check').onclick = async () => {
try {
const txHash = document.querySelector('textarea').value;
if (!txHash) return alert('Please paste your transaction hash in the box.')
const provider = new ethers.providers.Web3Provider(window.ethereum);
const txReceipt = await provider.getTransactionReceipt(txHash);
if (txReceipt && txReceipt.status === 0) return alert('Transaction has failed. Please check your transaction hash on the chain explorer.')
if (txReceipt && txReceipt.status === 1) {
const { logs } = txReceipt;
const celerSourceLog = await logs.find((log) => {
const { topics } = log;
if (topics[0].toLowerCase() === sendTopicLog) return log;
});
if (!celerSourceLog) throw new Error('Invalid Celer Bridge Transaction');
const { topics, data } = celerSourceLog;
const decodedData = ethers.utils.defaultAbiCoder.decode(
[
'bytes32',
'address',
'address',
'address',
'uint256',
'uint64',
'uint64',
'uint32',
],
data,
);
const transferId = decodedData[0];
const estimatedAmount = decodedData[4].toString();
let body = {
transfer_id: transferId,
};
let result;
let error;
await fetch('https://cbridge-prod2.celer.app/v2/getTransferStatus', {
method: "POST",
body: JSON.stringify(body),
headers: {"Content-type": "application/json; charset=UTF-8"}
}).then(response => response.json())
.then(json => {result = json;
console.log(json, typeof json)})
.catch(err => error = err);
if (error) return alert('Error in Checking Refund Status');
if (result && result.status) {
const status = result.status;
if (status === 0) return alert('Celer Network could not find this transaction.');
if (status === 1) return alert('Celer bridge is confirming your transaction. Please wait...');
if (status === 2) return alert('Transaction has failed. No funds have been detected');
if (status === 3) return alert ('Transaction Confirmation going on. Please Wait ...');
if (status === 4) return alert ('Celer is releasing your funds on the destination chain. Please wait ...');
if (status === 5) return alert (`Transfer is complete. Here is your transaction hash: ${result.dst_block_tx_link}`);
if (status === 6) {
let result_refund;
let error_refund;
fetch(`${celerSocketRefundUrl}?transferId=${transferId}&estimatedReceivedAmt=${estimatedAmount}`, {}).then(response => response.json())
.then(json => result_refund = json)
.catch(err => error_refund = err);
if (error_refund) return alert('Error in checking the refund status');
return alert ("We’ve sent a refund request to the Celer network which is not confirmed yet. Please click on “Check For Refund” again in 30 secs to verify you're eligible");
}
if (status === 7) return alert ('Celer Bridge is initiating the refund request. Please Wait for a few mins and then click on claim ...');
if (status === 8) return alert ('Please click on "Claim your refund" to start your refund process. You will be asked to do a transaction.');
if (status === 9) return alert ('Refund Process has been already initiated. Please Wait ...');
if (status === 10) return alert ('Transaction has been refunded successfully. Sorry for the inconvenience caused.');
}
}
} catch(e) {
alert('Error occured while checking refund.');
console.log(e);
}
}
// Claim the refund.
document.querySelector('.claim').onclick = async () => {
try {
const txHash = document.querySelector('textarea').value;
if (!txHash) return alert('Please paste your transaction hash in the box.')
const provider = new ethers.providers.Web3Provider(window.ethereum);
const txReceipt = await provider.getTransactionReceipt(txHash)
if (txReceipt && txReceipt.status === 0) return alert('Transaction has failed. Please check your transaction hash on the chain explorer.')
if (txReceipt && txReceipt.status === 1) {
const { logs } = txReceipt;
const celerSourceLog = await logs.find((log) => {
const { topics } = log;
if (topics[0].toLowerCase() === sendTopicLog) return log;
});
if (!celerSourceLog) throw new Error('Invalid Celer Bridge Transaction');
const { topics, data } = celerSourceLog;
const decodedData = ethers.utils.defaultAbiCoder.decode(
[
'bytes32',
'address',
'address',
'address',
'uint256',
'uint64',
'uint64',
'uint32',
],
data,
);
const transferId = decodedData[0];
const estimatedAmount = decodedData[4].toString();
let body = {
transfer_id: transferId,
};
let result;
let error;
await fetch('https://cbridge-prod2.celer.app/v2/getTransferStatus', {
method: "POST",
body: JSON.stringify(body),
headers: {"Content-type": "application/json; charset=UTF-8"}
}).then(response => response.json())
.then(json => result = json)
.catch(err => error = err);
if (error) return alert('Error in Checking Refund Status');
if (result && result.status) {
const { status, sorted_sigs, signers: _signers, powers: _powers, wd_onchain } = result;
if (status === 0) return alert('Celer Network could not find this transaction.');
if (status === 1) return alert('Celer bridge is confirming your transaction. Please wait...');
if (status === 2) return alert('Transaction has failed. No funds have been detected');
if (status === 3) return alert ('Transaction Confirmation going on. Please Wait ...');
if (status === 4) return alert ('Celer is releasing your funds on the destination chain. Please wait ...');
if (status === 5) return alert (`Transfer is complete. Here is your transaction hash: ${result.dst_block_tx_link}`);
if (status === 6) {
let result_refund;
let error_refund;
await fetch(`${celerSocketRefundUrl}?transferId=${transferId}&estimatedAmount=${estimatedAmount}`, {}).then(response => response.json())
.then(json => result_refund = json)
.catch(err => error_refund = err);
if (error_refund) return alert('Error in checking the refund status');
return alert ('Celer Bridge is initiating the refund request. Please Wait for a few mins and try again.');
}
if (status === 7) return alert ('Celer Bridge is initiating the refund request. Please Wait for a few mins and try again...');
if (status === 8) {
const { chainId } = await provider.getNetwork();
const wdmsg = ethers.utils.base64.decode(wd_onchain);
const signers = _signers.map((item) => {
const decodeSigners = ethers.utils.base64.decode(item);
const hexlifyObj = ethers.utils.hexlify(decodeSigners);
return ethers.utils.getAddress(hexlifyObj);
});
const sigs = sorted_sigs.map((item) => {
return ethers.utils.base64.decode(item);
});
const powers = _powers.map((item) => {
return ethers.utils.base64.decode(item);
});
const celerImplInterface = new ethers.utils.Interface(['function refundCelerUser(bytes,bytes[],address[],uint256[])']);
const functionParams = [wdmsg, sigs, signers, powers];
const txDataCeler = celerImplInterface.encodeFunctionData('refundCelerUser', functionParams);
const routeBytes4 = `0x${celerRouteIds[chainId].toString(16).padStart(8, '0')}`;
console.log(celerRouteIds[chainId]);
console.log({ wdmsg, sigs, signers, powers });
const txData = `${routeBytes4}${txDataCeler.substring(2)}`;
try {
const txDetails = {
"to": socketCelerImplAddresses[chainId],
"data": txData,
"value": "0x00"
};
console.log(txDetails);
const tx = await provider.getSigner().sendTransaction(txDetails);
await tx.wait();
return alert ('Refund has been successful. Please Check your wallet.');
// const socketCelerImpl = new ethers.Contract(
// socketCelerImplAddresses[chainId],
// ['function refundCelerUserAdmin(address,bytes,bytes[],address[],uint256[])'],
// provider.getSigner()
// );
// const tx = await socketCelerImpl.refundCelerUser(recipient, wdmsg, sigs, signers, powers);
// await tx.wait();
// return alert ('Refund has been successful. Please Check your wallet.');
} catch (error) {
console.log(error);
return alert('Error occured in claiming process: ', error.message);
}
}
if (status === 9) return alert ('Refund Process has been already initiated. Please Wait ...');
if (status === 10) return alert ('Refund has been successful! Please Check your wallet. Sorry for the inconvenience caused. We are trying to smoothen the experience.');
}
}
} catch(e) {
alert('Error occured while checking refund.');
console.log(e);
}
}
</script>
</body></html>