-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: auth server and sdk when not using sessions (#45)
- Loading branch information
1 parent
412382f
commit b9afdc3
Showing
14 changed files
with
575 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ logs | |
.env | ||
.env.* | ||
!.env.example | ||
forge-output.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
/// !!! !!! | ||
/// !!! THIS IS FOR DEMO PURPOSES ONLY !!! | ||
/// !!! !!! | ||
/// !!! DO NOT COPY THIS PAYMASTER !!! | ||
/// !!! FOR PRODUCTION APPLICATIONS !!! | ||
/// !!! !!! | ||
/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
||
import { IPaymaster, ExecutionResult, PAYMASTER_VALIDATION_SUCCESS_MAGIC } from "@matterlabs/zksync-contracts/l2/system-contracts/interfaces/IPaymaster.sol"; | ||
import { IPaymasterFlow } from "@matterlabs/zksync-contracts/l2/system-contracts/interfaces/IPaymasterFlow.sol"; | ||
import { TransactionHelper, Transaction } from "@matterlabs/zksync-contracts/l2/system-contracts/libraries/TransactionHelper.sol"; | ||
|
||
import "@matterlabs/zksync-contracts/l2/system-contracts/Constants.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @notice DO NOT USE THIS FOR PRODUCTION. This contract does not include any validations other than using the paymaster general flow. | ||
contract DemoPaymaster is IPaymaster { | ||
modifier onlyBootloader() { | ||
require(msg.sender == BOOTLOADER_FORMAL_ADDRESS, "Only bootloader can call this method"); | ||
// Continue execution if called from the bootloader. | ||
_; | ||
} | ||
|
||
function validateAndPayForPaymasterTransaction( | ||
bytes32, | ||
bytes32, | ||
Transaction calldata _transaction | ||
) external payable onlyBootloader returns (bytes4 magic, bytes memory context) { | ||
// By default we consider the transaction as accepted. | ||
magic = PAYMASTER_VALIDATION_SUCCESS_MAGIC; | ||
require(_transaction.paymasterInput.length >= 4, "The standard paymaster input must be at least 4 bytes long"); | ||
|
||
bytes4 paymasterInputSelector = bytes4(_transaction.paymasterInput[0:4]); | ||
require(paymasterInputSelector == IPaymasterFlow.general.selector, "Unsupported paymaster flow"); | ||
|
||
// Note, that while the minimal amount of ETH needed is tx.gasPrice * tx.gasLimit, | ||
// neither paymaster nor account are allowed to access this context variable. | ||
uint256 requiredETH = _transaction.gasLimit * _transaction.maxFeePerGas; | ||
|
||
// The bootloader never returns any data, so it can safely be ignored here. | ||
(bool success, ) = payable(BOOTLOADER_FORMAL_ADDRESS).call{ value: requiredETH }(""); | ||
require(success, "Failed to transfer tx fee to the Bootloader. Paymaster balance might not be enough."); | ||
} | ||
|
||
function postTransaction( | ||
bytes calldata _context, | ||
Transaction calldata _transaction, | ||
bytes32, | ||
bytes32, | ||
ExecutionResult _txResult, | ||
uint256 _maxRefundedGas | ||
) external payable override onlyBootloader {} | ||
|
||
function withdraw(address payable _to) external { | ||
uint256 balance = address(this).balance; | ||
(bool success, ) = _to.call{ value: balance }(""); | ||
require(success, "Failed to withdraw funds from paymaster."); | ||
} | ||
|
||
receive() external payable {} | ||
} |
Oops, something went wrong.