{"size": 1681, "ext": "js", "max_stars_repo_path": "buidler/tasks/gelato/core/gelato_providers/provide_funds/task.provideFunds.js", "max_stars_repo_name": "gelatodigital/gelato-network", "max_stars_repo_stars_event_min_datetime": "2020-07-03T11:51:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T11:57:17.000Z", "max_issues_repo_path": "buidler/tasks/gelato/core/gelato_providers/provide_funds/task.provideFunds.js", "max_issues_repo_name": "STR1017/gelato-network", "max_issues_repo_issues_event_min_datetime": "2020-07-03T12:16:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-02T13:28:41.000Z", "max_forks_repo_path": "buidler/tasks/gelato/core/gelato_providers/provide_funds/task.provideFunds.js", "max_forks_repo_name": "STR1017/gelato-network", "max_forks_repo_forks_event_min_datetime": "2020-07-03T11:53:00.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T19:13:45.000Z"}
{"max_stars_count": 243, "max_issues_count": 43, "max_forks_count": 24, "avg_line_length": 32.3269230769, "max_line_length": 86, "alphanum_fraction": 0.6115407496}
import { task } from "@nomiclabs/buidler/config";
import { defaultNetwork } from "../../../../../../buidler.config";
import { utils } from "ethers";

export default task(
  "gc-providefunds",
  `Sends tx to GelatoCore.provideFunds(<) on [--network] (default: ${defaultNetwork})`
)
  .addPositionalParam(
    "ethamount",
    "The amount of eth to add to the gelatoprovider's balance"
  )
  .addOptionalPositionalParam(
    "gelatoprovider",
    "The gelatoprovider to add balance to."
  )
  .addOptionalParam(
    "funderindex",
    "Index of tx Signer account generated from mnemonic available inside BRE",
    2,
    types.int
  )
  .addFlag("log", "Logs return values to stdout")
  .setAction(async ({ ethamount, gelatoprovider, funderindex, log }) => {
    try {
      const depositAmount = utils.parseEther(ethamount);
      gelatoprovider = await run("handleGelatoProvider", { gelatoprovider });
      const { [funderindex]: funder } = await ethers.getSigners();
      if (log) {
        console.log(`
          \n Funding from account with index: ${funderindex}\
          \n Funder:                          ${funder._address}\
          \n Funding Provider with Address:   ${gelatoprovider}\n
        `);
      }
      const gelatoCore = await run("instantiateContract", {
        contractname: "GelatoCore",
        write: true,
        signer: funder,
      });
      const tx = await gelatoCore.provideFunds(gelatoprovider, {
        value: depositAmount,
      });
      if (log) console.log(`\n\ntxHash providefunds: ${tx.hash}`);
      await tx.wait();
      return tx.hash;
    } catch (error) {
      console.error(error, "\n");
      process.exit(1);
    }
  });
