Skip to content

Commit fbb13dd

Browse files
committed
Github Action: Update contract
1 parent 6f71942 commit fbb13dd

File tree

3 files changed

+40
-246
lines changed

3 files changed

+40
-246
lines changed

tutorials/token-bridge-e2e/packages/l1-contracts/contracts/TokenPortal.sol

Lines changed: 16 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -14,165 +14,70 @@ contract TokenPortal {
1414

1515
IRegistry public registry;
1616
IERC20 public underlying;
17-
bytes32 public l2TokenAddress;
17+
bytes32 public l2Bridge;
1818

19-
function initialize(address _registry, address _underlying, bytes32 _l2TokenAddress) external {
19+
function initialize(address _registry, address _underlying, bytes32 _l2Bridge) external {
2020
registry = IRegistry(_registry);
2121
underlying = IERC20(_underlying);
22-
l2TokenAddress = _l2TokenAddress;
22+
l2Bridge = _l2Bridge;
2323
}
2424

2525
/**
2626
* @notice Deposit funds into the portal and adds an L2 message which can only be consumed publicly on Aztec
2727
* @param _to - The aztec address of the recipient
2828
* @param _amount - The amount to deposit
29-
* @param _canceller - The address that can cancel the L1 to L2 message
30-
* @param _deadline - The timestamp after which the entry can be cancelled
3129
* @param _secretHash - The hash of the secret consumable message. The hash should be 254 bits (so it can fit in a Field element)
3230
* @return The key of the entry in the Inbox
3331
*/
34-
function depositToAztecPublic(
35-
bytes32 _to,
36-
uint256 _amount,
37-
address _canceller,
38-
uint32 _deadline,
39-
bytes32 _secretHash
40-
) external payable returns (bytes32) {
32+
function depositToAztecPublic(bytes32 _to, uint256 _amount, bytes32 _secretHash)
33+
external
34+
returns (bytes32)
35+
{
4136
// Preamble
4237
IInbox inbox = registry.getInbox();
43-
DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2TokenAddress, 1);
38+
DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2Bridge, 1);
4439

4540
// Hash the message content to be reconstructed in the receiving contract
46-
bytes32 contentHash = Hash.sha256ToField(
47-
abi.encodeWithSignature("mint_public(bytes32,uint256,address)", _to, _amount, _canceller)
48-
);
41+
bytes32 contentHash =
42+
Hash.sha256ToField(abi.encodeWithSignature("mint_public(bytes32,uint256)", _to, _amount));
4943

5044
// Hold the tokens in the portal
5145
underlying.safeTransferFrom(msg.sender, address(this), _amount);
5246

5347
// Send message to rollup
54-
return inbox.sendL2Message{value: msg.value}(actor, _deadline, contentHash, _secretHash);
48+
return inbox.sendL2Message(actor, contentHash, _secretHash);
5549
}
5650

5751
/**
5852
* @notice Deposit funds into the portal and adds an L2 message which can only be consumed privately on Aztec
5953
* @param _secretHashForRedeemingMintedNotes - The hash of the secret to redeem minted notes privately on Aztec. The hash should be 254 bits (so it can fit in a Field element)
6054
* @param _amount - The amount to deposit
61-
* @param _canceller - The address that can cancel the L1 to L2 message
62-
* @param _deadline - The timestamp after which the entry can be cancelled
6355
* @param _secretHashForL2MessageConsumption - The hash of the secret consumable L1 to L2 message. The hash should be 254 bits (so it can fit in a Field element)
6456
* @return The key of the entry in the Inbox
6557
*/
6658
function depositToAztecPrivate(
6759
bytes32 _secretHashForRedeemingMintedNotes,
6860
uint256 _amount,
69-
address _canceller,
70-
uint32 _deadline,
7161
bytes32 _secretHashForL2MessageConsumption
72-
) external payable returns (bytes32) {
62+
) external returns (bytes32) {
7363
// Preamble
7464
IInbox inbox = registry.getInbox();
75-
DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2TokenAddress, 1);
65+
DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2Bridge, 1);
7666

7767
// Hash the message content to be reconstructed in the receiving contract
7868
bytes32 contentHash = Hash.sha256ToField(
7969
abi.encodeWithSignature(
80-
"mint_private(bytes32,uint256,address)",
81-
_secretHashForRedeemingMintedNotes,
82-
_amount,
83-
_canceller
70+
"mint_private(bytes32,uint256)", _secretHashForRedeemingMintedNotes, _amount
8471
)
8572
);
8673

8774
// Hold the tokens in the portal
8875
underlying.safeTransferFrom(msg.sender, address(this), _amount);
8976

9077
// Send message to rollup
91-
return inbox.sendL2Message{value: msg.value}(
92-
actor, _deadline, contentHash, _secretHashForL2MessageConsumption
93-
);
78+
return inbox.sendL2Message(actor, contentHash, _secretHashForL2MessageConsumption);
9479
}
9580

96-
/**
97-
* @notice Cancel a public depositToAztec L1 to L2 message
98-
* @dev only callable by the `canceller` of the message
99-
* @param _to - The aztec address of the recipient in the original message
100-
* @param _amount - The amount to deposit per the original message
101-
* @param _deadline - The timestamp after which the entry can be cancelled
102-
* @param _secretHash - The hash of the secret consumable message in the original message
103-
* @param _fee - The fee paid to the sequencer
104-
* @return The key of the entry in the Inbox
105-
*/
106-
function cancelL1ToAztecMessagePublic(
107-
bytes32 _to,
108-
uint256 _amount,
109-
uint32 _deadline,
110-
bytes32 _secretHash,
111-
uint64 _fee
112-
) external returns (bytes32) {
113-
IInbox inbox = registry.getInbox();
114-
DataStructures.L1Actor memory l1Actor = DataStructures.L1Actor(address(this), block.chainid);
115-
DataStructures.L2Actor memory l2Actor = DataStructures.L2Actor(l2TokenAddress, 1);
116-
DataStructures.L1ToL2Msg memory message = DataStructures.L1ToL2Msg({
117-
sender: l1Actor,
118-
recipient: l2Actor,
119-
content: Hash.sha256ToField(
120-
abi.encodeWithSignature("mint_public(bytes32,uint256,address)", _to, _amount, msg.sender)
121-
),
122-
secretHash: _secretHash,
123-
deadline: _deadline,
124-
fee: _fee
125-
});
126-
bytes32 entryKey = inbox.cancelL2Message(message, address(this));
127-
// release the funds to msg.sender (since the content hash (& entry key) is derived by hashing the caller,
128-
// we confirm that msg.sender is same as `_canceller` supplied when creating the message)
129-
underlying.transfer(msg.sender, _amount);
130-
return entryKey;
131-
}
132-
133-
/**
134-
* @notice Cancel a private depositToAztec L1 to L2 message
135-
* @dev only callable by the `canceller` of the message
136-
* @param _secretHashForRedeemingMintedNotes - The hash of the secret to redeem minted notes privately on Aztec
137-
* @param _amount - The amount to deposit per the original message
138-
* @param _deadline - The timestamp after which the entry can be cancelled
139-
* @param _secretHashForL2MessageConsumption - The hash of the secret consumable L1 to L2 message
140-
* @param _fee - The fee paid to the sequencer
141-
* @return The key of the entry in the Inbox
142-
*/
143-
function cancelL1ToAztecMessagePrivate(
144-
bytes32 _secretHashForRedeemingMintedNotes,
145-
uint256 _amount,
146-
uint32 _deadline,
147-
bytes32 _secretHashForL2MessageConsumption,
148-
uint64 _fee
149-
) external returns (bytes32) {
150-
IInbox inbox = registry.getInbox();
151-
DataStructures.L1Actor memory l1Actor = DataStructures.L1Actor(address(this), block.chainid);
152-
DataStructures.L2Actor memory l2Actor = DataStructures.L2Actor(l2TokenAddress, 1);
153-
DataStructures.L1ToL2Msg memory message = DataStructures.L1ToL2Msg({
154-
sender: l1Actor,
155-
recipient: l2Actor,
156-
content: Hash.sha256ToField(
157-
abi.encodeWithSignature(
158-
"mint_private(bytes32,uint256,address)",
159-
_secretHashForRedeemingMintedNotes,
160-
_amount,
161-
msg.sender
162-
)
163-
),
164-
secretHash: _secretHashForL2MessageConsumption,
165-
deadline: _deadline,
166-
fee: _fee
167-
});
168-
bytes32 entryKey = inbox.cancelL2Message(message, address(this));
169-
// release the funds to msg.sender (since the content hash (& entry key) is derived by hashing the caller,
170-
// we confirm that msg.sender is same as `_canceller` supplied when creating the message)
171-
underlying.transfer(msg.sender, _amount);
172-
return entryKey;
173-
}
174-
175-
17681
/**
17782
* @notice Withdraw funds from the portal
17883
* @dev Second part of withdraw, must be initiated from L2 first as it will consume a message from outbox
@@ -187,7 +92,7 @@ contract TokenPortal {
18792
returns (bytes32)
18893
{
18994
DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({
190-
sender: DataStructures.L2Actor(l2TokenAddress, 1),
95+
sender: DataStructures.L2Actor(l2Bridge, 1),
19196
recipient: DataStructures.L1Actor(address(this), block.chainid),
19297
content: Hash.sha256ToField(
19398
abi.encodeWithSignature(

tutorials/uniswap-integration-e2e/packages/l1-contracts/contracts/TokenPortal.sol

Lines changed: 16 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -14,165 +14,70 @@ contract TokenPortal {
1414

1515
IRegistry public registry;
1616
IERC20 public underlying;
17-
bytes32 public l2TokenAddress;
17+
bytes32 public l2Bridge;
1818

19-
function initialize(address _registry, address _underlying, bytes32 _l2TokenAddress) external {
19+
function initialize(address _registry, address _underlying, bytes32 _l2Bridge) external {
2020
registry = IRegistry(_registry);
2121
underlying = IERC20(_underlying);
22-
l2TokenAddress = _l2TokenAddress;
22+
l2Bridge = _l2Bridge;
2323
}
2424

2525
/**
2626
* @notice Deposit funds into the portal and adds an L2 message which can only be consumed publicly on Aztec
2727
* @param _to - The aztec address of the recipient
2828
* @param _amount - The amount to deposit
29-
* @param _canceller - The address that can cancel the L1 to L2 message
30-
* @param _deadline - The timestamp after which the entry can be cancelled
3129
* @param _secretHash - The hash of the secret consumable message. The hash should be 254 bits (so it can fit in a Field element)
3230
* @return The key of the entry in the Inbox
3331
*/
34-
function depositToAztecPublic(
35-
bytes32 _to,
36-
uint256 _amount,
37-
address _canceller,
38-
uint32 _deadline,
39-
bytes32 _secretHash
40-
) external payable returns (bytes32) {
32+
function depositToAztecPublic(bytes32 _to, uint256 _amount, bytes32 _secretHash)
33+
external
34+
returns (bytes32)
35+
{
4136
// Preamble
4237
IInbox inbox = registry.getInbox();
43-
DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2TokenAddress, 1);
38+
DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2Bridge, 1);
4439

4540
// Hash the message content to be reconstructed in the receiving contract
46-
bytes32 contentHash = Hash.sha256ToField(
47-
abi.encodeWithSignature("mint_public(bytes32,uint256,address)", _to, _amount, _canceller)
48-
);
41+
bytes32 contentHash =
42+
Hash.sha256ToField(abi.encodeWithSignature("mint_public(bytes32,uint256)", _to, _amount));
4943

5044
// Hold the tokens in the portal
5145
underlying.safeTransferFrom(msg.sender, address(this), _amount);
5246

5347
// Send message to rollup
54-
return inbox.sendL2Message{value: msg.value}(actor, _deadline, contentHash, _secretHash);
48+
return inbox.sendL2Message(actor, contentHash, _secretHash);
5549
}
5650

5751
/**
5852
* @notice Deposit funds into the portal and adds an L2 message which can only be consumed privately on Aztec
5953
* @param _secretHashForRedeemingMintedNotes - The hash of the secret to redeem minted notes privately on Aztec. The hash should be 254 bits (so it can fit in a Field element)
6054
* @param _amount - The amount to deposit
61-
* @param _canceller - The address that can cancel the L1 to L2 message
62-
* @param _deadline - The timestamp after which the entry can be cancelled
6355
* @param _secretHashForL2MessageConsumption - The hash of the secret consumable L1 to L2 message. The hash should be 254 bits (so it can fit in a Field element)
6456
* @return The key of the entry in the Inbox
6557
*/
6658
function depositToAztecPrivate(
6759
bytes32 _secretHashForRedeemingMintedNotes,
6860
uint256 _amount,
69-
address _canceller,
70-
uint32 _deadline,
7161
bytes32 _secretHashForL2MessageConsumption
72-
) external payable returns (bytes32) {
62+
) external returns (bytes32) {
7363
// Preamble
7464
IInbox inbox = registry.getInbox();
75-
DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2TokenAddress, 1);
65+
DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2Bridge, 1);
7666

7767
// Hash the message content to be reconstructed in the receiving contract
7868
bytes32 contentHash = Hash.sha256ToField(
7969
abi.encodeWithSignature(
80-
"mint_private(bytes32,uint256,address)",
81-
_secretHashForRedeemingMintedNotes,
82-
_amount,
83-
_canceller
70+
"mint_private(bytes32,uint256)", _secretHashForRedeemingMintedNotes, _amount
8471
)
8572
);
8673

8774
// Hold the tokens in the portal
8875
underlying.safeTransferFrom(msg.sender, address(this), _amount);
8976

9077
// Send message to rollup
91-
return inbox.sendL2Message{value: msg.value}(
92-
actor, _deadline, contentHash, _secretHashForL2MessageConsumption
93-
);
78+
return inbox.sendL2Message(actor, contentHash, _secretHashForL2MessageConsumption);
9479
}
9580

96-
/**
97-
* @notice Cancel a public depositToAztec L1 to L2 message
98-
* @dev only callable by the `canceller` of the message
99-
* @param _to - The aztec address of the recipient in the original message
100-
* @param _amount - The amount to deposit per the original message
101-
* @param _deadline - The timestamp after which the entry can be cancelled
102-
* @param _secretHash - The hash of the secret consumable message in the original message
103-
* @param _fee - The fee paid to the sequencer
104-
* @return The key of the entry in the Inbox
105-
*/
106-
function cancelL1ToAztecMessagePublic(
107-
bytes32 _to,
108-
uint256 _amount,
109-
uint32 _deadline,
110-
bytes32 _secretHash,
111-
uint64 _fee
112-
) external returns (bytes32) {
113-
IInbox inbox = registry.getInbox();
114-
DataStructures.L1Actor memory l1Actor = DataStructures.L1Actor(address(this), block.chainid);
115-
DataStructures.L2Actor memory l2Actor = DataStructures.L2Actor(l2TokenAddress, 1);
116-
DataStructures.L1ToL2Msg memory message = DataStructures.L1ToL2Msg({
117-
sender: l1Actor,
118-
recipient: l2Actor,
119-
content: Hash.sha256ToField(
120-
abi.encodeWithSignature("mint_public(bytes32,uint256,address)", _to, _amount, msg.sender)
121-
),
122-
secretHash: _secretHash,
123-
deadline: _deadline,
124-
fee: _fee
125-
});
126-
bytes32 entryKey = inbox.cancelL2Message(message, address(this));
127-
// release the funds to msg.sender (since the content hash (& entry key) is derived by hashing the caller,
128-
// we confirm that msg.sender is same as `_canceller` supplied when creating the message)
129-
underlying.transfer(msg.sender, _amount);
130-
return entryKey;
131-
}
132-
133-
/**
134-
* @notice Cancel a private depositToAztec L1 to L2 message
135-
* @dev only callable by the `canceller` of the message
136-
* @param _secretHashForRedeemingMintedNotes - The hash of the secret to redeem minted notes privately on Aztec
137-
* @param _amount - The amount to deposit per the original message
138-
* @param _deadline - The timestamp after which the entry can be cancelled
139-
* @param _secretHashForL2MessageConsumption - The hash of the secret consumable L1 to L2 message
140-
* @param _fee - The fee paid to the sequencer
141-
* @return The key of the entry in the Inbox
142-
*/
143-
function cancelL1ToAztecMessagePrivate(
144-
bytes32 _secretHashForRedeemingMintedNotes,
145-
uint256 _amount,
146-
uint32 _deadline,
147-
bytes32 _secretHashForL2MessageConsumption,
148-
uint64 _fee
149-
) external returns (bytes32) {
150-
IInbox inbox = registry.getInbox();
151-
DataStructures.L1Actor memory l1Actor = DataStructures.L1Actor(address(this), block.chainid);
152-
DataStructures.L2Actor memory l2Actor = DataStructures.L2Actor(l2TokenAddress, 1);
153-
DataStructures.L1ToL2Msg memory message = DataStructures.L1ToL2Msg({
154-
sender: l1Actor,
155-
recipient: l2Actor,
156-
content: Hash.sha256ToField(
157-
abi.encodeWithSignature(
158-
"mint_private(bytes32,uint256,address)",
159-
_secretHashForRedeemingMintedNotes,
160-
_amount,
161-
msg.sender
162-
)
163-
),
164-
secretHash: _secretHashForL2MessageConsumption,
165-
deadline: _deadline,
166-
fee: _fee
167-
});
168-
bytes32 entryKey = inbox.cancelL2Message(message, address(this));
169-
// release the funds to msg.sender (since the content hash (& entry key) is derived by hashing the caller,
170-
// we confirm that msg.sender is same as `_canceller` supplied when creating the message)
171-
underlying.transfer(msg.sender, _amount);
172-
return entryKey;
173-
}
174-
175-
17681
/**
17782
* @notice Withdraw funds from the portal
17883
* @dev Second part of withdraw, must be initiated from L2 first as it will consume a message from outbox
@@ -187,7 +92,7 @@ contract TokenPortal {
18792
returns (bytes32)
18893
{
18994
DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({
190-
sender: DataStructures.L2Actor(l2TokenAddress, 1),
95+
sender: DataStructures.L2Actor(l2Bridge, 1),
19196
recipient: DataStructures.L1Actor(address(this), block.chainid),
19297
content: Hash.sha256ToField(
19398
abi.encodeWithSignature(

0 commit comments

Comments
 (0)