diff --git a/.github/workflows/manual-deploy-testnet-l2.yml b/.github/workflows/manual-deploy-testnet-l2.yml index 503ee23351..925c1c4feb 100644 --- a/.github/workflows/manual-deploy-testnet-l2.yml +++ b/.github/workflows/manual-deploy-testnet-l2.yml @@ -66,6 +66,7 @@ jobs: echo "BATCH_INTERVAL=${{vars.BATCH_INTERVAL}}" echo "ROLLUP_INTERVAL=${{vars.ROLLUP_INTERVAL}}" + echo "FAUCET_FUNDS=${{vars.FAUCET_FUNDS}}" - name: 'Login via Azure CLI' uses: azure/login@v1 @@ -325,7 +326,8 @@ jobs: -l2_hoc_private_key=6e384a07a01263518a09a5424c7b6bbfc3604ba7d93f47e3a455cbdd7f9f0682 \ -l2_poc_private_key=4bfe14725e685901c062ccd4e220c61cf9c189897b6c78bd18d7f51291b2b8f8 \ -message_bus_contract_addr=${{ needs.build.outputs.MSG_BUS_CONTRACT_ADDR }} \ - -docker_image=${{vars.L2_HARDHATDEPLOYER_DOCKER_BUILD_TAG}} + -docker_image=${{vars.L2_HARDHATDEPLOYER_DOCKER_BUILD_TAG}} \ + -faucet_funds=${{vars.FAUCET_FUNDS}} - name: 'Save container logs on failure' if: failure() diff --git a/contracts/deployment_scripts/funding/layer1/002_fund_faucet.ts b/contracts/deployment_scripts/funding/layer1/002_fund_faucet.ts new file mode 100644 index 0000000000..4320d41cda --- /dev/null +++ b/contracts/deployment_scripts/funding/layer1/002_fund_faucet.ts @@ -0,0 +1,44 @@ +import {HardhatRuntimeEnvironment} from 'hardhat/types'; +import {DeployFunction} from 'hardhat-deploy/types'; + + +const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { + const layer1 = hre.companionNetworks.layer1; + + const {deployer} = await hre.getNamedAccounts(); + const l1Accs = await layer1.getNamedAccounts(); + + const messageBusAddress = process.env.MESSAGE_BUS_ADDRESS!! + const prefundAmountStr = process.env.PREFUND_FAUCET_AMOUNT!! + + if (prefundAmountStr == "0") { + return; + } + + const messageBus = (await hre.ethers.getContractFactory('MessageBus')).attach(messageBusAddress) + const prefundAmount = hre.ethers.utils.parseEther(prefundAmountStr); + const tx = await messageBus.populateTransaction.sendValueToL2("0xA58C60cc047592DE97BF1E8d2f225Fc5D959De77", prefundAmount, { + value: prefundAmount + }); + + + console.log(`Sending ${prefundAmount} to ${deployer}`); + + const receipt = await layer1.deployments.rawTx({ + from: l1Accs.deployer, + to: messageBusAddress, + value: prefundAmount, + data: tx.data, + log: true, + waitConfirmations: 1, + }); + if (receipt.events?.length === 0) { + console.log(`Account prefunding status = FAILURE NO CROSS CHAIN EVENT`); + } else { + console.log(`Account prefunding status = ${receipt.status}`); + } +}; + +export default func; +func.tags = ['GasPrefunding', 'GasPrefunding_deploy']; +// No dependencies \ No newline at end of file diff --git a/testnet/launcher/l2contractdeployer/cmd/cli.go b/testnet/launcher/l2contractdeployer/cmd/cli.go index 9de87e00e9..71486b73d7 100644 --- a/testnet/launcher/l2contractdeployer/cmd/cli.go +++ b/testnet/launcher/l2contractdeployer/cmd/cli.go @@ -15,6 +15,7 @@ type L2ContractDeployerConfigCLI struct { l2PrivateKey string l2HOCPrivateKey string l2POCPrivateKey string + faucetFunding string } // ParseConfigCLI returns a NodeConfigCLI based the cli params and defaults. @@ -31,6 +32,7 @@ func ParseConfigCLI() *L2ContractDeployerConfigCLI { l2PrivateKey := flag.String(l2privateKeyFlag, "", flagUsageMap[l2privateKeyFlag]) l2HOCPrivateKey := flag.String(l2HOCPrivateKeyFlag, "", flagUsageMap[l2HOCPrivateKeyFlag]) l2POCPrivateKey := flag.String(l2POCPrivateKeyFlag, "", flagUsageMap[l2POCPrivateKeyFlag]) + faucetFunds := flag.String(faucetFundingFlag, "0", flagUsageMap[faucetFundingFlag]) flag.Parse() @@ -43,6 +45,7 @@ func ParseConfigCLI() *L2ContractDeployerConfigCLI { cfg.l2PrivateKey = *l2PrivateKey cfg.l2HOCPrivateKey = *l2POCPrivateKey cfg.l2POCPrivateKey = *l2HOCPrivateKey + cfg.faucetFunding = *faucetFunds return cfg } diff --git a/testnet/launcher/l2contractdeployer/cmd/cli_flags.go b/testnet/launcher/l2contractdeployer/cmd/cli_flags.go index 54819e185a..d5286cf2bb 100644 --- a/testnet/launcher/l2contractdeployer/cmd/cli_flags.go +++ b/testnet/launcher/l2contractdeployer/cmd/cli_flags.go @@ -11,6 +11,7 @@ const ( l2privateKeyFlag = "l2_private_key" l2HOCPrivateKeyFlag = "l2_hoc_private_key" l2POCPrivateKeyFlag = "l2_poc_private_key" + faucetFundingFlag = "faucet_funds" ) // Returns a map of the flag usages. @@ -26,5 +27,6 @@ func getFlagUsageMap() map[string]string { l2privateKeyFlag: "Layer 2 private key", l2HOCPrivateKeyFlag: "Layer 2 HOC contract private key", l2POCPrivateKeyFlag: "Layer 2 POC contract private key", + faucetFundingFlag: "How much funds should the faucet account receive", } } diff --git a/testnet/launcher/l2contractdeployer/config.go b/testnet/launcher/l2contractdeployer/config.go index 5708936913..fe26b5199e 100644 --- a/testnet/launcher/l2contractdeployer/config.go +++ b/testnet/launcher/l2contractdeployer/config.go @@ -5,19 +5,22 @@ type Option = func(c *Config) // Config holds the properties that configure the package type Config struct { - l1HTTPURL string - l1privateKey string - l2Port int - l2Host string - l2PrivateKey string - hocPKString string - pocPKString string - messageBusAddress string - dockerImage string + l1HTTPURL string + l1privateKey string + l2Port int + l2Host string + l2PrivateKey string + hocPKString string + pocPKString string + messageBusAddress string + dockerImage string + faucetPrefundAmount string } func NewContractDeployerConfig(opts ...Option) *Config { - defaultConfig := &Config{} + defaultConfig := &Config{ + faucetPrefundAmount: "10000", + } for _, opt := range opts { opt(defaultConfig) @@ -79,3 +82,9 @@ func WithPocPKString(s string) Option { c.pocPKString = s } } + +func WithFaucetFunds(f string) Option { + return func(c *Config) { + c.faucetPrefundAmount = f + } +} diff --git a/testnet/launcher/l2contractdeployer/docker.go b/testnet/launcher/l2contractdeployer/docker.go index 5c04959d9a..564430a067 100644 --- a/testnet/launcher/l2contractdeployer/docker.go +++ b/testnet/launcher/l2contractdeployer/docker.go @@ -33,7 +33,8 @@ func (n *ContractDeployer) Start() error { } envs := map[string]string{ - "MESSAGE_BUS_ADDRESS": n.cfg.messageBusAddress, + "PREFUND_FAUCET_AMOUNT": n.cfg.faucetPrefundAmount, + "MESSAGE_BUS_ADDRESS": n.cfg.messageBusAddress, "NETWORK_JSON": fmt.Sprintf(` { "layer1" : {