Skip to content

Commit

Permalink
fix: update paymaster and token contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
danijelTxFusion committed Jan 26, 2024
1 parent 412fa47 commit 7c24ae2
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 23 deletions.
2 changes: 1 addition & 1 deletion go/17_deploy_create_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
var (
PrivateKey = os.Getenv("PRIVATE_KEY")
ZkSyncEraProvider = "https://sepolia.era.zksync.dev"
TokenAddress = "0xA70dF8446A6AeA0017D60e97e816e141aa28759b" // Crown token which can be minted for free
TokenAddress = "0x927488F48ffbc32112F1fF721759649A89721F8F" // Crown token which can be minted for free
)

// Connect to zkSync network
Expand Down
2 changes: 1 addition & 1 deletion go/18_deploy_create2_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
var (
PrivateKey = os.Getenv("PRIVATE_KEY")
ZkSyncEraProvider = "https://sepolia.era.zksync.dev"
TokenAddress = "0xA70dF8446A6AeA0017D60e97e816e141aa28759b" // Crown token which can be minted for free
TokenAddress = "0x927488F48ffbc32112F1fF721759649A89721F8F" // Crown token which can be minted for free
)

// Connect to zkSync network
Expand Down
4 changes: 2 additions & 2 deletions go/19_use_paymaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func main() {
var (
PrivateKey = os.Getenv("PRIVATE_KEY")
ZkSyncEraProvider = "https://sepolia.era.zksync.dev"
TokenAddress = common.HexToAddress("0xA70dF8446A6AeA0017D60e97e816e141aa28759b") // Crown token which can be minted for free
PaymasterAddress = common.HexToAddress("0x57F48f0d845E0ed7C9Bf066cEbFF64FbeBE6AFEF") // Paymaster for Crown token
TokenAddress = common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") // Crown token which can be minted for free
PaymasterAddress = common.HexToAddress("0x13D0D8550769f59aa241a41897D4859c87f7Dd46") // Paymaster for Crown token
)

// Connect to zkSync network
Expand Down
2 changes: 1 addition & 1 deletion js/src/16_deploy_create_account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const provider = Provider.getDefaultProvider(types.Network.Sepolia);
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const wallet = new Wallet(PRIVATE_KEY, provider);

const tokenAddress = "0xA70dF8446A6AeA0017D60e97e816e141aa28759b";
const tokenAddress = "0x927488F48ffbc32112F1fF721759649A89721F8F";

async function main() {
const conf = require("../../solidity/custom_paymaster/paymaster/build/Paymaster.json");
Expand Down
2 changes: 1 addition & 1 deletion js/src/17_deploy_create2_account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const provider = Provider.getDefaultProvider(types.Network.Sepolia);
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const wallet = new Wallet(PRIVATE_KEY, provider);

const tokenAddress = "0xA70dF8446A6AeA0017D60e97e816e141aa28759b";
const tokenAddress = "0x927488F48ffbc32112F1fF721759649A89721F8F";

async function main() {
const conf = require("../../solidity/custom_paymaster/paymaster/build/Paymaster.json");
Expand Down
4 changes: 2 additions & 2 deletions js/src/18_use_paymaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const ethProvider = ethers.getDefaultProvider("sepolia");
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);

const tokenAddress = "0xA70dF8446A6AeA0017D60e97e816e141aa28759b"; // Crown token which can be minted for free
const paymasterAddress = "0x57F48f0d845E0ed7C9Bf066cEbFF64FbeBE6AFEF"; // Paymaster for Crown token
const tokenAddress = "0x927488F48ffbc32112F1fF721759649A89721F8F"; // Crown token which can be minted for free
const paymasterAddress = "0x13D0D8550769f59aa241a41897D4859c87f7Dd46"; // Paymaster for Crown token
const token = new ethers.Interface(
require("../../solidity/custom_paymaster/token/build/Token.json").abi,
);
Expand Down
2 changes: 1 addition & 1 deletion python/13_deploy_account_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def deploy_account(
contract_path = Path("../solidity/custom_paymaster/paymaster/build/Paymaster.json")

# Crown token than can be minted for free
token_address = zk_web3.to_checksum_address("0xA70dF8446A6AeA0017D60e97e816e141aa28759b")
token_address = zk_web3.to_checksum_address("0x927488F48ffbc32112F1fF721759649A89721F8F")
constructor_arguments = {"_erc20": token_address}

# Perform contract deployment
Expand Down
2 changes: 1 addition & 1 deletion python/14_deploy_account_create2.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def deploy_account(
contract_path = Path("../solidity/custom_paymaster/paymaster/build/Paymaster.json")

# Crown token than can be minted for free
token_address = zk_web3.to_checksum_address("0xA70dF8446A6AeA0017D60e97e816e141aa28759b")
token_address = zk_web3.to_checksum_address("0x927488F48ffbc32112F1fF721759649A89721F8F")
constructor_arguments = {"_erc20": token_address}

# Perform contract deployment
Expand Down
4 changes: 2 additions & 2 deletions python/15_use_paymaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def get_abi_from_standard_json(standard_json: Path):
account: LocalAccount = Account.from_key(PRIVATE_KEY)

# Crown token than can be minted for free
token_address = zk_web3.to_checksum_address("0xA70dF8446A6AeA0017D60e97e816e141aa28759b")
token_address = zk_web3.to_checksum_address("0x927488F48ffbc32112F1fF721759649A89721F8F")
# Paymaster for Crown token
paymaster_address = zk_web3.to_checksum_address("0x57F48f0d845E0ed7C9Bf066cEbFF64FbeBE6AFEF")
paymaster_address = zk_web3.to_checksum_address("0x13D0D8550769f59aa241a41897D4859c87f7Dd46")

# Provide a compiled JSON source contract
contract_path = Path("../solidity/custom_paymaster/token/build/Token.json")
Expand Down
21 changes: 14 additions & 7 deletions solidity/custom_paymaster/paymaster/Paymaster.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

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";

contract MyPaymaster is IPaymaster {
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

/// @author Matter Labs
/// @notice This smart contract pays the gas fees for accounts with balance of a specific ERC20 token. It makes use of the approval-based flow paymaster.
contract ApprovalPaymaster is IPaymaster, Ownable {
uint256 constant PRICE_FOR_PAYING_FEES = 1;

address public allowedToken;
Expand Down Expand Up @@ -47,6 +50,7 @@ contract MyPaymaster is IPaymaster {
bytes4 paymasterInputSelector = bytes4(
_transaction.paymasterInput[0:4]
);
// Approval based flow
if (paymasterInputSelector == IPaymasterFlow.approvalBased.selector) {
// While the transaction data consists of address, uint256 and bytes data,
// the data is not needed for this paymaster
Expand Down Expand Up @@ -75,7 +79,7 @@ contract MyPaymaster is IPaymaster {
// 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;
_transaction.maxFeePerGas;

try
IERC20(token).transferFrom(userAddress, thisAddress, amount)
Expand Down Expand Up @@ -111,9 +115,12 @@ contract MyPaymaster is IPaymaster {
bytes32,
ExecutionResult _txResult,
uint256 _maxRefundedGas
) external payable override onlyBootloader {
// Refunds are not supported yet.
) external payable override onlyBootloader {}

function withdraw(address _to) external onlyOwner {
(bool success, ) = payable(_to).call{value: address(this).balance}("");
require(success, "Failed to withdraw funds from paymaster.");
}

receive() external payable {}
}
}
73 changes: 69 additions & 4 deletions solidity/custom_paymaster/paymaster/build/Paymaster.json

Large diffs are not rendered by default.

0 comments on commit 7c24ae2

Please sign in to comment.