-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathAliceAndBobScenario.sol
108 lines (97 loc) · 2.84 KB
/
AliceAndBobScenario.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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import {SrcDstChainScenario} from "./SrcDstChainScenario.sol";
import {BridgeParams, RouterActions} from "./RouterActions.sol";
contract AliceAndBobScenario is SrcDstChainScenario, RouterActions {
address alice = address(0xa11ce);
address bob = address(0xb0b);
uint64 public constant BRIDGE_ONLY_GAS = 200000;
function sendAliceToBobAndReceive(
uint amount,
bool deliverEth
) public returns (uint fees) {
return
sendAliceToTargetAndReceive(
amount,
deliverEth,
bob,
BRIDGE_ONLY_GAS,
""
);
}
function sendAliceToBob(
uint amount,
bool deliverEth
) public returns (uint fees) {
(, , fees) = sendAliceToTarget(
amount,
deliverEth,
bob,
BRIDGE_ONLY_GAS,
""
);
}
function sendAliceToBobDeliverEth(uint amount) public returns (uint fees) {
return sendAliceToBob(amount, true);
}
function sendAliceToBobDeliverWeth(uint amount) public returns (uint fees) {
return sendAliceToBob(amount, false);
}
function sendAliceToBobAndReceiveDeliverEth(
uint amount
) public returns (uint fees) {
return sendAliceToBobAndReceive(amount, true);
}
function sendAliceToBobAndReceiveDeliverWeth(
uint amount
) public returns (uint fees) {
return sendAliceToBobAndReceive(amount, false);
}
function sendAliceToTarget(
uint amount,
bool deliverEth,
address target,
uint64 dstGasForCall,
bytes memory payload
) public returns (BridgeParams memory params, uint8 msgType, uint fees) {
params = BridgeParams({
src: srcChain,
dst: dstChain,
fromAddress: alice,
toAddress: target,
amount: amount
});
msgType = payload.length == 0
? MT_ETH_TRANSFER
: MT_ETH_TRANSFER_WITH_PAYLOAD;
fees = attemptBridge(
params,
msgType,
deliverEth,
dstGasForCall,
payload
);
}
function sendAliceToTargetAndReceive(
uint amount,
bool deliverEth,
address target,
uint64 dstGasForCall,
bytes memory payload
) public returns (uint fees) {
startRecordingLzMessages();
(
BridgeParams memory params,
, // uint8 msgType
uint _fees
) = sendAliceToTarget(
amount,
deliverEth,
target,
dstGasForCall,
payload
);
fees = _fees;
deliverLzMessageAtDestination(params.src, params.dst, dstGasForCall);
}
}