Skip to content

Commit

Permalink
fix: don't pay fee first
Browse files Browse the repository at this point in the history
  • Loading branch information
antoncoding committed Nov 3, 2023
1 parent 929b0f7 commit 7f4dbf0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
15 changes: 6 additions & 9 deletions src/gelato/LyraSelfPayingForwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,15 @@ contract LyraSelfPayingForwarder is LyraForwarderBase, GelatoRelayContextERC2771
/**
* @notice Deposit USDC to L2
* @dev Users never have to approve USDC to this contract, we use receiveWithAuthorization to save gas
* @param depositAmount Amount of USDC to deposit
* @param l2Receiver Address of the receiver on L2
* @param minGasLimit Minimum gas limit for the L2 execution
*/
function depositUSDCNativeBridge(
uint256 depositAmount,
uint256 maxERC20Fee,
address l2Receiver,
uint32 minGasLimit,
ReceiveWithAuthData calldata authData
) external onlyGelatoRelayERC2771 {
_transferRelayFeeCapped(maxERC20Fee);

// step 1: receive USDC from user to this contract
IERC3009(usdcLocal).receiveWithAuthorization(
_getMsgSender(),
Expand All @@ -57,7 +53,9 @@ contract LyraSelfPayingForwarder is LyraForwarderBase, GelatoRelayContextERC2771
authData.s
);

uint256 remaining = depositAmount - _getFee();
_transferRelayFeeCapped(maxERC20Fee);

uint256 remaining = authData.value - _getFee();

// step 3: call bridge to L2
IL1StandardBridge(standardBridge).bridgeERC20To(usdcLocal, usdcRemote, l2Receiver, remaining, minGasLimit, "");
Expand All @@ -67,14 +65,11 @@ contract LyraSelfPayingForwarder is LyraForwarderBase, GelatoRelayContextERC2771
* @notice Deposit USDC to L2 through other socket fast bridge. Gas is paid in USDC
*/
function depositUSDCSocketBridge(
uint256 depositAmount,
uint256 maxERC20Fee,
address l2Receiver,
uint32 minGasLimit,
ReceiveWithAuthData calldata authData
) external onlyGelatoRelayERC2771 {
_transferRelayFeeCapped(maxERC20Fee);

// step 1: receive USDC from user to this contract
IERC3009(usdcLocal).receiveWithAuthorization(
_getMsgSender(),
Expand All @@ -88,8 +83,10 @@ contract LyraSelfPayingForwarder is LyraForwarderBase, GelatoRelayContextERC2771
authData.s
);

_transferRelayFeeCapped(maxERC20Fee);

// pay gelato fee
uint256 remaining = depositAmount - _getFee();
uint256 remaining = authData.value - _getFee();

// pay socket protocol fee
uint256 socketFee = ISocketVault(socketVault).getMinFees(socketConnector, minGasLimit);
Expand Down
24 changes: 8 additions & 16 deletions src/gelato/LyraSponsoredForwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@ contract LyraSponsoredForwarder is LyraForwarderBase, ERC2771Context {
* @notice Deposit USDC to L2
* @dev Users never have to approve USDC to this contract, we use receiveWithAuthorization to save gas
*
* @param depositAmount Amount of USDC to deposit
* @param isScwWallet True if user wants to deposit to default LightAccount on L2
* @param minGasLimit Minimum gas limit for the L2 execution
* @param authData Data and signatures for receiveWithAuthorization
*/
function depositUSDCNativeBridge(
uint256 depositAmount,
bool isScwWallet,
uint32 minGasLimit,
ReceiveWithAuthData calldata authData
) external {
function depositUSDCNativeBridge(bool isScwWallet, uint32 minGasLimit, ReceiveWithAuthData calldata authData)
external
{
address msgSender = _msgSender();

IERC3009(usdcLocal).receiveWithAuthorization(
Expand All @@ -60,25 +56,21 @@ contract LyraSponsoredForwarder is LyraForwarderBase, ERC2771Context {

// step 3: call bridge to L2
IL1StandardBridge(standardBridge).bridgeERC20To(
usdcLocal, usdcRemote, _getL2Receiver(msgSender, isScwWallet), depositAmount, minGasLimit, ""
usdcLocal, usdcRemote, _getL2Receiver(msgSender, isScwWallet), authData.value, minGasLimit, ""
);
}

/**
* @notice Deposit USDC to L2 through Socket fast bridge
* @dev Users never have to approve USDC to this contract, we use receiveWithAuthorization to save gas
*
* @param depositAmount Amount of USDC to deposit
* @param isScwWallet True if user wants to deposit to default LightAccount on L2
* @param minGasLimit Minimum gas limit for the L2 execution
* @param authData Data and signatures for receiveWithAuthorization
*/
function depositUSDCSocketBridge(
uint256 depositAmount,
bool isScwWallet,
uint32 minGasLimit,
ReceiveWithAuthData calldata authData
) external {
function depositUSDCSocketBridge(bool isScwWallet, uint32 minGasLimit, ReceiveWithAuthData calldata authData)
external
{
address msgSender = _msgSender();

// step 1: receive USDC from user to this contract
Expand All @@ -97,7 +89,7 @@ contract LyraSponsoredForwarder is LyraForwarderBase, ERC2771Context {
uint256 feeInWei = ISocketVault(socketVault).getMinFees(socketConnector, minGasLimit);

ISocketVault(socketVault).depositToAppChain{value: feeInWei}(
_getL2Receiver(msgSender, isScwWallet), depositAmount, minGasLimit, socketConnector
_getL2Receiver(msgSender, isScwWallet), authData.value, minGasLimit, socketConnector
);
}
}

0 comments on commit 7f4dbf0

Please sign in to comment.