Skip to content

Commit

Permalink
Github Action: Update contract
Browse files Browse the repository at this point in the history
  • Loading branch information
catmcgee committed Mar 27, 2024
1 parent c8fdf1a commit c8ad799
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {SafeERC20} from "@oz/token/ERC20/utils/SafeERC20.sol";
// Messaging
import {IRegistry} from "@aztec/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol";
import {IInbox} from "@aztec/l1-contracts/src/core/interfaces/messagebridge/IInbox.sol";
import {IOutbox} from "@aztec/l1-contracts/src/core/interfaces/messagebridge/IOutbox.sol";
import {DataStructures} from "@aztec/l1-contracts/src/core/libraries/DataStructures.sol";
import {Hash} from "@aztec/l1-contracts/src/core/libraries/Hash.sol";

Expand Down Expand Up @@ -84,13 +85,19 @@ contract TokenPortal {
* @param _recipient - The address to send the funds to
* @param _amount - The amount to withdraw
* @param _withCaller - Flag to use `msg.sender` as caller, otherwise address(0)
* @param _l2BlockNumber - The address to send the funds to
* @param _leafIndex - The amount to withdraw
* @param _path - Flag to use `msg.sender` as caller, otherwise address(0)
* Must match the caller of the message (specified from L2) to consume it.
* @return The key of the entry in the Outbox
*/
function withdraw(address _recipient, uint256 _amount, bool _withCaller)
external
returns (bytes32)
{
function withdraw(
address _recipient,
uint256 _amount,
bool _withCaller,
uint256 _l2BlockNumber,
uint256 _leafIndex,
bytes32[] calldata _path
) external {
DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({
sender: DataStructures.L2Actor(l2Bridge, 1),
recipient: DataStructures.L1Actor(address(this), block.chainid),
Expand All @@ -104,10 +111,10 @@ contract TokenPortal {
)
});

bytes32 entryKey = registry.getOutbox().consume(message);
IOutbox outbox = registry.getOutbox();

underlying.transfer(_recipient, _amount);
outbox.consume(message, _l2BlockNumber, _leafIndex, _path);

return entryKey;
underlying.transfer(_recipient, _amount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {SafeERC20} from "@oz/token/ERC20/utils/SafeERC20.sol";
// Messaging
import {IRegistry} from "@aztec/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol";
import {IInbox} from "@aztec/l1-contracts/src/core/interfaces/messagebridge/IInbox.sol";
import {IOutbox} from "@aztec/l1-contracts/src/core/interfaces/messagebridge/IOutbox.sol";
import {DataStructures} from "@aztec/l1-contracts/src/core/libraries/DataStructures.sol";
import {Hash} from "@aztec/l1-contracts/src/core/libraries/Hash.sol";

Expand Down Expand Up @@ -84,13 +85,19 @@ contract TokenPortal {
* @param _recipient - The address to send the funds to
* @param _amount - The amount to withdraw
* @param _withCaller - Flag to use `msg.sender` as caller, otherwise address(0)
* @param _l2BlockNumber - The address to send the funds to
* @param _leafIndex - The amount to withdraw
* @param _path - Flag to use `msg.sender` as caller, otherwise address(0)
* Must match the caller of the message (specified from L2) to consume it.
* @return The key of the entry in the Outbox
*/
function withdraw(address _recipient, uint256 _amount, bool _withCaller)
external
returns (bytes32)
{
function withdraw(
address _recipient,
uint256 _amount,
bool _withCaller,
uint256 _l2BlockNumber,
uint256 _leafIndex,
bytes32[] calldata _path
) external {
DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({
sender: DataStructures.L2Actor(l2Bridge, 1),
recipient: DataStructures.L1Actor(address(this), block.chainid),
Expand All @@ -104,10 +111,10 @@ contract TokenPortal {
)
});

bytes32 entryKey = registry.getOutbox().consume(message);
IOutbox outbox = registry.getOutbox();

underlying.transfer(_recipient, _amount);
outbox.consume(message, _l2BlockNumber, _leafIndex, _path);

return entryKey;
underlying.transfer(_recipient, _amount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ pragma solidity >=0.8.18;
import {IERC20} from "@oz/token/ERC20/IERC20.sol";

import {IRegistry} from "@aztec/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol";
import {IOutbox} from "@aztec/l1-contracts/src/core/interfaces/messagebridge/IOutbox.sol";
import {DataStructures} from "@aztec/l1-contracts/src/core/libraries/DataStructures.sol";
import {DataStructures as PortalDataStructures} from "./DataStructures.sol";
import {Hash} from "@aztec/l1-contracts/src/core/libraries/Hash.sol";

import {TokenPortal} from "./TokenPortal.sol";
Expand Down Expand Up @@ -48,7 +50,7 @@ contract UniswapPortal {
* @param _aztecRecipient - The aztec address to receive the output assets
* @param _secretHashForL1ToL2Message - The hash of the secret consumable message. The hash should be 254 bits (so it can fit in a Field element)
* @param _withCaller - When true, using `msg.sender` as the caller, otherwise address(0)
* @return The entryKey of the deposit transaction in the Inbox
* @return A hash of the L1 to L2 message inserted in the Inbox
*/
function swapPublic(
address _inputTokenPortal,
Expand All @@ -58,15 +60,27 @@ contract UniswapPortal {
uint256 _amountOutMinimum,
bytes32 _aztecRecipient,
bytes32 _secretHashForL1ToL2Message,
bool _withCaller
bool _withCaller,
// Avoiding stack too deep
PortalDataStructures.OutboxMessageMetadata[2] calldata _outboxMessageMetadata
) public returns (bytes32) {
LocalSwapVars memory vars;

vars.inputAsset = TokenPortal(_inputTokenPortal).underlying();
vars.outputAsset = TokenPortal(_outputTokenPortal).underlying();

// Withdraw the input asset from the portal
TokenPortal(_inputTokenPortal).withdraw(address(this), _inAmount, true);
{
TokenPortal(_inputTokenPortal).withdraw(
address(this),
_inAmount,
true,
_outboxMessageMetadata[0]._l2BlockNumber,
_outboxMessageMetadata[0]._leafIndex,
_outboxMessageMetadata[0]._path
);
}

{
// prevent stack too deep errors
vars.contentHash = Hash.sha256ToField(
Expand All @@ -85,13 +99,20 @@ contract UniswapPortal {
}

// Consume the message from the outbox
registry.getOutbox().consume(
DataStructures.L2ToL1Msg({
sender: DataStructures.L2Actor(l2UniswapAddress, 1),
recipient: DataStructures.L1Actor(address(this), block.chainid),
content: vars.contentHash
})
);
{
IOutbox outbox = registry.getOutbox();

outbox.consume(
DataStructures.L2ToL1Msg({
sender: DataStructures.L2Actor(l2UniswapAddress, 1),
recipient: DataStructures.L1Actor(address(this), block.chainid),
content: vars.contentHash
}),
_outboxMessageMetadata[1]._l2BlockNumber,
_outboxMessageMetadata[1]._leafIndex,
_outboxMessageMetadata[1]._path
);
}

// Perform the swap
ISwapRouter.ExactInputSingleParams memory swapParams;
Expand Down Expand Up @@ -134,7 +155,7 @@ contract UniswapPortal {
* @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)
* @param _secretHashForL1ToL2Message - The hash of the secret consumable message. The hash should be 254 bits (so it can fit in a Field element)
* @param _withCaller - When true, using `msg.sender` as the caller, otherwise address(0)
* @return The entryKey of the deposit transaction in the Inbox
* @return A hash of the L1 to L2 message inserted in the Inbox
*/
function swapPrivate(
address _inputTokenPortal,
Expand All @@ -144,15 +165,26 @@ contract UniswapPortal {
uint256 _amountOutMinimum,
bytes32 _secretHashForRedeemingMintedNotes,
bytes32 _secretHashForL1ToL2Message,
bool _withCaller
bool _withCaller,
// Avoiding stack too deep
PortalDataStructures.OutboxMessageMetadata[2] calldata _outboxMessageMetadata
) public returns (bytes32) {
LocalSwapVars memory vars;

vars.inputAsset = TokenPortal(_inputTokenPortal).underlying();
vars.outputAsset = TokenPortal(_outputTokenPortal).underlying();

// Withdraw the input asset from the portal
TokenPortal(_inputTokenPortal).withdraw(address(this), _inAmount, true);
{
TokenPortal(_inputTokenPortal).withdraw(
address(this),
_inAmount,
true,
_outboxMessageMetadata[0]._l2BlockNumber,
_outboxMessageMetadata[0]._leafIndex,
_outboxMessageMetadata[0]._path
);
}

{
// prevent stack too deep errors
vars.contentHash = Hash.sha256ToField(
Expand All @@ -171,13 +203,20 @@ contract UniswapPortal {
}

// Consume the message from the outbox
registry.getOutbox().consume(
DataStructures.L2ToL1Msg({
sender: DataStructures.L2Actor(l2UniswapAddress, 1),
recipient: DataStructures.L1Actor(address(this), block.chainid),
content: vars.contentHash
})
);
{
IOutbox outbox = registry.getOutbox();

outbox.consume(
DataStructures.L2ToL1Msg({
sender: DataStructures.L2Actor(l2UniswapAddress, 1),
recipient: DataStructures.L1Actor(address(this), block.chainid),
content: vars.contentHash
}),
_outboxMessageMetadata[1]._l2BlockNumber,
_outboxMessageMetadata[1]._leafIndex,
_outboxMessageMetadata[1]._path
);
}

// Perform the swap
ISwapRouter.ExactInputSingleParams memory swapParams;
Expand Down

0 comments on commit c8ad799

Please sign in to comment.