-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
950cfa2
commit 46f4693
Showing
3 changed files
with
184 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { type DeploymentsExtension } from 'hardhat-deploy/types' | ||
|
||
import { GsnDomainSeparatorType, GsnRequestType } from '@opengsn/common' | ||
import { defaultGsnConfig } from '@opengsn/provider' | ||
|
||
import { type DeployOptions, type DeployResult } from 'hardhat-deploy/dist/types' | ||
import chalk from 'chalk' | ||
import { formatEther } from 'ethers' | ||
import { type HardhatRuntimeEnvironment } from 'hardhat/types' | ||
import { ethers } from 'hardhat' | ||
|
||
import { | ||
applyDeploymentConfig, | ||
fatal, getDeploymentEnv, | ||
printRelayInfo, | ||
} from '../src/deployUtils' | ||
|
||
const FORWARDER_FILE = '@opengsn/contracts/src/forwarder/Forwarder.sol:Forwarder' | ||
const PENALIZER_FILE = '@opengsn/contracts/src/Penalizer.sol:Penalizer' | ||
const STAKE_MANAGER_FILE = '@opengsn/contracts/src/StakeManager.sol:StakeManager' | ||
const RELAY_REGISTRAR_FILE = '@opengsn/contracts/src/utils/RelayRegistrar.sol:RelayRegistrar' | ||
const RELAY_HUB_FILE = '@opengsn/contracts/src/RelayHub.sol:RelayHub' | ||
|
||
// helper: nicer logging view fo deployed contracts | ||
async function deploy(deployments: DeploymentsExtension, name: string, options: DeployOptions): Promise<DeployResult> { | ||
console.log('Deploying: ', name) | ||
const res = await deployments.deploy(name, { ...options, log: true }) | ||
console.log(name, res.address, res.newlyDeployed ? chalk.yellow('newlyDeployed') : chalk.gray('existing')) | ||
return res | ||
} | ||
|
||
export default async function deploymentFunc(hre: HardhatRuntimeEnvironment): Promise<void> { | ||
const { env, deployments, deployer } = await getDeploymentEnv(hre) | ||
|
||
const balance = await ethers.provider.getBalance(deployer) | ||
console.log('deployer=', deployer, 'balance=', formatEther(balance.toString())) | ||
|
||
if (env.deploymentConfiguration == null || Object.keys(env.deploymentConfiguration.minimumStakePerToken).length === 0) { | ||
fatal('must have at least one entry in minimumStakePerToken') | ||
} | ||
|
||
let stakingTokenAddress = Object.keys(env.deploymentConfiguration.minimumStakePerToken ?? {})[0] | ||
if (stakingTokenAddress == null) { | ||
fatal('must specify token address in minimumStakePerToken (or "test" to deploy TestWrappedNativeToken') | ||
} | ||
|
||
if (stakingTokenAddress === 'test') { | ||
const TestWrappedNativeToken = await deploy(deployments, 'TestWrappedNativeToken', { | ||
from: deployer | ||
}) | ||
stakingTokenAddress = TestWrappedNativeToken.address | ||
} | ||
|
||
const deployedForwarder = await deploy(deployments, 'Forwarder', { | ||
contract: FORWARDER_FILE, | ||
from: deployer, | ||
deterministicDeployment: true | ||
}) | ||
|
||
if (deployedForwarder.newlyDeployed) { | ||
const options = { from: deployer, log: true } | ||
await deployments.execute('Forwarder', options, 'registerRequestType', GsnRequestType.typeName, GsnRequestType.typeSuffix) | ||
await deployments.execute('Forwarder', options, 'registerDomainSeparator', defaultGsnConfig.domainSeparatorName, GsnDomainSeparatorType.version) | ||
} | ||
|
||
const penalizer = await deploy(deployments, 'Penalizer', { | ||
from: deployer, | ||
contract: PENALIZER_FILE, | ||
args: [ | ||
env.penalizerConfiguration.penalizeBlockDelay, | ||
env.penalizerConfiguration.penalizeBlockDelay | ||
] | ||
}) | ||
|
||
const stakeManager = await deploy(deployments, 'StakeManager', { | ||
from: deployer, | ||
contract: STAKE_MANAGER_FILE, | ||
args: [env.maxUnstakeDelay, env.abandonmentDelay, env.escheatmentDelay, env.stakeBurnAddress, env.relayHubConfiguration.devAddress] | ||
}) | ||
|
||
const relayRegistrar = await deploy(deployments, 'RelayRegistrar', { | ||
from: deployer, | ||
contract: RELAY_REGISTRAR_FILE, | ||
args: [env.deploymentConfiguration.registrationMaxAge] | ||
}) | ||
|
||
const hubConfig = env.relayHubConfiguration | ||
let relayHub: DeployResult | ||
let hubContractName: string | ||
let hubContractFile: string | ||
|
||
hubContractName = 'RelayHub' | ||
hubContractFile = RELAY_HUB_FILE | ||
relayHub = await deploy(deployments, hubContractName, { | ||
from: deployer, | ||
contract: hubContractFile, | ||
args: [ | ||
stakeManager.address, | ||
penalizer.address, | ||
ethers.ZeroAddress, // batch gateway | ||
relayRegistrar.address, | ||
hubConfig | ||
] | ||
}) | ||
|
||
await applyDeploymentConfig(hre) | ||
|
||
await printRelayInfo(hre, env.deploymentConfiguration?.isArbitrum) | ||
} |
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,19 @@ | ||
module.exports = { | ||
'18021980': { | ||
environmentsKey: 'ethereumMainnet', | ||
relayHubConfiguration: { | ||
devAddress: '0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc', | ||
devFee: 10 | ||
}, | ||
deploymentConfiguration: { | ||
registrationMaxAge: 15552000, | ||
paymasterDeposit: '0.1', | ||
isArbitrum: false, | ||
deployTestPaymaster: false, | ||
deploySingleRecipientPaymaster: false, | ||
// Set the staking token to a small number of DDD tokens. | ||
// This is tied into our dev setup. | ||
minimumStakePerToken: { '0x3E8174689882c629de7478B4a0336266B6560C6D': '0.00000000000005' } | ||
} | ||
} | ||
} |
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,56 @@ | ||
/** | ||
* @type import('hardhat/config').HardhatUserConfig | ||
*/ | ||
import '@nomiclabs/hardhat-web3' | ||
import 'hardhat-deploy' | ||
import '@nomiclabs/hardhat-ethers' | ||
import '@nomiclabs/hardhat-etherscan' | ||
|
||
import fs from 'fs' | ||
import { type HardhatUserConfig } from 'hardhat/config' | ||
import { type NetworkUserConfig } from 'hardhat/src/types/config' | ||
import path from 'path' | ||
import chalk from 'chalk' | ||
import './src/exportTask' | ||
|
||
function getNetwork(url: string): NetworkUserConfig { | ||
return { | ||
url, | ||
accounts: [ | ||
/* user1 - exposed local dev account */ "0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba" | ||
] | ||
} | ||
} | ||
|
||
const CONTRACTS_LINK = 'contracts-link' | ||
|
||
if (!fs.existsSync(path.join(CONTRACTS_LINK, 'RelayHub.sol'))) { | ||
console.log('== creating symlink', chalk.yellow(CONTRACTS_LINK), 'for contracts') | ||
fs.symlinkSync('../contracts/solpp', CONTRACTS_LINK) | ||
} | ||
if (!fs.existsSync(path.join(CONTRACTS_LINK, 'paymasters/SingleRecipientPaymaster.sol'))) { | ||
console.log('== creating symlink', chalk.yellow(CONTRACTS_LINK + '/paymasters'), 'for contracts') | ||
fs.symlinkSync('../../paymasters/contracts', CONTRACTS_LINK + '/paymasters') | ||
} | ||
|
||
const config: HardhatUserConfig = { | ||
solidity: { | ||
version: '0.8.7', | ||
settings: { | ||
optimizer: { | ||
enabled: true | ||
} | ||
} | ||
}, | ||
paths: { | ||
deployments: 'deployments/networks', | ||
sources: CONTRACTS_LINK // can't use "../contracts/src" directly. | ||
}, | ||
networks: { | ||
// TS updates | ||
// Local geth node | ||
dev: getNetwork('http://geth:8546'), | ||
} | ||
} | ||
|
||
module.exports = config |