Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes for Binance Smart Chain/BEP20 integration. #876

Merged
merged 8 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions azure-pipelines-build-stage-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
WASM_BINDGEN_TEST_TIMEOUT: 120
GECKODRIVER: '/home/azureagent/wasm/geckodriver'
# Explicit --test-threads=16 makes testing process slightly faster on agents that have <16 CPU cores.
# Always run tests on mm2.1 branch and PRs
- bash: |
cargo test --all -- --test-threads=16
displayName: 'Test MM2'
Expand All @@ -55,6 +56,7 @@ jobs:
ALICE_PASSPHRASE: $(${{ parameters.alice_passphrase }})
ALICE_USERPASS: $(${{ parameters.alice_userpass }})
RUST_LOG: debug
condition: or( eq( variables['Build.Reason'], 'PullRequest' ), eq( variables['Build.SourceBranchName'], 'mm2.1' ) )
- bash: |
cargo clippy -- -D warnings
displayName: 'Check Clippy warnings'
Expand Down
2 changes: 1 addition & 1 deletion etomic_build/client/buy_ONE_ANOTHER
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ curl --url "http://127.0.0.1:7783" --data '
"method":"buy",
"base":"'$1'",
"rel":"'$2'",
"volume":"1",
"volume":"0.1",
"price":"2"
}
'
3 changes: 3 additions & 0 deletions etomic_build/client/enable_ADEX
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"ADEX\",\"urls\":[\"https://bsc-dataseed.binance.org\"],\"swap_contract_address\":\"0xeDc5b89Fe1f0382F9E4316069971D90a0951DB31\"}"
3 changes: 3 additions & 0 deletions etomic_build/client/enable_BNB
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"BNB\",\"urls\":[\"https://bsc-dataseed.binance.org\"],\"swap_contract_address\":\"0xeDc5b89Fe1f0382F9E4316069971D90a0951DB31\"}"
3 changes: 3 additions & 0 deletions etomic_build/client/enable_BNBT
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"BNBT\",\"urls\":[\"https://data-seed-prebsc-1-s2.binance.org:8545\"],\"swap_contract_address\":\"0xcCD17C913aD7b772755Ad4F0BDFF7B34C6339150\"}"
22 changes: 12 additions & 10 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,9 @@ impl EthCoinImpl {
Box::new(fut)
}

fn estimate_gas(
&self,
req: CallRequest,
block: Option<BlockNumber>,
) -> Box<dyn Future<Item = U256, Error = web3::Error> + Send> {
Box::new(self.web3.eth().estimate_gas(req, block))
fn estimate_gas(&self, req: CallRequest) -> Box<dyn Future<Item = U256, Error = web3::Error> + Send> {
// always using None block number as old Geth version accept only single argument in this RPC
Box::new(self.web3.eth().estimate_gas(req, None))
}

/// Gets `ReceiverSpent` events from etomic swap smart contract since `from_block`
Expand Down Expand Up @@ -426,8 +423,14 @@ async fn withdraw_impl(ctx: MmArc, coin: EthCoin, req: WithdrawRequest) -> Resul
Some(_) => return ERR!("Unsupported input fee type"),
None => {
let gas_price = try_s!(coin.get_gas_price().compat().await);
// covering edge case by deducting the standard transfer fee when we want to max withdraw ETH
let eth_value_for_estimate = if req.max && coin.coin_type == EthCoinType::Eth {
eth_value - gas_price * U256::from(21000)
} else {
eth_value
};
let estimate_gas_req = CallRequest {
value: Some(eth_value),
value: Some(eth_value_for_estimate),
data: Some(data.clone().into()),
from: Some(coin.my_address),
to: call_addr,
Expand All @@ -436,7 +439,7 @@ async fn withdraw_impl(ctx: MmArc, coin: EthCoin, req: WithdrawRequest) -> Resul
// logic on gas price, e.g. TUSD: https://github.com/KomodoPlatform/atomicDEX-API/issues/643
gas_price: Some(gas_price),
};
let gas_fut = coin.estimate_gas(estimate_gas_req, None).compat();
let gas_fut = coin.estimate_gas(estimate_gas_req).compat();
(try_s!(gas_fut.await), gas_price)
},
};
Expand Down Expand Up @@ -2550,10 +2553,9 @@ impl MmCoin for EthCoin {
// Please note if the wallet's balance is insufficient to withdraw, then `estimate_gas` may fail with the `Exception` error.
// Ideally we should determine the case when we have the insufficient balance and return `TradePreimageError::NotSufficientBalance` error.
let gas_limit = try_map!(
coin.estimate_gas(estimate_gas_req, None).compat().await,
coin.estimate_gas(estimate_gas_req).compat().await,
TradePreimageError::Other
);

let total_fee = gas_limit * gas_price;
let amount = try_map!(u256_to_big_decimal(total_fee, 18), TradePreimageError::Other);
Ok(TradeFee {
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/eth/eth_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ fn test_get_fee_to_send_taker_fee() {

EthCoinImpl::get_gas_price.mock_safe(|_| MockResult::Return(Box::new(futures01::future::ok(GAS_PRICE.into()))));
EthCoinImpl::estimate_gas
.mock_safe(|_, _, _| MockResult::Return(Box::new(futures01::future::ok(TRANSFER_GAS_LIMIT.into()))));
.mock_safe(|_, _| MockResult::Return(Box::new(futures01::future::ok(TRANSFER_GAS_LIMIT.into()))));

// fee to send taker fee is `TRANSFER_GAS_LIMIT * gas_price` always.
let amount = u256_to_big_decimal((TRANSFER_GAS_LIMIT * GAS_PRICE).into(), 18).expect("!u256_to_big_decimal");
Expand Down