-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathbridge.js
69 lines (64 loc) · 1.67 KB
/
bridge.js
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
import {parseFromDecimals, parseToDecimals, parseToFelt, parseToUint256} from '../utils';
import {l1_callContract, l1_sendTransaction, l2_sendTransaction} from '../utils/contract';
export const deposit = async ({recipient, amount, decimals, contract, options, emitter}) => {
try {
return l1_sendTransaction(
contract,
'deposit',
[parseToDecimals(amount, decimals), recipient],
options,
emitter
);
} catch (ex) {
return Promise.reject(ex);
}
};
export const depositEth = async ({recipient, amount, contract, options, emitter}) => {
try {
return l1_sendTransaction(
contract,
'deposit',
[recipient],
{
...options,
value: parseToDecimals(amount)
},
emitter
);
} catch (ex) {
return Promise.reject(ex);
}
};
export const withdraw = async ({recipient, amount, decimals, contract, emitter}) => {
try {
return l1_sendTransaction(
contract,
'withdraw',
[parseToDecimals(amount, decimals), recipient],
{
from: recipient
},
emitter
);
} catch (ex) {
return Promise.reject(ex);
}
};
export const maxDeposit = async ({decimals, contract}) => {
try {
const maxDeposit = await l1_callContract(contract, 'maxDeposit');
return parseFromDecimals(maxDeposit, decimals);
} catch (ex) {
return Promise.reject(ex);
}
};
export const initiateWithdraw = async ({recipient, amount, decimals, contract}) => {
try {
return l2_sendTransaction(contract, 'initiate_withdraw', {
l1Recipient: parseToFelt(recipient),
amount: parseToUint256(amount, decimals)
});
} catch (ex) {
return Promise.reject(ex);
}
};