Skip to content

Commit 0cc0578

Browse files
shamardydimxyonur-ozkanborngracedDeckerSU
committed
chore(release): v2.3.0-beta (#2284)
* feat(LRAPI): add 1inch classic swap rpc (#2222) This commit adds initial code to connect to 1inch Liquidity Routing API (LRAPI) provider and two new RPCs to use 1inch classic swap API. It also adds 'approve' and 'allowance' RPCs (for ERC20 tokens). * chore(release): bump mm2 version to 2.3.0-beta (#2285) * improvement(error-handling): main files (#2288) Makes KDF to check main files (config/coins/etc..) before reading them to prevent potential panics. * fix(rpc): remove character check blocking password input (#2287) This commit removes check for <, >, & characters in RPC request bodies that was incorrectly blocking valid password characters in get_mnemonic RPC call. These special characters should be allowed in passwords. This aligns native behavior with WASM implementation. * don't rely on core (#2289) Signed-off-by: onur-ozkan <work@onurozkan.dev> * chore(ctx): replace gstuff constructible with oncelock (#2267) * chore(adex-cli): use "Komodo DeFi Framework" name in adex_cli (#2290) * bump libp2p (#2296) Signed-off-by: onur-ozkan <work@onurozkan.dev> --------- Signed-off-by: onur-ozkan <work@onurozkan.dev> Co-authored-by: dimxy <dimxy@komodoplatform.com> Co-authored-by: Onur Özkan <work@onurozkan.dev> Co-authored-by: Samuel Onoja <samiodev@icloud.com> Co-authored-by: DeckerSU <support@decker.su>
1 parent 0e7111e commit 0cc0578

File tree

50 files changed

+1572
-167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1572
-167
lines changed

.github/workflows/pr-lint.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
types: |
2323
feat
2424
fix
25+
improvement
2526
chore
2627
docs
2728
deps
@@ -38,9 +39,9 @@ jobs:
3839
TITLE: ${{ github.event.pull_request.title }}
3940
run: |
4041
title_length=${#TITLE}
41-
if [ $title_length -gt 72 ]
42+
if [ $title_length -gt 85 ]
4243
then
43-
echo "PR title is too long (greater than 72 characters)"
44+
echo "PR title is too long (greater than 85 characters)"
4445
exit 1
4546
fi
4647

Cargo.lock

+24-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ members = [
3939
"mm2src/proxy_signature",
4040
"mm2src/rpc_task",
4141
"mm2src/trezor",
42+
"mm2src/trading_api",
4243
]
4344

4445
exclude = [

mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Mm2Cfg {
107107

108108
self.dbdir = CustomType::<InquireOption<String>>::new("What is dbdir")
109109
.with_placeholder(DEFAULT_OPTION_PLACEHOLDER)
110-
.with_help_message("AtomicDEX API database path. Optional, defaults to a subfolder named DB in the path of your mm2 binary")
110+
.with_help_message("Komodo DeFi Framework database path. Optional, defaults to a subfolder named DB in the path of your mm2 binary")
111111
.with_validator(is_reachable_dir)
112112
.prompt()
113113
.map_err(|error|
@@ -128,7 +128,7 @@ impl Mm2Cfg {
128128
fn inquire_net_id(&mut self) -> Result<()> {
129129
self.netid = CustomType::<u16>::new("What is the network `mm2` is going to be a part, netid:")
130130
.with_default(DEFAULT_NET_ID)
131-
.with_help_message(r#"Network ID number, telling the AtomicDEX API which network to join. 8762 is the current main network, though alternative netids can be used for testing or "private" trades"#)
131+
.with_help_message(r#"Network ID number, telling the Komodo DeFi Framework which network to join. 8762 is the current main network, though alternative netids can be used for testing or "private" trades"#)
132132
.with_placeholder(format!("{DEFAULT_NET_ID}").as_str())
133133
.prompt()
134134
.map_err(|error|
@@ -268,7 +268,7 @@ impl Mm2Cfg {
268268
.with_formatter(DEFAULT_OPTION_BOOL_FORMATTER)
269269
.with_default_value_formatter(DEFAULT_DEFAULT_OPTION_BOOL_FORMATTER)
270270
.with_default(InquireOption::None)
271-
.with_help_message("If false the AtomicDEX API will allow rpc methods sent from external IP addresses. Optional, defaults to true. Warning: Only use this if you know what you are doing, and have put the appropriate security measures in place.")
271+
.with_help_message("If false the Komodo DeFi Framework will allow rpc methods sent from external IP addresses. Optional, defaults to true. Warning: Only use this if you know what you are doing, and have put the appropriate security measures in place.")
272272
.prompt()
273273
.map_err(|error|
274274
error_anyhow!("Failed to get rpc_local_only: {error}")
@@ -283,7 +283,7 @@ impl Mm2Cfg {
283283
.with_formatter(DEFAULT_OPTION_BOOL_FORMATTER)
284284
.with_default_value_formatter(DEFAULT_DEFAULT_OPTION_BOOL_FORMATTER)
285285
.with_default(InquireOption::None)
286-
.with_help_message("Runs AtomicDEX API as a seed node mode (acting as a relay for AtomicDEX API clients). Optional, defaults to false. Use of this mode is not reccomended on the main network (8762) as it could result in a pubkey ban if non-compliant. on alternative testing or private networks, at least one seed node is required to relay information to other AtomicDEX API clients using the same netID.")
286+
.with_help_message("Runs Komodo DeFi Framework as a seed node mode (acting as a relay for Komodo DeFi Framework clients). Optional, defaults to false. Use of this mode is not reccomended on the main network (8762) as it could result in a pubkey ban if non-compliant. on alternative testing or private networks, at least one seed node is required to relay information to other Komodo DeFi Framework clients using the same netID.")
287287
.prompt()
288288
.map_err(|error|
289289
error_anyhow!("Failed to get i_am_a_seed: {error}")

mm2src/coins/eth.rs

+18-23
Original file line numberDiff line numberDiff line change
@@ -524,20 +524,6 @@ pub type Web3RpcFut<T> = Box<dyn Future<Item = T, Error = MmError<Web3RpcError>>
524524
pub type Web3RpcResult<T> = Result<T, MmError<Web3RpcError>>;
525525
type EthPrivKeyPolicy = PrivKeyPolicy<KeyPair>;
526526

527-
#[macro_export]
528-
macro_rules! wei_from_gwei_decimal {
529-
($big_decimal: expr) => {
530-
$crate::eth::wei_from_big_decimal($big_decimal, $crate::eth::ETH_GWEI_DECIMALS)
531-
};
532-
}
533-
534-
#[macro_export]
535-
macro_rules! wei_to_gwei_decimal {
536-
($gwei: expr) => {
537-
$crate::eth::u256_to_big_decimal($gwei, $crate::eth::ETH_GWEI_DECIMALS)
538-
};
539-
}
540-
541527
#[derive(Clone, Debug)]
542528
pub(crate) struct LegacyGasPrice {
543529
pub(crate) gas_price: U256,
@@ -582,11 +568,11 @@ impl TryFrom<PayForGasParams> for PayForGasOption {
582568
fn try_from(param: PayForGasParams) -> Result<Self, Self::Error> {
583569
match param {
584570
PayForGasParams::Legacy(legacy) => Ok(Self::Legacy(LegacyGasPrice {
585-
gas_price: wei_from_gwei_decimal!(&legacy.gas_price)?,
571+
gas_price: wei_from_gwei_decimal(&legacy.gas_price)?,
586572
})),
587573
PayForGasParams::Eip1559(eip1559) => Ok(Self::Eip1559(Eip1559FeePerGas {
588-
max_fee_per_gas: wei_from_gwei_decimal!(&eip1559.max_fee_per_gas)?,
589-
max_priority_fee_per_gas: wei_from_gwei_decimal!(&eip1559.max_priority_fee_per_gas)?,
574+
max_fee_per_gas: wei_from_gwei_decimal(&eip1559.max_fee_per_gas)?,
575+
max_priority_fee_per_gas: wei_from_gwei_decimal(&eip1559.max_priority_fee_per_gas)?,
590576
})),
591577
}
592578
}
@@ -1082,6 +1068,9 @@ impl EthCoinImpl {
10821068
let guard = self.erc20_tokens_infos.lock().unwrap();
10831069
(*guard).clone()
10841070
}
1071+
1072+
#[inline(always)]
1073+
pub fn chain_id(&self) -> u64 { self.chain_id }
10851074
}
10861075

10871076
async fn get_raw_transaction_impl(coin: EthCoin, req: RawTransactionRequest) -> RawTransactionResult {
@@ -1204,8 +1193,8 @@ pub async fn withdraw_erc1155(ctx: MmArc, withdraw_type: WithdrawErc1155) -> Wit
12041193
let fee_details = EthTxFeeDetails::new(gas, pay_for_gas_option, fee_coin)?;
12051194

12061195
Ok(TransactionNftDetails {
1207-
tx_hex: BytesJson::from(signed_bytes.to_vec()),
1208-
tx_hash: format!("{:02x}", signed.tx_hash_as_bytes()),
1196+
tx_hex: BytesJson::from(signed_bytes.to_vec()), // TODO: should we return tx_hex 0x-prefixed (everywhere)?
1197+
tx_hash: format!("{:02x}", signed.tx_hash_as_bytes()), // TODO: add 0x hash (use unified hash format for eth wherever it is returned)
12091198
from: vec![eth_coin.my_address()?],
12101199
to: vec![withdraw_type.to],
12111200
contract_type: ContractType::Erc1155,
@@ -1296,7 +1285,7 @@ pub async fn withdraw_erc721(ctx: MmArc, withdraw_type: WithdrawErc721) -> Withd
12961285

12971286
Ok(TransactionNftDetails {
12981287
tx_hex: BytesJson::from(signed_bytes.to_vec()),
1299-
tx_hash: format!("{:02x}", signed.tx_hash_as_bytes()),
1288+
tx_hash: format!("{:02x}", signed.tx_hash_as_bytes()), // TODO: add 0x hash (use unified hash format for eth wherever it is returned)
13001289
from: vec![eth_coin.my_address()?],
13011290
to: vec![withdraw_type.to],
13021291
contract_type: ContractType::Erc721,
@@ -2456,7 +2445,7 @@ impl MarketCoinOps for EthCoin {
24562445
let fut = async move {
24572446
coin.send_raw_transaction(bytes.into())
24582447
.await
2459-
.map(|res| format!("{:02x}", res))
2448+
.map(|res| format!("{:02x}", res)) // TODO: add 0x hash (use unified hash format for eth wherever it is returned)
24602449
.map_err(|e| ERRL!("{}", e))
24612450
};
24622451

@@ -4762,7 +4751,7 @@ impl EthCoin {
47624751
self.call(request, Some(BlockId::Number(BlockNumber::Latest))).await
47634752
}
47644753

4765-
fn allowance(&self, spender: Address) -> Web3RpcFut<U256> {
4754+
pub fn allowance(&self, spender: Address) -> Web3RpcFut<U256> {
47664755
let coin = self.clone();
47674756
let fut = async move {
47684757
match coin.coin_type {
@@ -4827,7 +4816,7 @@ impl EthCoin {
48274816
Box::new(fut.boxed().compat())
48284817
}
48294818

4830-
fn approve(&self, spender: Address, amount: U256) -> EthTxFut {
4819+
pub fn approve(&self, spender: Address, amount: U256) -> EthTxFut {
48314820
let coin = self.clone();
48324821
let fut = async move {
48334822
let token_addr = match coin.coin_type {
@@ -6194,6 +6183,12 @@ pub fn wei_from_big_decimal(amount: &BigDecimal, decimals: u8) -> NumConversResu
61946183
U256::from_dec_str(&amount).map_to_mm(|e| NumConversError::new(format!("{:?}", e)))
61956184
}
61966185

6186+
pub fn wei_from_gwei_decimal(bigdec: &BigDecimal) -> NumConversResult<U256> {
6187+
wei_from_big_decimal(bigdec, ETH_GWEI_DECIMALS)
6188+
}
6189+
6190+
pub fn wei_to_gwei_decimal(wei: U256) -> NumConversResult<BigDecimal> { u256_to_big_decimal(wei, ETH_GWEI_DECIMALS) }
6191+
61976192
impl Transaction for SignedEthTx {
61986193
fn tx_hex(&self) -> Vec<u8> { rlp::encode(self).to_vec() }
61996194

mm2src/coins/eth/eip1559_gas_fee.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Provides estimations of base and priority fee per gas or fetch estimations from a gas api provider
22
33
use super::web3_transport::FeeHistoryResult;
4-
use super::{Web3RpcError, Web3RpcResult};
5-
use crate::{wei_from_gwei_decimal, wei_to_gwei_decimal, EthCoin, NumConversError};
4+
use super::{wei_from_gwei_decimal, wei_to_gwei_decimal, Web3RpcError, Web3RpcResult};
5+
use crate::{EthCoin, NumConversError};
66
use ethereum_types::U256;
77
use mm2_err_handle::mm_error::MmError;
88
use mm2_err_handle::or_mm_error::OrMmError;
@@ -104,24 +104,24 @@ impl TryFrom<InfuraFeePerGas> for FeePerGasEstimated {
104104

105105
fn try_from(infura_fees: InfuraFeePerGas) -> Result<Self, Self::Error> {
106106
Ok(Self {
107-
base_fee: wei_from_gwei_decimal!(&infura_fees.estimated_base_fee)?,
107+
base_fee: wei_from_gwei_decimal(&infura_fees.estimated_base_fee)?,
108108
low: FeePerGasLevel {
109-
max_fee_per_gas: wei_from_gwei_decimal!(&infura_fees.low.suggested_max_fee_per_gas)?,
110-
max_priority_fee_per_gas: wei_from_gwei_decimal!(&infura_fees.low.suggested_max_priority_fee_per_gas)?,
109+
max_fee_per_gas: wei_from_gwei_decimal(&infura_fees.low.suggested_max_fee_per_gas)?,
110+
max_priority_fee_per_gas: wei_from_gwei_decimal(&infura_fees.low.suggested_max_priority_fee_per_gas)?,
111111
min_wait_time: Some(infura_fees.low.min_wait_time_estimate),
112112
max_wait_time: Some(infura_fees.low.max_wait_time_estimate),
113113
},
114114
medium: FeePerGasLevel {
115-
max_fee_per_gas: wei_from_gwei_decimal!(&infura_fees.medium.suggested_max_fee_per_gas)?,
116-
max_priority_fee_per_gas: wei_from_gwei_decimal!(
117-
&infura_fees.medium.suggested_max_priority_fee_per_gas
115+
max_fee_per_gas: wei_from_gwei_decimal(&infura_fees.medium.suggested_max_fee_per_gas)?,
116+
max_priority_fee_per_gas: wei_from_gwei_decimal(
117+
&infura_fees.medium.suggested_max_priority_fee_per_gas,
118118
)?,
119119
min_wait_time: Some(infura_fees.medium.min_wait_time_estimate),
120120
max_wait_time: Some(infura_fees.medium.max_wait_time_estimate),
121121
},
122122
high: FeePerGasLevel {
123-
max_fee_per_gas: wei_from_gwei_decimal!(&infura_fees.high.suggested_max_fee_per_gas)?,
124-
max_priority_fee_per_gas: wei_from_gwei_decimal!(&infura_fees.high.suggested_max_priority_fee_per_gas)?,
123+
max_fee_per_gas: wei_from_gwei_decimal(&infura_fees.high.suggested_max_fee_per_gas)?,
124+
max_priority_fee_per_gas: wei_from_gwei_decimal(&infura_fees.high.suggested_max_priority_fee_per_gas)?,
125125
min_wait_time: Some(infura_fees.high.min_wait_time_estimate),
126126
max_wait_time: Some(infura_fees.high.max_wait_time_estimate),
127127
},
@@ -143,33 +143,33 @@ impl TryFrom<BlocknativeBlockPricesResponse> for FeePerGasEstimated {
143143
return Ok(FeePerGasEstimated::default());
144144
}
145145
Ok(Self {
146-
base_fee: wei_from_gwei_decimal!(&block_prices.block_prices[0].base_fee_per_gas)?,
146+
base_fee: wei_from_gwei_decimal(&block_prices.block_prices[0].base_fee_per_gas)?,
147147
low: FeePerGasLevel {
148-
max_fee_per_gas: wei_from_gwei_decimal!(
149-
&block_prices.block_prices[0].estimated_prices[2].max_fee_per_gas
148+
max_fee_per_gas: wei_from_gwei_decimal(
149+
&block_prices.block_prices[0].estimated_prices[2].max_fee_per_gas,
150150
)?,
151-
max_priority_fee_per_gas: wei_from_gwei_decimal!(
152-
&block_prices.block_prices[0].estimated_prices[2].max_priority_fee_per_gas
151+
max_priority_fee_per_gas: wei_from_gwei_decimal(
152+
&block_prices.block_prices[0].estimated_prices[2].max_priority_fee_per_gas,
153153
)?,
154154
min_wait_time: None,
155155
max_wait_time: None,
156156
},
157157
medium: FeePerGasLevel {
158-
max_fee_per_gas: wei_from_gwei_decimal!(
159-
&block_prices.block_prices[0].estimated_prices[1].max_fee_per_gas
158+
max_fee_per_gas: wei_from_gwei_decimal(
159+
&block_prices.block_prices[0].estimated_prices[1].max_fee_per_gas,
160160
)?,
161-
max_priority_fee_per_gas: wei_from_gwei_decimal!(
162-
&block_prices.block_prices[0].estimated_prices[1].max_priority_fee_per_gas
161+
max_priority_fee_per_gas: wei_from_gwei_decimal(
162+
&block_prices.block_prices[0].estimated_prices[1].max_priority_fee_per_gas,
163163
)?,
164164
min_wait_time: None,
165165
max_wait_time: None,
166166
},
167167
high: FeePerGasLevel {
168-
max_fee_per_gas: wei_from_gwei_decimal!(
169-
&block_prices.block_prices[0].estimated_prices[0].max_fee_per_gas
168+
max_fee_per_gas: wei_from_gwei_decimal(
169+
&block_prices.block_prices[0].estimated_prices[0].max_fee_per_gas,
170170
)?,
171-
max_priority_fee_per_gas: wei_from_gwei_decimal!(
172-
&block_prices.block_prices[0].estimated_prices[0].max_priority_fee_per_gas
171+
max_priority_fee_per_gas: wei_from_gwei_decimal(
172+
&block_prices.block_prices[0].estimated_prices[0].max_priority_fee_per_gas,
173173
)?,
174174
min_wait_time: None,
175175
max_wait_time: None,
@@ -260,7 +260,7 @@ impl FeePerGasSimpleEstimator {
260260
let max_priority_fee_per_gas = Self::percentile_of(&level_rewards, Self::PRIORITY_FEE_PERCENTILES[level_index]);
261261
// Convert the priority fee to BigDecimal gwei, falling back to 0 on error.
262262
let max_priority_fee_per_gas_gwei =
263-
wei_to_gwei_decimal!(max_priority_fee_per_gas).unwrap_or_else(|_| BigDecimal::from(0));
263+
wei_to_gwei_decimal(max_priority_fee_per_gas).unwrap_or_else(|_| BigDecimal::from(0));
264264

265265
// Calculate the max fee per gas by adjusting the base fee and adding the priority fee.
266266
let adjust_max_fee =
@@ -273,7 +273,7 @@ impl FeePerGasSimpleEstimator {
273273

274274
Ok(FeePerGasLevel {
275275
max_priority_fee_per_gas,
276-
max_fee_per_gas: wei_from_gwei_decimal!(&max_fee_per_gas_dec)?,
276+
max_fee_per_gas: wei_from_gwei_decimal(&max_fee_per_gas_dec)?,
277277
// TODO: Consider adding default wait times if applicable (and mark them as uncertain).
278278
min_wait_time: None,
279279
max_wait_time: None,
@@ -290,7 +290,7 @@ impl FeePerGasSimpleEstimator {
290290
.first()
291291
.cloned()
292292
.unwrap_or_else(|| U256::from(0));
293-
let latest_base_fee_dec = wei_to_gwei_decimal!(latest_base_fee).unwrap_or_else(|_| BigDecimal::from(0));
293+
let latest_base_fee_dec = wei_to_gwei_decimal(latest_base_fee).unwrap_or_else(|_| BigDecimal::from(0));
294294

295295
// The predicted base fee is not used for calculating eip1559 values here and is provided for other purposes
296296
// (f.e if the caller would like to do own estimates of max fee and max priority fee)

mm2src/coins/eth/eth_rpc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ impl EthCoin {
241241
.and_then(|t| serde_json::from_value(t).map_err(Into::into))
242242
}
243243

244-
/// Get chain id
245-
pub(crate) async fn chain_id(&self) -> Result<U256, web3::Error> {
244+
/// Get chain id from network
245+
pub(crate) async fn network_chain_id(&self) -> Result<U256, web3::Error> {
246246
self.try_rpc_send("eth_chainId", vec![])
247247
.await
248248
.and_then(|t| serde_json::from_value(t).map_err(Into::into))

mm2src/coins/eth/eth_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use super::*;
22
use crate::IguanaPrivKey;
3-
use common::{block_on, block_on_f01};
3+
use common::block_on;
44
use mm2_core::mm_ctx::MmCtxBuilder;
55

66
cfg_native!(
77
use crate::eth::for_tests::{eth_coin_for_test, eth_coin_from_keypair};
88
use crate::DexFee;
99

10-
use common::now_sec;
10+
use common::{now_sec, block_on_f01};
1111
use ethkey::{Generator, Random};
1212
use mm2_test_helpers::for_tests::{ETH_MAINNET_CHAIN_ID, ETH_MAINNET_NODE, ETH_SEPOLIA_CHAIN_ID, ETH_SEPOLIA_NODES,
1313
ETH_SEPOLIA_TOKEN_CONTRACT};

mm2src/coins/hd_wallet/storage/sqlite_storage.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl HDWalletStorageInternalOps for HDWalletSqliteStorage {
101101
where
102102
Self: Sized,
103103
{
104-
let shared = ctx.shared_sqlite_conn.as_option().or_mm_err(|| {
104+
let shared = ctx.shared_sqlite_conn.get().or_mm_err(|| {
105105
HDWalletStorageError::Internal("'MmCtx::shared_sqlite_conn' is not initialized".to_owned())
106106
})?;
107107
let storage = HDWalletSqliteStorage {

mm2src/coins/lightning/ln_utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub async fn init_db(ctx: &MmArc, ticker: String) -> EnableLightningResult<Sqlit
8787
let db = SqliteLightningDB::new(
8888
ticker,
8989
ctx.sqlite_connection
90+
.get()
9091
.ok_or(MmError::new(EnableLightningError::DbError(
9192
"sqlite_connection is not initialized".into(),
9293
)))?

0 commit comments

Comments
 (0)