Get pool balances from BalancerV2 in Solidity - solidity

I am trying to inspect the pool balances of a decentralized exchange called Balancer. The implementation is done with the main version V2.
I want to get the pool balance with
vault.getPoolTokens(0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014);
The contract looks like this:
contract BalancerV2 {
IVault private constant vault = "0xBA12222222228d8Ba445958a75a0704d566BF2C8";
function getPoolTokens() public view returns(uint) {
return vault.getPoolTokens(0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014);
}
}
But it gives me the following error message:
from solidity:
contracts/BalancerV2.sol:8:37: TypeError: Type literal_string "0xBA12222222228d8Ba445958a75a0704d566BF2C8" is not implicitly convertible to expected type contract IVault.
IVault private constant vault = "0xBA12222222228d8Ba445958a75a0704d566BF2C8";
^------------------------------------------^
My question is:
How is it possible that even in the official GitHub repository they have a working example of how to initialize the vault with solidity compiler version 0.7.0 and I'm literally trying the same with getting this error?
By the way, the example in the documentation has a typo so it won't compile. Just in case if someone from the devs sees this.
https://dev.balancer.fi/resources/pool-interfacing#pool-balances
I am trying to compile this contract and am expecting to get this result:
tokens: [0xba100000625a3754423978a60c9317c58a424e3D,
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2]
balances: [5720903090084350251216632,
7939247003721636150710]

Instead of:
IVault private constant vault = "0xBA12222222228d8Ba445958a75a0704d566BF2C8";
try this:
IVault private constant vault = IVault(0xBA12222222228d8Ba445958a75a0704d566BF2C8);

Related

solidity : bytecode optimization : require( condition ) issue

I have a solidity code which uses an optimization=200 in remix.
I'm suspicious if optimization is buggy on my code.
when I use for example :
mapping(address => uint8) allowedUsers;
function doSomething(address wallet) external {
...
require( allowedUsers[wallet]!=1, "User already set" );
allowedUsers[wallet]=1;
...
if I run it on binance mainnet or under rinkeby, there is no issue.
But sometimes randomly when used on ethereum mainnet I'm getting
revert error "User already set".
What is strange, It occurs on the first function call for a wallet. But not always.
It seems mapping & require have issues together. because it can occur on another require with mapping not just as on this example.
I cannot disable optimization since bytecode is nearly 25400 bytes out of 25476 allowed.
Any idea what's wrong?
I'm using solidity 0.8.15
The issue was something completely different, and was happening in the ethereum mempool.
I understand what happened : I've been front-runned by a MEV BOT. It detected an ETH transaction was sent from my smartcontract, and sent a copy-cat of the transaction earlier than mine.
I've put counter-actions to avoid it. it's okay now.

what is the difference between these two ethers.js functions [duplicate]

Can somebody please point me to the documentation (official or otherwise ) that explains the function ethers.getContractAt():
the original context of this is as follows:
vrfCoordinator = await ethers.getContractAt('VRFCoordinatorMock', VRFCoordinatorMock.address, signer)
and the full code can be found here...
https://github.com/PatrickAlphaC/all-on-chain-generated-nft/blob/main/deploy/02_Deploy_RandomSVG.js
In the absence of such documentation, an explanation would be much appreciated. Thank you!
The getContractAt() function is part of the hardhat-ethers plugin for Hardhat, expanding the ethers object.
It's not a part of the core Ethers package, so it's not included in their documentation.
Hardhat docs mentioning the plugin: https://hardhat.org/plugins/nomiclabs-hardhat-ethers.html#helpers
Basically, it is doing the same thing, that attach do but in one line. i.e you can actually interact with an already deployed contract.
For reference below is the code if you are using attach
let xyzContract = await hre.ethers.getContractFactory("Name of the contract");
let xyzContractInstance = xyzContract.attach('Address of the contract');
You can accomplish the same thing in one line via getContractAt() when using hardhat
let xyzContractInstance = await hre.ethers.getContractAt(
"Contract Address",
deployed contract address
);

Verifying a Contract on BSCScan.com

I created a cryptocurrency with the help of a friend of mine (it took us ages to copy-paste codes from here and there) and to edit the contract's info, which is crucial for me, I now need to verify the contract. Here's my contract address:
0xe1c7a0d5e099a1f0c14b60b0c320423cf2f4543b
and here is the code I used in Remix:
pragma solidity >=0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract HelpingArtistsAtRisk is ERC20 {
constructor(uint256 initialsupply) public ERC20 ("Helping Artists At Risk", "HAAR"){
_mint(msg.sender,initialsupply);}
}
It gives me error after error when I try to verify it. Here are the error messages:
Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: " to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> myc
ParserError: Source "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol" not found: File import callback not supported
--> myc:3:1:
|
3 | import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol"
BEP-20.sol:1:1: Error: Compiler version >=0.8.0 does not satisfy the r semver requirement
ParserError: Expected pragma, import directive or contract/interface/library/struct/enum/constant/function definition.
--> myc:1:1:
|
1 | "SPDX-License-Identifier: UNLICENSED"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I just wanted to have the BSCSCAN's verification.
Since solidity 0.6.8 you should set a License header to your contract, so you need to add this at the first line of your file:
// SPDX-License-Identifier: UNLICENSED
You can use the UNLICENSED or use one of the predefined licenses. Here is the list: https://spdx.org/licenses/
More information about the SPDX License herader here: https://forum.openzeppelin.com/t/solidity-0-6-8-introduces-spdx-license-identifiers/2859
This should fix your first Warning and the last error.
After making this change I was able to compile the contract using remix, but I think that all other errors are related with the compiler version, could you share version and other settings that you see in the compiler options?
I'm using Compiler 0.8.4+commit.c7e474f2
Also you need to remove the public keyword in the constructor, it is ignored by the compiler. The final result is:
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract HelpingArtistsAtRisk is ERC20 {
constructor(uint256 initialsupply) ERC20 ("Helping Artists At Risk", "HAAR"){
_mint(msg.sender,initialsupply);}
}

How to update deployed Ethereum smart contract with ABI only through console (Truffle)

I need to update value on deployed contract ( I dont have sol neither it has been deployed on my platform )
I want to update param with setter in contract and call getter to see changed value .. always default value comes back!
here is the code Im using :
new web3.eth.Contract(HelloWorld.abi,'0x085Ab4C596535FFCE5B520D277f1C01236a656CB').methods.setMessage('Hi').call()
=> Result {}
then call :
new web3.eth.Contract(HelloWorld.abi,'0x085Ab4C596535FFCE5B520D277f1C01236a656CB').methods.getMessage().call()
=>
'hello world10' 🤔
Im using Truffle console:
truffle console --network ropsten
one comment if I use :
HelloWorld.deployed().then(instance => instance.setMessage('new Hi').call())
then call:
HelloWorld.deployed().then(instance => instance.getMessage.call()).then(result => message = result)
then I got expected value .. but I don't have deployed contract. neither sol. all what I have part ABI
Is it wrong with my calls that should be async .. or I need to redeploy contract ?
Im still new in this crypto-world 🙂
welcome to the "crypto-world" as you named it.
I've got a bit lost on your question but what you want is to deploy a contract with an initial message and then change that message using setMessage method, all through the console.
First thing you are doing wrong is calling the "setMessage" method using .call(). When you want to change something in the blockchain, you will send a transaction, and to send a transaction you need to specify an account. The correct method should be .send({ from: "you-account-address" }).
In order to simplify a bit, let me just show a few lines that you can use and then explain
$ > truffle console --network ropsten
$ (truffle) > helloInstance = await HelloWorld.deployed()
$ (truffle) > await helloInstance.getMessage()
$ (truffle) > await helloInstance.setMessage("new Hi", { from: "you-account-address" })
So, basically, all calls are async. First, you call HelloWorld.deployed() because when you deployed the contracts with truffle, truffle created a folder named "build" where it saved the contracts with all the necessary data, that's why you don't need to specify the address neither the abi. This is totally different from using web3.js in which you need to specify both.
Then, you can just call the methods.
You can find more detailed information here https://www.trufflesuite.com/docs/truffle/getting-started/interacting-with-your-contracts

NoValueFactoryException when using Zeroc Ice - Sliced vs. compact format?

I am trying to use an Ice client in an OSGi context. Running the server and a minimal example client in a non-OSGi environment works fine. With the client in an OSGi environment I get the following exception:
com.zeroc.Ice.NoValueFactoryException
reason = "no value factory found and compact format prevents slicing (the sender should use the sliced format instead)"
type = "::MyModule::Knowledge::CMKnowledge"
However, I am not 100% sure, if the OSGi runtime makes a difference here. The Slice file looks like this:
module MyModule{
module Knowledge{
class KnowledgePart{
string value;
}
class FMKnowledge extends KnowledgePart{}
class CMKnowledge extends KnowledgePart{}
interface IKnowledge{
void sendKnowledge(KnowledgePart knowledge);
FMKnowledge getFMKnowledge();
CMKnowledge getCMKnowledge();
}
}
}
What does this exception mean in this context and how can I fix it? I already tried to set ["format:sliced"] instead of the implicitly used compact format.
The error mean that Ice run-time try to load MyModule.Knowledge.CMKnowledge class but it failed to do so. You must ensure that the class loader used by the application can load MyModule.Knowledge.CMKnowledgeclass.
See also https://doc.zeroc.com/ice/3.7/language-mappings/java-mapping/custom-class-loaders