yuichiroaoki / poly-flash

Flashloan on Polygon
https://yuichiroaoki.medium.com/no-flashloan-fee-with-dodo-cc78215d7f93
MIT License
294 stars 174 forks source link

'too many arguments: in Contract constructor' #1

Closed digitalftl closed 2 years ago

digitalftl commented 2 years ago

Hi there, I really appreciate you've made this open-source, really good work.

I'm new into this, I've been watching quite a few tutorials on how to deploy the contract with hardhat on mainnet. I believe I managed to config hardhat.configs for the mainnet, but when I run the command I get this error.

Would you be kind to guide me? What do I need to do?

PS D:\Arbitrage\poly-flash-main> npx hardhat run scripts/sample-script.ts --network polygon
No need to generate any newer typings.
Nothing to compile
No need to generate any newer typings.
Error: too many arguments:  in Contract constructor (count=1, expectedCount=0, code=UNEXPECTED_ARGUMENT, version=contracts/5.5.0)
    at Logger.makeError (D:\Arbitrage\poly-flash-main\node_modules\@ethersproject\logger\src.ts\index.ts:225:28)
    at Logger.throwError (D:\Arbitrage\poly-flash-main\node_modules\@ethersproject\logger\src.ts\index.ts:237:20)
    at Logger.checkArgumentCount (D:\Arbitrage\poly-flash-main\node_modules\@ethersproject\logger\src.ts\index.ts:303:18)
    at ContractFactory.getDeployTransaction (D:\Arbitrage\poly-flash-main\node_modules\@ethersproject\contracts\src.ts\index.ts:1206:16)
    at ContractFactory.<anonymous> (D:\Arbitrage\poly-flash-main\node_modules\@ethersproject\contracts\src.ts\index.ts:1234:53)
    at step (D:\Arbitrage\poly-flash-main\node_modules\@ethersproject\contracts\lib\index.js:48:23)
    at Object.next (D:\Arbitrage\poly-flash-main\node_modules\@ethersproject\contracts\lib\index.js:29:53)
    at fulfilled (D:\Arbitrage\poly-flash-main\node_modules\@ethersproject\contracts\lib\index.js:20:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  reason: 'too many arguments:  in Contract constructor',
  code: 'UNEXPECTED_ARGUMENT',
  count: 1,
  expectedCount: 0
}

Thank you!

yuichiroaoki commented 2 years ago

Hi, I'm glad that you like it!

Have you changed scripts/sample-script.ts ?? Could you show me your scripts/sample-script.ts?? Also the smart contract you want to deploy??

digitalftl commented 2 years ago

Hi, yes I set Flashloan in sample-scripts.ts. Do I need to do something else?


import { ethers, run } from 'hardhat';

async function main() {
  await run('compile');
  const Flashloan = await ethers.getContractFactory('Flashloan');
  const flashloan = await Flashloan.deploy("Hello, Flashloan");

  console.log(`FlashBot deployed to ${flashloan.address}`);
}

main()
  .then(() => process.exit(0))
  .catch((err) => {
    console.error(err);
    process.exit(1);
  });
yuichiroaoki commented 2 years ago

You are passing an argument Hello, Flashloan to the deploy function, which you are not supposed to.

It should be like the following code:


import { ethers, run } from 'hardhat';

async function main() {
  await run('compile');
  const Flashloan = await ethers.getContractFactory('Flashloan');
  const flashloan = await Flashloan.deploy();  // Flashloan.sol deploy function takes no arguments

  console.log(`FlashBot deployed to ${flashloan.address}`);
}

main()
  .then(() => process.exit(0))
  .catch((err) => {
    console.error(err);
    process.exit(1);
  });

Notice this Flashloan contract does not have a constructor that takes one parameter.

https://github.com/yuichiroaoki/poly-flash/blob/main/contracts/Flashloan.sol

While this hardhat default Greeter contract has a constructor that takes one string parameter.

https://github.com/yuichiroaoki/poly-flash/blob/8bf493e075b11fcbefa09daa003544a6c0056183/contracts/Greeter.sol#L7-L14

That's why when you deploy this Greeter contract, you pass a string, Hello, Hardhat! to the deploy function.

https://github.com/yuichiroaoki/poly-flash/blob/8bf493e075b11fcbefa09daa003544a6c0056183/scripts/sample-script.ts#L18-L20

Hope this makes sense😄

digitalftl commented 2 years ago

``Yes, it does make sense.

I've got 2 more questions.

  1. Do I need to verify the contract?
  2. Does the bot have any console log?

Because I've started the bot, nothing happens, I see in the alchemy dashboard that there is only one request made every few seconds.

eth_chainId

and after a while I get this error

502
Error Request failed with status code 502

Thank you so much for your patience.

yuichiroaoki commented 2 years ago
  1. No, people usually verify their contracts so that everyone can use it like when they build a new Defi protocol. If you just want use it personally, I think don't have to.

  2. Unless there's some errors fetching data from 1inch API or the bot finds an arbitrage, I think it doesn't show any console.log messages.

I think I need to update the docs and code, because you can't tell if the bot running properly or not.

The error message you got means probably the bot successfully sent a request to 1inch API, but 1inch failed to respond price data.