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 simple deploy scripts for gasless #14

Draft
wants to merge 5 commits into
base: gw-gasless
Choose a base branch
from
Draft
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
81 changes: 81 additions & 0 deletions deploy/deploy-gasless-contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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 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')
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 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 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')
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)
}
5 changes: 5 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
47 changes: 47 additions & 0 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import hre from 'hardhat'
import {
addPaymasterStake,
addWhitelistAddress,
deployAlwaysSuccessPaymaster,
deployEntryPoint,
deployPaymaster,
depositPaymasterStake,
getBalance,
getStake
} from '../deploy/deploy-gasless-contract'

async function main () {

await deployEntryPoint("0x715ab282b873b79a7be8b0e8c13c4e8966a52040")

// await deployPaymasterContract();
// await deployAlwaysSuccessPaymaster("0xc52059c8cd8f0817f9e67009e014322f5239547f");


// await addWhitelistAddress(
// "0xa8a0B28AbC58290EF91Dd4375Ea5e1274dE16f47",
// "0x73b72d6EE63e16c898AD18C7f447846BfC3AB1aC"
// );

//await addPaymasterStake("0xb3f9633d9603D39424ff107B4846708c7E6dFaeA", "1000");
//await getStake("0xb3f9633d9603D39424ff107B4846708c7E6dFaeA")
// await depositPaymasterStake('0xc52059c8cd8f0817f9e67009e014322f5239547f', '0xb3f9633d9603D39424ff107B4846708c7E6dFaeA', '1000')
// await getBalance('0xc52059c8cd8f0817f9e67009e014322f5239547f', '0xb3f9633d9603D39424ff107B4846708c7E6dFaeA')
}

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)
})