Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add(sepolia): as the main testnet #18

Merged
merged 4 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1 @@
WALLET_PRIVATE_KEY=
WALLET_PRIVATE_KEY=
6 changes: 5 additions & 1 deletion contracts/deploy/allowListPaymaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { Provider, Wallet } from "zksync-web3";
import * as ethers from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { HttpNetworkUserConfig } from "hardhat/types";

// load env file
import dotenv from "dotenv";

dotenv.config();

// load wallet private key from env file
Expand All @@ -15,7 +17,9 @@ if (!PRIVATE_KEY)

export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the AllowlistPaymaster contract...`);
const provider = new Provider("https://testnet.era.zksync.dev");
// Currently targeting the Sepolia zkSync testnet
const network = hre.userConfig.networks?.zkSyncTestnet;
const provider = new Provider((network as HttpNetworkUserConfig).url);

// The wallet that will deploy the token and the paymaster
// It is assumed that this wallet already has sufficient funds on zkSync
Expand Down
8 changes: 3 additions & 5 deletions contracts/deploy/erc20.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Provider, Wallet } from "zksync-web3";
import * as ethers from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";

import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Wallet } from "zksync-web3";
// load env file
import dotenv from "dotenv";

dotenv.config();

// load wallet private key from env file
Expand All @@ -20,8 +20,6 @@ if (!RECIPIENT_ADDRESS)

export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the MyERC20 contract...`);
const provider = new Provider("https://testnet.era.zksync.dev");
AlbionaHoti marked this conversation as resolved.
Show resolved Hide resolved

// The wallet that will deploy the token and the paymaster
// It is assumed that this wallet already has sufficient funds on zkSync
const wallet = new Wallet(PRIVATE_KEY);
Expand Down
12 changes: 9 additions & 3 deletions contracts/deploy/erc20fixedPaymaster.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { Provider, Wallet } from "zksync-web3";
import * as ethers from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Provider, Wallet } from "zksync-web3";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import {
HardhatRuntimeEnvironment,
HttpNetworkUserConfig,
} from "hardhat/types";

// load env file
import dotenv from "dotenv";

dotenv.config();

// load wallet private key from env file
Expand All @@ -20,7 +24,9 @@ if (!TOKEN_ADDRESS)

export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the ERC20fixedPaymaster contract...`);
const provider = new Provider("https://testnet.era.zksync.dev");
// Currently targeting the Sepolia zkSync testnet
const network = hre.userConfig.networks?.zkSyncTestnet;
const provider = new Provider((network as HttpNetworkUserConfig).url);
// The wallet that will deploy the token and the paymaster
// It is assumed that this wallet already has sufficient funds on zkSync
const wallet = new Wallet(PRIVATE_KEY);
Expand Down
7 changes: 3 additions & 4 deletions contracts/deploy/erc721.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Provider, Wallet } from "zksync-web3";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Wallet } from "zksync-web3";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";

import { HardhatRuntimeEnvironment } from "hardhat/types";
// load env file
import dotenv from "dotenv";

dotenv.config();

// load wallet private key from env file
Expand All @@ -19,7 +19,6 @@ if (!RECIPIENT_ADDRESS)

export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the MyNFT contract...`);
const provider = new Provider("https://testnet.era.zksync.dev");

// The wallet that will deploy the token and the paymaster
// It is assumed that this wallet already has sufficient funds on zkSync
Expand Down
13 changes: 9 additions & 4 deletions contracts/deploy/erc721gatedPaymaster.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Provider, Wallet } from "zksync-web3";
import * as ethers from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Provider, Wallet } from "zksync-web3";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";

import {
HardhatRuntimeEnvironment,
HttpNetworkUserConfig,
} from "hardhat/types";
// load env file
import dotenv from "dotenv";

dotenv.config();

// load wallet private key from env file
Expand All @@ -20,7 +23,9 @@ if (!NFT_COLLECTION_ADDRESS)

export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the ERC721gatedPaymaster contract...`);
const provider = new Provider("https://testnet.era.zksync.dev");
// Currently targeting the Sepolia zkSync testnet
const network = hre.userConfig.networks?.zkSyncTestnet;
const provider = new Provider((network as HttpNetworkUserConfig).url);

// The wallet that will deploy the token and the paymaster
// It is assumed that this wallet already has sufficient funds on zkSync
Expand Down
14 changes: 9 additions & 5 deletions contracts/deploy/gaslessPaymaster.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Provider, Wallet } from "zksync-web3";
import * as ethers from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Provider, Wallet } from "zksync-web3";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";

import {
HardhatRuntimeEnvironment,
HttpNetworkUserConfig,
} from "hardhat/types";
// load env file
import dotenv from "dotenv";

dotenv.config();

// load wallet private key from env file
Expand All @@ -15,8 +18,9 @@ if (!PRIVATE_KEY)

export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the GaslessPaymaster contract...`);
const provider = new Provider("https://testnet.era.zksync.dev");

// Currently targeting the Sepolia zkSync testnet
const network = hre.userConfig.networks?.zkSyncTestnet;
const provider = new Provider((network as HttpNetworkUserConfig).url);
// The wallet that will deploy the token and the paymaster
// It is assumed that this wallet already has sufficient funds on zkSync
const wallet = new Wallet(PRIVATE_KEY);
Expand Down
2 changes: 1 addition & 1 deletion contracts/deploy/greeter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Wallet, utils } from "zksync-web3";
import { Wallet } from "zksync-web3";
import * as ethers from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
Expand Down
13 changes: 9 additions & 4 deletions contracts/deploy/timeBasedPaymaster.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Provider, Wallet } from "zksync-web3";
import * as ethers from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Provider, Wallet } from "zksync-web3";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";

import {
HardhatRuntimeEnvironment,
HttpNetworkUserConfig,
} from "hardhat/types";
// load env file
import dotenv from "dotenv";

dotenv.config();

// load wallet private key from env file
Expand All @@ -15,7 +18,9 @@ if (!PRIVATE_KEY)

export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the TimeBasedPaymaster contract...`);
const provider = new Provider("https://testnet.era.zksync.dev");
// Currently targeting the Sepolia zkSync testnet
const network = hre.userConfig.networks?.zkSyncTestnet;
const provider = new Provider((network as HttpNetworkUserConfig).url);

const wallet = new Wallet(PRIVATE_KEY);
const deployer = new Deployer(hre, wallet);
Expand Down
2 changes: 1 addition & 1 deletion contracts/deploy/use-greeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import dotenv from "dotenv";
dotenv.config();

// load contract artifact. Make sure to compile first!
import * as ContractArtifact from "../artifacts-zk/contracts/Greeter.sol/Greeter.json";
import * as ContractArtifact from "../artifacts-zk/contracts/utils/Greeter.sol/Greeter.json";

const PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY || "";

Expand Down
52 changes: 19 additions & 33 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,9 @@
import { HardhatUserConfig } from "hardhat/config";

import "@matterlabs/hardhat-zksync-deploy";
import "@matterlabs/hardhat-zksync-solc";
import "@matterlabs/hardhat-zksync-verify";
import "@nomiclabs/hardhat-etherscan";

const getNetworkConfig = () => {
const env = process.env.DEPLOY_ENV || "local";
switch (env) {
case "local":
return {
url: "http://localhost:3050",
ethNetwork: "http://localhost:8545",
zksync: true,
};
case "ci":
return {
url: "http://127.0.0.1:8011",
ethNetwork: "goerli",
zksync: true,
};
case "testnet":
return {
url: "https://zksync2-testnet.zksync.dev",
ethNetwork: "goerli",
zksync: true,
// Verification endpoint for Goerli
verifyURL:
"https://zksync2-testnet-explorer.zksync.dev/contract_verification",
};
default:
throw new Error(`Unsupported DEPLOY_ENV: ${env}`);
}
};

const networkConfig = getNetworkConfig();
import { HardhatUserConfig } from "hardhat/config";

const config: HardhatUserConfig = {
zksolc: {
Expand All @@ -46,7 +15,24 @@ const config: HardhatUserConfig = {
hardhat: {
zksync: false,
},
zkSyncTestnet: networkConfig,
zkSyncInMemory: {
url: "http://127.0.0.1:8011",
ethNetwork: "sepolia",
zksync: true,
},
zkSyncLocal: {
url: "http://localhost:3050",
ethNetwork: "http://localhost:8545",
zksync: true,
},
zkSyncTestnet: {
url: "https://sepolia.era.zksync.dev",
ethNetwork: "sepolia",
zksync: true,
// Verification endpoint for Sepolia
verifyURL:
"https://explorer.sepolia.era.zksync.dev/contract_verification",
},
},
solidity: {
version: "0.8.17",
Expand Down
4 changes: 2 additions & 2 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"zksync-web3": "^0.14.3"
},
"scripts": {
"test": "NODE_ENV=local hardhat test --network zkSyncTestnet",
"ci:tests": "DEPLOY_ENV=ci hardhat test --network zkSyncTestnet --show-stack-traces",
"test": "hardhat test --network zkSyncInMemory",
"ci:tests": "hardhat test --network zkSyncInMemory --show-stack-traces",
"deploy": "hardhat deploy-zksync",
"greeter": "hardhat deploy-zksync --script greeter.ts",
"gasless": "hardhat deploy-zksync --script gaslessPaymaster.ts",
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/allowlist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("AllowlistPaymaster", function () {
let greeter: Contract;

before(async function () {
const deployUrl = hardhatConfig.networks.zkSyncTestnet.url;
const deployUrl = hardhatConfig.networks.zkSyncInMemory.url;
// setup deployer
[provider, wallet, deployer] = setupDeployer(deployUrl, PRIVATE_KEY);
// setup new wallet
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/erc20fixed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("ERC20fixedPaymaster", function () {
let token: Contract;

before(async function () {
const deployUrl = hardhatConfig.networks.zkSyncTestnet.url;
const deployUrl = hardhatConfig.networks.zkSyncInMemory.url;
// setup deployer
[provider, wallet, deployer] = setupDeployer(deployUrl, PRIVATE_KEY);
// setup new wallet
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/erc721gated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("ERC721gatedPaymaster", function () {
let erc721: Contract;

before(async function () {
const deployUrl = hardhatConfig.networks.zkSyncTestnet.url;
const deployUrl = hardhatConfig.networks.zkSyncInMemory.url;
// setup deployer
[provider, wallet, deployer] = setupDeployer(deployUrl, PRIVATE_KEY);
// setup new wallet
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/gasless.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("GaslessPaymaster", function () {
let greeter: Contract;

before(async function () {
const deployUrl = hardhatConfig.networks.zkSyncTestnet.url;
const deployUrl = hardhatConfig.networks.zkSyncInMemory.url;
// setup deployer
[provider, wallet, deployer] = setupDeployer(deployUrl, PRIVATE_KEY);
// setup new wallet
Expand Down
33 changes: 16 additions & 17 deletions contracts/test/timeBased.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("TimeBasedPaymaster", function () {
let greeter: Contract;

before(async function () {
const deployUrl = hardhatConfig.networks.zkSyncTestnet.url;
const deployUrl = hardhatConfig.networks.zkSyncInMemory.url;
[provider, wallet, deployer] = setupDeployer(deployUrl, PRIVATE_KEY);
userWallet = Wallet.createRandom();
console.log(`User wallet's address: ${userWallet.address}`);
Expand Down Expand Up @@ -55,6 +55,21 @@ describe("TimeBasedPaymaster", function () {
await setGreetingTx.wait();
}

it("should fail due to Paymaster validation error outside the time window", async function () {
// Arrange
let errorOccurred = false;

// Act
try {
await executeGreetingTransaction(wallet);
} catch (error) {
errorOccurred = true;
expect(error.message).to.include("Paymaster validation error");
}
// Assert
expect(errorOccurred).to.be.true;
});

it("should cost the user no gas during the time window", async function () {
// Arrange
const currentDate = new Date();
Expand All @@ -75,20 +90,4 @@ describe("TimeBasedPaymaster", function () {
expect(newBalance.toString()).to.equal(initialBalance.toString());
expect(await greeter.greet()).to.equal("Hola, mundo!");
});

it("should fail due to Paymaster validation error outside the time window", async function () {
// Arrange
let errorOccurred = false;

// Act
try {
await executeGreetingTransaction(wallet);
} catch (error) {
errorOccurred = true;
expect(error.message).to.include("Paymaster validation error");
}

// Assert
expect(errorOccurred).to.be.true;
});
});
2 changes: 1 addition & 1 deletion frontend/src/constants/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export const ERC721_GATED_PAYMASTER = "ERC721Gated Paymaster 🎨";
export const ERC20_GATED_PAYMASTER = "ERC20Fixed Paymaster 🎫";
export const GASLESS_PAYMASTER = "Gasless Paymaster πŸ†“";
export const ALLOWLIST_PAYMASTER = "Allowlist Paymaster πŸ“œ";
export const TESTNET_EXPLORER_URL = "https://goerli.explorer.zksync.io/tx/";
export const TESTNET_EXPLORER_URL = "https://sepolia.explorer.zksync.io/";