Crowd Sale Contract Issue while minting token - solidity

I am currently working on a crowd sale contract, But I am having an issue with a function as the list of the error and the code of the function is attached, I need someone to tell me that what is happening in the code and how can i resolve the error that I'm facing in the code. Solidity version ^0.5.0
Code:
function _finalization() internal {
if (goalReached()) {
ERC20Mintable erc20Mintable = ERC20Mintable(token);
//getting the total tokens that are been minted yet
uint256 alreadyMintedToken = erc20Mintable.totalSupply();
//tokens of the final total supply
uint256 finalTotalTokenSupply = alreadyMintedToken
.div(tokenSalePercentage)
.mul(100);
foundersTimelock = new TokenTimelock(
token,
foundersFund,
releaseTime
);
partnersTimelock = new TokenTimelock(
token,
foundersFund,
releaseTime
);
foundationTimelock = new TokenTimelock(
token,
foundersFund,
releaseTime
);
//we will have the tokens that the founder will get
erc20Mintable.mint(
address(foundersTimelock),
finalTotalTokenSupply.mul(foundersPercentage).div(100)
);
erc20Mintable.mint(
address(partnersTimelock),
finalTotalTokenSupply.mul(partnersPercentage).div(100)
);
erc20Mintable.mint(
address(foundationTimelock),
finalTotalTokenSupply.mul(foundationPercentage).div(100)
);
erc20Mintable.renounceMinter();
// Unpause the token
ERC20Pausable erc20Pausable = new ERC20Pausable(token);
erc20Pausable.unpause();
erc20Pausable.renounceOwnership(wallet);
}
super._finalization();
}
Error 1:
Explicit type conversion not allowed from "function () view returns
(contract IERC20)" to "contract ERC20Mintable". ERC20Mintable
erc20Mintable = ERC20Mintable(token);
Error 2:
Crowdsale.sol:179:46: TypeError: Invalid type for argument in function call. Invalid implicit conversion from function () view returns (contract IERC20) to contract IERC20 requested.
foundersTimelock = new TokenTimelock(token,foundersFund,releaseTime);
^---^
Error 3:
Crowdsale.sol:179:28: TypeError: Type contract TokenTimelock is not
implicitly convertible to expected type address. foundersTimelock =
new TokenTimelock(token,foundersFund,releaseTime);

Related

Tezos LIGO send tezos from contract to an address using jsLigo

I am going to send tezos from contract to an address using jsLigo
if (amount > (0 as tez)) {
let receiver: contract<unit> =
match ((Tezos.get_contract_opt(sender) as option<contract<unit>>), {
Some: (contract) => contract,
None: () => failwith("Contract not found.")
});
Tezos.transaction(unit, (amount as tez), receiver);
}
I am getting this error while building.
Invalid type(s)
Cannot unify operation with unit.
And I am not sure it is correct method to send tezos.

Solidity calling payable function with arguments with hardhat ethers.js

I'm testing this function:
function Deposit(uint256 StopLoss) public payable {//Deposita quantity i es registre
//Pay subscription
if (msg.value == 0){
revert Quantity_zero();
}
//Add wallet to the s_Wallets
s_Wallets.push(payable(msg.sender));
//Start subscription time
Dades storage dades = s_Registre[msg.sender];
dades.Quantity += msg.value;
dades.Stop = StopLoss;
}
When sending value and StopLoss argument it allways send me some error.
This is the js testing code being 1850 the argument StopLoss value and sending a 5 ETH value.
describe("Subscription", async function () {//PriceConversion
it("Subscribes the deployer", async function () {
await MarketOrder.Deposit(1850, {value: ethers.utils.parseEther("5")})
const Quantity = await MarketOrder.CallQuantity()
console.log(`Q: ${Quantity}`)
const Stop = await MarketOrder.CallStop()
console.log(`S: ${Stop}`)
assert.equal(Quantity.toString(), 1850)
assert.equal(Stop.toString(), 5)
}
})
This is the error:
1) MarketOrder Unit Tests
Subscription
Subscribes the deployer:
Error: invalid BigNumber value (argument="value", value=[1850], code=INVALID_ARGUMENT, version=bignumber/5.6.2)
at Logger.makeError (node_modules/#ethersproject/logger/src.ts/index.ts:261:28)
at Logger.throwError (node_modules/#ethersproject/logger/src.ts/index.ts:273:20)
at Logger.throwArgumentError (node_modules/#ethersproject/logger/src.ts/index.ts:277:21)
at Function.BigNumber.from (node_modules/#ethersproject/bignumber/src.ts/bignumber.ts:289:23)
at NumberCoder.encode (node_modules/#ethersproject/abi/src.ts/coders/number.ts:25:27)
at /home/oriok/hh-ff/1.uniswapV3/node_modules/#ethersproject/abi/src.ts/coders/array.ts:71:19
at Array.forEach (<anonymous>)
at pack (node_modules/#ethersproject/abi/src.ts/coders/array.ts:54:12)
at TupleCoder.encode (node_modules/#ethersproject/abi/src.ts/coders/tuple.ts:54:20)
at AbiCoder.encode (node_modules/#ethersproject/abi/src.ts/abi-coder.ts:111:15)
error Command failed with exit code 1.
Does anyone know how to send argument + value properly?? I have tryed many codes but not working.
Ty guys!
ethers.utils.parseEther returns object with BigNumber in it..
you have to convert it into string before using it in the test..
Eg:
ethers.utils.parseEther("5").toString()
Refer.. https://docs.ethers.io/v5/api/utils/display-logic/#utils-parseEther

UniswapV2 pairFor gives wrong contract address

When i try to add liquidity function fails because pairFor returns wrong pair address
original code (not working on ganache, hardhat and testnets)
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash
))));
}
found some similar issues on stackoverflow and they suggested changing init code hash
therefore i used bytes32 public constant INIT_CODE_PAIR_HASH = keccak256(abi.encodePacked(type(UniswapV2Pair).creationCode))
and it still doesn't work
My modified code with new init hash
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
'0x932b4f40ffd7547443affda5e84a39f3efc69f2ca17d46f0f9427e015f0fb178' // init code hash
))));
}```

Smart Contract Lottery throws "VirtualMachineError: revert" when ending the lottery

I have been following Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial (https://www.youtube.com/watch?v=M576WGiDBdQ&t=28658s). When I run deploy_lottery.py, it breaks down while ending the lottery. Here is the snippet of code in Lottery.sol
function endLottery() public onlyOwner {
lottery_state = LOTTERY_STATE.CALCULATING_WINNER;
bytes32 requestId = requestRandomness(keyhash, fee);
emit RequestedRandomness(requestId);
}
Here is the code snippet in deploy_lottery.py
def end_lottery():
account = get_account()
lottery = Lottery[-1]
# fund the contract
# then end the lottery
tx = fund_with_link(lottery.address)
tx.wait(1)
print("Here")
ending_transaction = lottery.endLottery({"from": account})
print("ended transaction")
ending_transaction.wait(1)
time.sleep(180)
print(f"{lottery.recentWinner()} is the new winner!")
I have also attached snapshot of error. Thanks in advance.
https://i.stack.imgur.com/yU8jC.png
I have been stuck with the same error. The solution was to fund the contract with sufficient token. For testing I did
amount=5000000000000000000 in fund_with_link()
def fund_with_link(contract_address, account=None, link_token=None, amount=5000000000000000000):
account = account if account else get_account()
link_token = link_token if link_token else get_contract("link_token")
tx = link_token.transfer(contract_address, amount, {"from": account})
tx.wait(1)
print("Contract Funded")
return tx

Fail to swap ETH to dai using uniswap sdk with web3.js

I am coming across an issue swapping weth to dai using uniswap Node.js SDK with web3.js.
My code is below:
const dai = await Fetcher.fetchTokenData(net, daiAddress);
const weth = await Fetcher.fetchTokenData(net, wethAddress);
const pair = await Fetcher.fetchPairData(dai, weth);
const route = new Route([pair], weth);
console.log(route.midPrice.toSignificant(6))
console.log(route.midPrice.invert().toSignificant(6))
const trade = new Trade(route, new TokenAmount(weth, "1000000000000000000"), TradeType.EXACT_INPUT)
console.log(trade.executionPrice.toSignificant(6))
const slippageTollerance = new Percent("10", "10000")
const amountOutMin = trade.minimumAmountOut(slippageTollerance)
// const amountOutMin = web3.current.utils.toBN(amountOutMinRaw)
const path = [weth.address, dai.address]
const deadline = Math.floor(Date.now() / 1000 ) + 60*20
const amountIn = trade.inputAmount.raw
const to = ""
uniSwapRouter.current = new web3.current.eth.Contract(
uniRouterAbi,
"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"
);
const tx = await uniSwapRouter.current.methods.swapExactETHForTokens(
// amountIn,
1,
to,
path,
deadline
).send({
from:accounts[0],
gasLimit: 8000000,
gasPrice: web3.current.utils.toWei('100', 'Gwei'),
value: web3.current.utils.toWei('1', 'Ether')
})
console.log(tx.hash)
And it turns error:
Unhandled Rejection (Error): expected array value (argument="path", value="", code=INVALID_ARGUMENT, version=abi/5.0.7)
Anyone helps let me know which part I mess up. I have been struggling with it for two days.
I am running it on kovan testnet and I am sure that I have some DAI(11.647) & ETH(2.4845) in my kovan metamask wallet.
I think I found out where the thing gone wrong.
The deadline might be too short to go through the transaction.
It turned out ok after expending the deadline.