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
))));
}```
Related
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);
I want to send a signed POST request to Okex: Authentication Docs POST Request Docs.
I always get back an "invalid sign" error.
I successfully sent a signed GET request. For the POST you also need to add the body in the signature. If I do that, none of my signatures are valid anymore. I already verified that my signature is the same as one produced by their official Python SDK (that's why I wrote the JSON by hand. Python has spaces in the JSON). I am new to Rust so I am hoping I am missing something obvious.
OKEx client implementations in other languages: https://github.com/okcoin-okex/open-api-v3-sdk
/// [dependencies]
/// hmac="0.7.1"
/// reqwest = "0.9.18"
/// chrono = "0.4.6"
/// base64="0.10.1"
/// sha2="0.8.0"
use reqwest::header::{HeaderMap, HeaderValue, CONTENT_TYPE};
use chrono::prelude::{Utc, SecondsFormat};
use hmac::{Hmac, Mac};
use sha2::{Sha256};
static API_KEY: &'static str = "<insert your key!>";
static API_SECRET: &'static str = "<insert your secret!>";
static PASSPHRASE: &'static str = "<insert your passphrase!>";
fn main() {
let timestamp = Utc::now().to_rfc3339_opts(SecondsFormat::Millis, true);
let method = "POST";
let request_path = "/api/spot/v3/orders";
let body_str = "{\"type\": \"market\", \"side\": \"sell\", \"instrument_id\": \"ETH-USDT\", \"size\": \"0.001\"}";
let mut signature_content = String::new();
signature_content.push_str(×tamp);
signature_content.push_str(method);
signature_content.push_str(request_path);
signature_content.push_str(&body_str);
type HmacSha256 = Hmac<Sha256>;
let mut mac = HmacSha256::new_varkey(API_SECRET.as_bytes()).unwrap();
mac.input(signature_content.as_bytes());
let signature = mac.result().code();
let base64_signature = base64::encode(&signature);
let mut header_map = HeaderMap::new();
header_map.insert("OK-ACCESS-KEY", HeaderValue::from_str(API_KEY).unwrap());
header_map.insert("OK-ACCESS-SIGN", HeaderValue::from_str(&base64_signature).unwrap());
header_map.insert("OK-ACCESS-TIMESTAMP", HeaderValue::from_str(×tamp).unwrap());
header_map.insert("OK-ACCESS-PASSPHRASE", HeaderValue::from_str(PASSPHRASE).unwrap());
header_map.insert(CONTENT_TYPE, HeaderValue::from_static("application/json; charset=UTF-8"));
let client = reqwest::Client::new();
let mut complete_url = String::from("https://okex.com");
complete_url.push_str(request_path);
let res = client
.post(complete_url.as_str())
.headers(header_map)
.body(body_str)
.send().unwrap().text();
println!("{:#?}", res);
}
This returns an "Invalid Sign" error at the moment but should return a successful http code (if enough funds are on the account).
Solution was to use "https://www.okex.com" instead of "https://okex.com. The latter produces the "Invalid Sign" error. But just for POST requests. Issue was therefore not Rust related.
I want create multisig address on blockcypher api. pubkeys array is required.
$pubkeys = array(
"02c716d071a76cbf0d29c29cacfec76e0ef8116b37389fb7a3e76d6d32cf59f4d3",
"033ef4d5165637d99b673bcdbb7ead359cee6afd7aaf78d3da9d2392ee4102c8ea",
"022b8934cc41e76cb4286b9f3ed57e2d27798395b04dd23711981a77dc216df8ca"
);
But I don't know, how can I create these keys.
For generate public keys you can use bitcore-lib.
For example if you want use HD keys:
const HdPrivate = require('bitcore-lib').HDPrivateKey;
const HdPublic = require('bitcore-lib').HDPublicKey;
const root = new HdPrivate();
function newPublic(root, depth){
//return the public key at depth
return root.derive(depth).publicKey.toString();
}
const publicKey = newPublic(root, 'm/1');
Of course for you must save and keep secret root.
So I'm trying to create a private/public key from 64 characters that I already know using bitcoinjs with the code below:
key = Bitcoin.ECKey.makeRandom();
// Print your private key (in WIF format)
document.write(key.toWIF());
// => Kxr9tQED9H44gCmp6HAdmemAzU3n84H3dGkuWTKvE23JgHMW8gct
// Print your public key (toString defaults to a Bitcoin address)
document.write(key.pub.getAddress().toString());
// => 14bZ7YWde4KdRb5YN7GYkToz3EHVCvRxkF
If I try to set "key" to my 64 characters instead of "Bitcoin.ECKey.makeRandom();" it fails. Is there a method or library that I overlooked that would allow me to use the known 64 characters in order to generate the private key in wif format and the public address?
Thanks in advance to anyone that may be able to offer some help.
You should use fromWIF method to pass your own data.
from source code of eckey.js
// Static constructors
ECKey.fromWIF = function(string) {
var payload = base58check.decode(string)
var compressed = false
// Ignore the version byte
payload = payload.slice(1)
if (payload.length === 33) {
assert.strictEqual(payload[32], 0x01, 'Invalid compression flag')
// Truncate the compression flag
payload = payload.slice(0, -1)
compressed = true
}
To create WIF from your key please follow https://en.bitcoin.it/wiki/Wallet_import_format
Here is interactive tool http://gobittest.appspot.com/PrivateKey
The solution to generate private and public key:
//public-key
var address = eckey.getBitcoinAddress().toString();
var privateKeyBytesCompressed = privateKeyBytes.slice(0);
privateKeyBytesCompressed.push(0x01);
var privateKeyWIFCompressed = new Bitcoin.Address(privateKeyBytesCompressed);
privateKeyWIFCompressed.version = 0x80;
//private-key
privateKeyWIFCompressed = privateKeyWIFCompressed.toString();
Take a look at moneyart.info for beautifully designed paperwallets.
I have created P2SH address and send coins to the address
https://www.blocktrail.com/tBTC/address/2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r
Next I want to send coins from 2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r address.
How to prepare P2SH transaction and connect it to the output script?
public static void sendFromP2SH(WalletAppKit kit, Address destAdd, Coin coin) throws AddressFormatException, InsufficientMoneyException, ExecutionException, InterruptedException {
Transaction tx = new Transaction(TestNet3Params.get());
tx.addOutput(coin, destAdd); //prepare destination output
Wallet.SendRequest req = Wallet.SendRequest.forTx(tx);
//TODO prepare P2SH input for output //https://www.blocktrail.com/tBTC/address/2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r
Script script = P2SHScript(kit); //2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r
TransactionOutput t = null;//... HOW TO CONNECT P2SH input transaction to the output ?
tx.addInput(t);
kit.wallet().completeTx(req);
kit.wallet().commitTx(req.tx);
kit.peerGroup().broadcastTransaction(req.tx).get();
}
prepare script for the P2SH address 2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r
public static Script P2SHScript(WalletAppKit kit) {
ECKey pubClientKey = kit.wallet().getImportedKeys().get(0);
ECKey pubServerKey = kit.wallet().getImportedKeys().get(1);
return ScriptBuilder.createP2SHOutputScript(1, ImmutableList.of(pubClientKey, pubServerKey));
}
Thank you.
What about the following constructor?
public TransactionOutput(NetworkParameters params, Transaction parent, BigInteger value, Address to)
Inside the code it speculates over the 'to' address to check if it is multisig and creates the output script appropriately.