From c253e2ae647d80ddc5e855f5a541e3b09c4a5a1a Mon Sep 17 00:00:00 2001 From: RetricSu Date: Thu, 22 Dec 2022 16:30:26 +0800 Subject: [PATCH 1/5] add simple deploy scripts for gasless --- deploy/deploy-gasless-contract.ts | 49 +++++++++++++++++++++++++++++++ scripts/deploy.ts | 34 +++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 deploy/deploy-gasless-contract.ts create mode 100644 scripts/deploy.ts diff --git a/deploy/deploy-gasless-contract.ts b/deploy/deploy-gasless-contract.ts new file mode 100644 index 000000000..92019ed00 --- /dev/null +++ b/deploy/deploy-gasless-contract.ts @@ -0,0 +1,49 @@ +import { BigNumber } from 'ethers' +import { ethers } from 'hardhat' + +const DEFAULT_UNSTACKED_DELAY_SEC = 86400 +const DEFAULT_PAYMASTER_STAKE = ethers.utils.parseEther('1') + +export const deployEntryPoint = async function (gwFullNodeAddress: string, paymasterStakeInEth?: string, unstackedDelaySec?: number) { + const [admin] = await ethers.getSigners() + const paymasterStake: BigNumber = paymasterStakeInEth ? ethers.utils.parseEther(paymasterStakeInEth) : DEFAULT_PAYMASTER_STAKE + const unstackedDelSec: number = unstackedDelaySec ?? DEFAULT_UNSTACKED_DELAY_SEC + + const Contract = await ethers.getContractFactory("GaslessEntryPoint") + const contract = await Contract.connect(admin).deploy(gwFullNodeAddress, paymasterStake, unstackedDelSec); + await contract.deployed(); + + console.log('==Entrypoint addr=', contract.address) +} + +export const deployPaymaster = async function (entrypointAddress: string) { + const [admin] = await ethers.getSigners() + + const Contract = await ethers.getContractFactory("GaslessDemoPaymaster") + const contract = await Contract.connect(admin).deploy(entrypointAddress); + await contract.deployed(); + + console.log('==Paymaster addr=', contract.address) +} + +export const addPaymasterStake = async function (paymasterAddr: string, ethAmount: string) { + const [admin] = await ethers.getSigners() + const Contract = await ethers.getContractFactory("GaslessDemoPaymaster") + const contract = await Contract.attach(paymasterAddr); + const tx = await contract.connect(admin).addStake(99999999, { value: ethers.utils.parseEther(ethAmount) }) + console.log('addPaymasterStake tx sent: ', tx.hash); + const receipt = await tx.wait(); + console.log('tx receipt: ', receipt); +} + +export const addWhitelistAddress = async function (paymasterAddr: string, whitelistAddress: string) { + const [admin] = await ethers.getSigners() + const Contract = await ethers.getContractFactory("GaslessDemoPaymaster") + const contract = await Contract.attach(paymasterAddr); + const tx = await contract.connect(admin).addWhitelistAddress(whitelistAddress); + console.log('addWhitelistAddress tx sent: ', tx.hash); + const receipt = await tx.wait(); + console.log('tx receipt: ', receipt); +} + + diff --git a/scripts/deploy.ts b/scripts/deploy.ts new file mode 100644 index 000000000..3004faa8d --- /dev/null +++ b/scripts/deploy.ts @@ -0,0 +1,34 @@ +import hre from "hardhat"; +import { + addPaymasterStake, + addWhitelistAddress, + deployPaymaster, +} from "../deploy/deploy-gasless-contract"; + +async function main() { + //await deployPaymasterContract(); + + // await addWhitelistAddress( + // "0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47", + // "0xFb2C72d3ffe10Ef7c9960272859a23D24db9e04A" + // ); + + await addPaymasterStake("0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47", "1"); +} + +const deployPaymasterContract = async () => { + const entrypoint = process.env.ENTRYPOINT; + if (entrypoint == null) { + throw new Error("process.env.ENTRYPOINT is null"); + } + await deployPaymaster(entrypoint); +}; + +// We recommend this pattern to be able to use async/await everywhere +// and properly handle errors. +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); From 4646f368dad2d699c84f5db63cab4148983af356 Mon Sep 17 00:00:00 2001 From: RetricSu Date: Wed, 28 Dec 2022 14:32:14 +0800 Subject: [PATCH 2/5] add more script func --- deploy/deploy-gasless-contract.ts | 17 +++++++++++++++++ scripts/deploy.ts | 8 ++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/deploy/deploy-gasless-contract.ts b/deploy/deploy-gasless-contract.ts index 92019ed00..4de7b5a1e 100644 --- a/deploy/deploy-gasless-contract.ts +++ b/deploy/deploy-gasless-contract.ts @@ -36,6 +36,23 @@ export const addPaymasterStake = async function (paymasterAddr: string, ethAmoun console.log('tx receipt: ', receipt); } +export const depositPaymasterStake = async function (entrypointAddr: string, paymasterAddr: string, ethAmount: string) { + const [admin] = await ethers.getSigners() + const Contract = await ethers.getContractFactory("GaslessEntryPoint") + const contract = await Contract.attach(entrypointAddr); + const tx = await contract.connect(admin).depositTo(paymasterAddr, { value: ethers.utils.parseEther(ethAmount) }) + console.log('depositPaymasterStake tx sent: ', tx.hash); + const receipt = await tx.wait(); + console.log('tx receipt: ', receipt); +} + +export const getBalance = async function (entrypointAddr: string, paymasterAddr: string) { + const Contract = await ethers.getContractFactory("GaslessEntryPoint") + const contract = await Contract.attach(entrypointAddr); + const balance = await contract.balanceOf(paymasterAddr); + console.log('paymaster balance: ', balance); +} + export const addWhitelistAddress = async function (paymasterAddr: string, whitelistAddress: string) { const [admin] = await ethers.getSigners() const Contract = await ethers.getContractFactory("GaslessDemoPaymaster") diff --git a/scripts/deploy.ts b/scripts/deploy.ts index 3004faa8d..77e0675a9 100644 --- a/scripts/deploy.ts +++ b/scripts/deploy.ts @@ -3,6 +3,8 @@ import { addPaymasterStake, addWhitelistAddress, deployPaymaster, + depositPaymasterStake, + getBalance, } from "../deploy/deploy-gasless-contract"; async function main() { @@ -10,10 +12,12 @@ async function main() { // await addWhitelistAddress( // "0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47", - // "0xFb2C72d3ffe10Ef7c9960272859a23D24db9e04A" + // "0x73b72d6EE63e16c898AD18C7f447846BfC3AB1aC" // ); - await addPaymasterStake("0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47", "1"); + //await addPaymasterStake("0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47", "1000"); + await depositPaymasterStake("0xc52059c8cd8f0817f9e67009e014322f5239547f", "0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47", "1000"); + await getBalance("0xc52059c8cd8f0817f9e67009e014322f5239547f", "0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47") } const deployPaymasterContract = async () => { From 8f26339d5668fc23e5766009ee203f71b649dff5 Mon Sep 17 00:00:00 2001 From: RetricSu Date: Wed, 28 Dec 2022 15:07:21 +0800 Subject: [PATCH 3/5] fix: lint --- deploy/deploy-gasless-contract.ts | 54 +++++++++++++++---------------- scripts/deploy.ts | 32 +++++++++--------- 2 files changed, 42 insertions(+), 44 deletions(-) diff --git a/deploy/deploy-gasless-contract.ts b/deploy/deploy-gasless-contract.ts index 4de7b5a1e..1ce593dc8 100644 --- a/deploy/deploy-gasless-contract.ts +++ b/deploy/deploy-gasless-contract.ts @@ -9,9 +9,9 @@ export const deployEntryPoint = async function (gwFullNodeAddress: string, payma const paymasterStake: BigNumber = paymasterStakeInEth ? ethers.utils.parseEther(paymasterStakeInEth) : DEFAULT_PAYMASTER_STAKE const unstackedDelSec: number = unstackedDelaySec ?? DEFAULT_UNSTACKED_DELAY_SEC - const Contract = await ethers.getContractFactory("GaslessEntryPoint") - const contract = await Contract.connect(admin).deploy(gwFullNodeAddress, paymasterStake, unstackedDelSec); - await contract.deployed(); + const Contract = await ethers.getContractFactory('GaslessEntryPoint') + const contract = await Contract.connect(admin).deploy(gwFullNodeAddress, paymasterStake, unstackedDelSec) + await contract.deployed() console.log('==Entrypoint addr=', contract.address) } @@ -19,48 +19,46 @@ export const deployEntryPoint = async function (gwFullNodeAddress: string, payma export const deployPaymaster = async function (entrypointAddress: string) { const [admin] = await ethers.getSigners() - const Contract = await ethers.getContractFactory("GaslessDemoPaymaster") - const contract = await Contract.connect(admin).deploy(entrypointAddress); - await contract.deployed(); + const Contract = await ethers.getContractFactory('GaslessDemoPaymaster') + const contract = await Contract.connect(admin).deploy(entrypointAddress) + await contract.deployed() console.log('==Paymaster addr=', contract.address) } export const addPaymasterStake = async function (paymasterAddr: string, ethAmount: string) { const [admin] = await ethers.getSigners() - const Contract = await ethers.getContractFactory("GaslessDemoPaymaster") - const contract = await Contract.attach(paymasterAddr); + const Contract = await ethers.getContractFactory('GaslessDemoPaymaster') + const contract = await Contract.attach(paymasterAddr) const tx = await contract.connect(admin).addStake(99999999, { value: ethers.utils.parseEther(ethAmount) }) - console.log('addPaymasterStake tx sent: ', tx.hash); - const receipt = await tx.wait(); - console.log('tx receipt: ', receipt); + console.log('addPaymasterStake tx sent: ', tx.hash) + const receipt = await tx.wait() + console.log('tx receipt: ', receipt) } export const depositPaymasterStake = async function (entrypointAddr: string, paymasterAddr: string, ethAmount: string) { const [admin] = await ethers.getSigners() - const Contract = await ethers.getContractFactory("GaslessEntryPoint") - const contract = await Contract.attach(entrypointAddr); + const Contract = await ethers.getContractFactory('GaslessEntryPoint') + const contract = await Contract.attach(entrypointAddr) const tx = await contract.connect(admin).depositTo(paymasterAddr, { value: ethers.utils.parseEther(ethAmount) }) - console.log('depositPaymasterStake tx sent: ', tx.hash); - const receipt = await tx.wait(); - console.log('tx receipt: ', receipt); + console.log('depositPaymasterStake tx sent: ', tx.hash) + const receipt = await tx.wait() + console.log('tx receipt: ', receipt) } export const getBalance = async function (entrypointAddr: string, paymasterAddr: string) { - const Contract = await ethers.getContractFactory("GaslessEntryPoint") - const contract = await Contract.attach(entrypointAddr); - const balance = await contract.balanceOf(paymasterAddr); - console.log('paymaster balance: ', balance); + const Contract = await ethers.getContractFactory('GaslessEntryPoint') + const contract = await Contract.attach(entrypointAddr) + const balance = await contract.balanceOf(paymasterAddr) + console.log('paymaster balance: ', balance) } export const addWhitelistAddress = async function (paymasterAddr: string, whitelistAddress: string) { const [admin] = await ethers.getSigners() - const Contract = await ethers.getContractFactory("GaslessDemoPaymaster") - const contract = await Contract.attach(paymasterAddr); - const tx = await contract.connect(admin).addWhitelistAddress(whitelistAddress); - console.log('addWhitelistAddress tx sent: ', tx.hash); - const receipt = await tx.wait(); - console.log('tx receipt: ', receipt); + const Contract = await ethers.getContractFactory('GaslessDemoPaymaster') + const contract = await Contract.attach(paymasterAddr) + const tx = await contract.connect(admin).addWhitelistAddress(whitelistAddress) + console.log('addWhitelistAddress tx sent: ', tx.hash) + const receipt = await tx.wait() + console.log('tx receipt: ', receipt) } - - diff --git a/scripts/deploy.ts b/scripts/deploy.ts index 77e0675a9..b3c4f57fd 100644 --- a/scripts/deploy.ts +++ b/scripts/deploy.ts @@ -1,38 +1,38 @@ -import hre from "hardhat"; +import hre from 'hardhat' import { - addPaymasterStake, + addPaymasterStake, addWhitelistAddress, deployPaymaster, depositPaymasterStake, - getBalance, -} from "../deploy/deploy-gasless-contract"; + getBalance +} from '../deploy/deploy-gasless-contract' -async function main() { - //await deployPaymasterContract(); +async function main () { + // await deployPaymasterContract(); // await addWhitelistAddress( // "0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47", // "0x73b72d6EE63e16c898AD18C7f447846BfC3AB1aC" // ); - //await addPaymasterStake("0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47", "1000"); - await depositPaymasterStake("0xc52059c8cd8f0817f9e67009e014322f5239547f", "0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47", "1000"); - await getBalance("0xc52059c8cd8f0817f9e67009e014322f5239547f", "0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47") + // await addPaymasterStake("0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47", "1000"); + await depositPaymasterStake('0xc52059c8cd8f0817f9e67009e014322f5239547f', '0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47', '1000') + await getBalance('0xc52059c8cd8f0817f9e67009e014322f5239547f', '0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47') } const deployPaymasterContract = async () => { - const entrypoint = process.env.ENTRYPOINT; + const entrypoint = process.env.ENTRYPOINT if (entrypoint == null) { - throw new Error("process.env.ENTRYPOINT is null"); + throw new Error('process.env.ENTRYPOINT is null') } - await deployPaymaster(entrypoint); -}; + await deployPaymaster(entrypoint) +} // We recommend this pattern to be able to use async/await everywhere // and properly handle errors. main() .then(() => process.exit(0)) .catch((error) => { - console.error(error); - process.exit(1); - }); + console.error(error) + process.exit(1) + }) From 909cbf7e767acc5920ba0171cde04745873e4181 Mon Sep 17 00:00:00 2001 From: RetricSu Date: Wed, 4 Jan 2023 12:40:41 +0800 Subject: [PATCH 4/5] add deploy always success paymaster --- deploy/deploy-gasless-contract.ts | 17 +++++++++++++++++ scripts/deploy.ts | 13 +++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/deploy/deploy-gasless-contract.ts b/deploy/deploy-gasless-contract.ts index 1ce593dc8..b3636aa90 100644 --- a/deploy/deploy-gasless-contract.ts +++ b/deploy/deploy-gasless-contract.ts @@ -26,6 +26,16 @@ export const deployPaymaster = async function (entrypointAddress: string) { console.log('==Paymaster addr=', contract.address) } +export const deployAlwaysSuccessPaymaster = async function (entrypointAddress: string) { + const [admin] = await ethers.getSigners() + + const Contract = await ethers.getContractFactory('GaslessAlwaysSuccessPaymaster') + const contract = await Contract.connect(admin).deploy(entrypointAddress) + await contract.deployed() + + console.log('==Always-success Paymaster addr=', contract.address) +} + export const addPaymasterStake = async function (paymasterAddr: string, ethAmount: string) { const [admin] = await ethers.getSigners() const Contract = await ethers.getContractFactory('GaslessDemoPaymaster') @@ -53,6 +63,13 @@ export const getBalance = async function (entrypointAddr: string, paymasterAddr: console.log('paymaster balance: ', balance) } +export const getStake = async function (paymasterAddr: string) { + const Contract = await ethers.getContractFactory("GaslessDemoPaymaster") + const contract = await Contract.attach(paymasterAddr) + const balance = await contract.getDeposit() + console.log('paymaster getDeposit: ', balance) +} + export const addWhitelistAddress = async function (paymasterAddr: string, whitelistAddress: string) { const [admin] = await ethers.getSigners() const Contract = await ethers.getContractFactory('GaslessDemoPaymaster') diff --git a/scripts/deploy.ts b/scripts/deploy.ts index b3c4f57fd..257f0c08e 100644 --- a/scripts/deploy.ts +++ b/scripts/deploy.ts @@ -2,22 +2,27 @@ import hre from 'hardhat' import { addPaymasterStake, addWhitelistAddress, + deployAlwaysSuccessPaymaster, deployPaymaster, depositPaymasterStake, - getBalance + getBalance, + getStake } from '../deploy/deploy-gasless-contract' async function main () { // await deployPaymasterContract(); + // await deployAlwaysSuccessPaymaster("0xc52059c8cd8f0817f9e67009e014322f5239547f"); + // await addWhitelistAddress( // "0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47", // "0x73b72d6EE63e16c898AD18C7f447846BfC3AB1aC" // ); - // await addPaymasterStake("0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47", "1000"); - await depositPaymasterStake('0xc52059c8cd8f0817f9e67009e014322f5239547f', '0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47', '1000') - await getBalance('0xc52059c8cd8f0817f9e67009e014322f5239547f', '0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47') + //await addPaymasterStake("0xb3f9633d9603D39424ff107B4846708c7E6dFaeA", "1000"); + await getStake("0xb3f9633d9603D39424ff107B4846708c7E6dFaeA") + // await depositPaymasterStake('0xc52059c8cd8f0817f9e67009e014322f5239547f', '0xb3f9633d9603D39424ff107B4846708c7E6dFaeA', '1000') + // await getBalance('0xc52059c8cd8f0817f9e67009e014322f5239547f', '0xb3f9633d9603D39424ff107B4846708c7E6dFaeA') } const deployPaymasterContract = async () => { From e95d5ccc7b83e7ff76918cf8c04ae599ca053baa Mon Sep 17 00:00:00 2001 From: RetricSu Date: Wed, 4 Jan 2023 19:06:18 +0800 Subject: [PATCH 5/5] add gw testnet --- hardhat.config.ts | 5 +++++ scripts/deploy.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index e4a85de25..0ed96888f 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -76,6 +76,11 @@ const config: HardhatUserConfig = { accounts: [`0x${TEST_PK1}`, `0x${TEST_PK2}`, `${PRIVATE_KEY0}`, `${PRIVATE_KEY1}`], chainId: 202206 }, + gw_testnet_v1: { + url: `https://v1.testnet.godwoken.io/rpc/instant-finality-hack`, + accounts: [`0x${TEST_PK1}`, `0x${TEST_PK2}`, `0x${TEST_PK3}`,`${PRIVATE_KEY0}`, `${PRIVATE_KEY1}`], + chainId: 71401, + }, dev: { url: 'http://localhost:8545' }, // github action starts localgeth service, for gas calculations localgeth: { url: 'http://localgeth:8545' }, diff --git a/scripts/deploy.ts b/scripts/deploy.ts index 257f0c08e..c35b97526 100644 --- a/scripts/deploy.ts +++ b/scripts/deploy.ts @@ -3,6 +3,7 @@ import { addPaymasterStake, addWhitelistAddress, deployAlwaysSuccessPaymaster, + deployEntryPoint, deployPaymaster, depositPaymasterStake, getBalance, @@ -10,6 +11,9 @@ import { } from '../deploy/deploy-gasless-contract' async function main () { + + await deployEntryPoint("0x715ab282b873b79a7be8b0e8c13c4e8966a52040") + // await deployPaymasterContract(); // await deployAlwaysSuccessPaymaster("0xc52059c8cd8f0817f9e67009e014322f5239547f"); @@ -20,7 +24,7 @@ async function main () { // ); //await addPaymasterStake("0xb3f9633d9603D39424ff107B4846708c7E6dFaeA", "1000"); - await getStake("0xb3f9633d9603D39424ff107B4846708c7E6dFaeA") + //await getStake("0xb3f9633d9603D39424ff107B4846708c7E6dFaeA") // await depositPaymasterStake('0xc52059c8cd8f0817f9e67009e014322f5239547f', '0xb3f9633d9603D39424ff107B4846708c7E6dFaeA', '1000') // await getBalance('0xc52059c8cd8f0817f9e67009e014322f5239547f', '0xb3f9633d9603D39424ff107B4846708c7E6dFaeA') }