Skip to content

Commit

Permalink
added faucet funding. (#1562)
Browse files Browse the repository at this point in the history
* added faucet funding.

* Increased amount.

* Added config option.

* Added env variables for faucet funds.

* Fix new line issue.

---------

Co-authored-by: StefanIliev545 <[email protected]>
  • Loading branch information
StefanIliev545 and StefanIliev545 authored Sep 29, 2023
1 parent 10ded30 commit a818470
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/manual-deploy-testnet-l2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
44 changes: 44 additions & 0 deletions contracts/deployment_scripts/funding/layer1/002_fund_faucet.ts
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions testnet/launcher/l2contractdeployer/cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()

Expand All @@ -43,6 +45,7 @@ func ParseConfigCLI() *L2ContractDeployerConfigCLI {
cfg.l2PrivateKey = *l2PrivateKey
cfg.l2HOCPrivateKey = *l2POCPrivateKey
cfg.l2POCPrivateKey = *l2HOCPrivateKey
cfg.faucetFunding = *faucetFunds

return cfg
}
2 changes: 2 additions & 0 deletions testnet/launcher/l2contractdeployer/cmd/cli_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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",
}
}
29 changes: 19 additions & 10 deletions testnet/launcher/l2contractdeployer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -79,3 +82,9 @@ func WithPocPKString(s string) Option {
c.pocPKString = s
}
}

func WithFaucetFunds(f string) Option {
return func(c *Config) {
c.faucetPrefundAmount = f
}
}
3 changes: 2 additions & 1 deletion testnet/launcher/l2contractdeployer/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" : {
Expand Down

0 comments on commit a818470

Please sign in to comment.