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

V2 erc activation #2235

Closed
wants to merge 4 commits into from
Closed
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
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ add_executable(${PROJECT_NAME}_tests MACOSX_BUNDLE ${ICON}
tests/api/komodo_prices/komodo.prices.tests.cpp
tests/api/mm2/mm2.rpc.trade.preimage.tests.cpp
tests/api/mm2/mm2.fraction.tests.cpp
tests/api/mm2/enable_bch_with_tokens_rpc_tests.cpp
tests/api/mm2/rpc2.enable_bch_with_tokens_tests.cpp
tests/api/mm2/rpc2.enable_eth_with_tokens_tests.cpp

##! Utilities
tests/utilities/qt.utilities.tests.cpp
Expand Down
11 changes: 8 additions & 3 deletions src/core/atomicdex/api/mm2/mm2.client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

#include <meta/detection/detection.hpp>

#include "enable_slp_rpc.hpp"
#include "get_public_key_rpc.hpp"
#include "enable_bch_with_tokens_rpc.hpp"
#include "rpc2.enable_slp.hpp"
#include "rpc2.get_public_key.hpp"
#include "rpc2.enable_bch_with_tokens.hpp"
#include "my_tx_history_rpc.hpp"
#include "my_tx_history_v1_rpc.hpp"
#include "mm2.client.hpp"
Expand All @@ -30,6 +30,8 @@
#include "rpc.tx.history.hpp"
#include "rpc2.enable_tendermint_token.hpp"
#include "rpc2.enable_tendermint_with_assets.hpp"
#include "rpc2.enable_erc20.hpp"
#include "rpc2.enable_eth_with_tokens.hpp"

namespace
{
Expand Down Expand Up @@ -167,6 +169,9 @@ namespace atomic_dex::mm2
template void mm2_client::process_rpc_async<enable_tendermint_with_assets_rpc>(const std::function<void(enable_tendermint_with_assets_rpc)>&);
template void mm2_client::process_rpc_async<my_tx_history_rpc>(const std::function<void(my_tx_history_rpc)>&);
template void mm2_client::process_rpc_async<my_tx_history_v1_rpc>(const std::function<void(my_tx_history_v1_rpc)>&);

template void mm2_client::process_rpc_async<enable_erc20_rpc>(const std::function<void(enable_erc20_rpc)>&);
template void mm2_client::process_rpc_async<enable_eth_with_tokens_rpc>(const std::function<void(enable_eth_with_tokens_rpc)>&);

template <mm2::rpc Rpc>
void mm2_client::process_rpc_async(typename Rpc::expected_request_type request, const std::function<void(Rpc)>& on_rpc_processed)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <nlohmann/json.hpp>

#include "enable_bch_with_tokens_rpc.hpp"
#include "rpc2.enable_bch_with_tokens.hpp"

namespace atomic_dex::mm2
{
Expand Down
26 changes: 26 additions & 0 deletions src/core/atomicdex/api/mm2/rpc2.enable_erc20.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <nlohmann/json.hpp>

#include "rpc2.enable_erc20.hpp"

namespace atomic_dex::mm2
{
void to_json(nlohmann::json& j, const enable_erc20_rpc_request& request)
{
j["ticker"] = request.ticker;
if (request.activation_params.required_confirmations)
{
j["activation_params"]["required_confirmations"] = *request.activation_params.required_confirmations;
}
else
{
j["activation_params"] = nlohmann::json::object();
}
}

void from_json(const nlohmann::json& j, enable_erc20_rpc_result& in)
{
j.at("platform_coin").get_to(in.platform_coin);
j.at("required_confirmations").get_to(in.required_confirmations);
j.at("balances").get_to<std::unordered_map<std::string, balance_info>>(in.balances);
}
}
59 changes: 59 additions & 0 deletions src/core/atomicdex/api/mm2/rpc2.enable_erc20.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/******************************************************************************
* Copyright © 2013-2022 The Komodo Platform Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* Komodo Platform software, including this file may be copied, modified, *
* propagated or distributed except according to the terms contained in the *
* LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/

#pragma once

#include <string>

#include <nlohmann/json_fwd.hpp> //> nlohmann::json

#include "rpc.hpp"
#include "balance_info.hpp"

namespace atomic_dex::mm2
{
struct enable_erc20_rpc
{
static constexpr auto endpoint = "enable_erc20";
static constexpr bool is_v2 = true;

struct expected_request_type
{
std::string ticker;
struct { std::optional<int> required_confirmations; } activation_params;
};

struct expected_result_type
{
std::string platform_coin;
int required_confirmations;
std::unordered_map<std::string, balance_info> balances;
};

using expected_error_type = rpc_basic_error_type;

expected_request_type request;
std::optional<expected_result_type> result;
std::optional<expected_error_type> error;
};

using enable_erc20_rpc_request = enable_erc20_rpc::expected_request_type;
using enable_erc20_rpc_result = enable_erc20_rpc::expected_result_type;
using enable_erc20_rpc_error = enable_erc20_rpc::expected_error_type;

void to_json(nlohmann::json& j, const enable_erc20_rpc_request& request);
void from_json(const nlohmann::json& j, enable_erc20_rpc_result& in);
}
151 changes: 151 additions & 0 deletions src/core/atomicdex/api/mm2/rpc2.enable_eth_with_tokens.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#include <nlohmann/json.hpp>

#include "rpc2.enable_eth_with_tokens.hpp"

namespace atomic_dex::mm2
{
void to_json(nlohmann::json& j, const enable_eth_with_tokens_request_rpc& in)
{
j["ticker"] = in.ticker;
j["nodes"] = in.nodes;
j["tx_history"] = in.tx_history;
j["erc20_tokens_requests"] = in.erc20_tokens_requests;
if (in.required_confirmations.has_value())
j["required_confirmations"] = in.required_confirmations.value();
if (in.requires_notarization.has_value())
j["requires_notarization"] = in.requires_notarization.value();

switch (in.coin_type)
{
case CoinType::ERC20:
{
j["gas_station_url"] = eth_gas_station_url;
j["swap_contract_address"] = in.is_testnet.value_or(false) ? erc_testnet_swap_contract_address : erc_swap_contract_address;
j["fallback_swap_contract"] = in.is_testnet.value_or(false) ? erc_testnet_fallback_swap_contract_address : erc_fallback_swap_contract_address;
break;
}
case CoinType::Matic:
{
SPDLOG_INFO("MATIC");
j["gas_station_url"] = in.is_testnet.value_or(false) ? testnet_matic_gas_station_url : matic_gas_station_url;
j["gas_station_decimals"] = 9;
j["swap_contract_address"] = in.is_testnet.value_or(false) ? matic_erc_testnet_swap_contract_address : matic_erc_swap_contract_address;
j["fallback_swap_contract"] = in.is_testnet.value_or(false) ? matic_erc_testnet_fallback_swap_contract_address : matic_erc_fallback_swap_contract_address;
break;
}
case CoinType::Arbitrum:
{
j["swap_contract_address"] = arbitrum_erc_swap_contract_address;
j["fallback_swap_contract"] = arbitrum_erc_fallback_swap_contract_address;
break;
}
case CoinType::BEP20:
{
j["swap_contract_address"] = in.is_testnet.value_or(false) ? bnb_testnet_swap_contract_address : bnb_swap_contract_address;
j["fallback_swap_contract"] = in.is_testnet.value_or(false) ? bnb_testnet_fallback_swap_contract_address : bnb_fallback_swap_contract_address;
break;
}
case CoinType::AVX20:
{
j["swap_contract_address"] = in.is_testnet.value_or(false) ? avax_erc_testnet_swap_contract_address : avax_erc_swap_contract_address;
j["fallback_swap_contract"] = in.is_testnet.value_or(false) ? avax_erc_testnet_fallback_swap_contract_address : avax_erc_fallback_swap_contract_address;
break;
}
case CoinType::FTM20:
{
j["swap_contract_address"] = in.is_testnet.value_or(false) ? ftm_erc_testnet_swap_contract_address : ftm_erc_swap_contract_address;
j["fallback_swap_contract"] = in.is_testnet.value_or(false) ? ftm_erc_testnet_fallback_swap_contract_address : ftm_erc_fallback_swap_contract_address;
break;
}
case CoinType::HRC20:
{
j["swap_contract_address"] = in.is_testnet.value_or(false) ? one_erc_testnet_swap_contract_address : one_erc_swap_contract_address;
j["fallback_swap_contract"] = in.is_testnet.value_or(false) ? one_erc_testnet_fallback_swap_contract_address : one_erc_fallback_swap_contract_address;
break;
}
case CoinType::Ubiq:
{
j["swap_contract_address"] = in.is_testnet.value_or(false) ? ubiq_erc_testnet_swap_contract_address : ubiq_erc_swap_contract_address;
j["fallback_swap_contract"] = in.is_testnet.value_or(false) ? ubiq_erc_testnet_fallback_swap_contract_address : ubiq_erc_fallback_swap_contract_address;
break;
}
case CoinType::KRC20:
{
j["swap_contract_address"] = in.is_testnet.value_or(false) ? krc_erc_testnet_swap_contract_address : krc_erc_swap_contract_address;
j["fallback_swap_contract"] = in.is_testnet.value_or(false) ? krc_erc_testnet_fallback_swap_contract_address : krc_erc_fallback_swap_contract_address;
break;
}
case CoinType::Moonriver:
{
j["swap_contract_address"] = in.is_testnet.value_or(false) ? movr_erc_testnet_swap_contract_address : movr_erc_swap_contract_address;
j["fallback_swap_contract"] = in.is_testnet.value_or(false) ? movr_erc_testnet_fallback_swap_contract_address : movr_erc_fallback_swap_contract_address;
break;
}
case CoinType::Moonbeam:
{
j["swap_contract_address"] = in.is_testnet.value_or(false) ? glmr_erc_testnet_swap_contract_address : glmr_erc_swap_contract_address;
j["fallback_swap_contract"] = in.is_testnet.value_or(false) ? glmr_erc_testnet_fallback_swap_contract_address : glmr_erc_fallback_swap_contract_address;
break;
}
case CoinType::HecoChain:
{
j["swap_contract_address"] = in.is_testnet.value_or(false) ? hco_erc_testnet_swap_contract_address : hco_erc_swap_contract_address;
j["fallback_swap_contract"] = in.is_testnet.value_or(false) ? hco_erc_testnet_fallback_swap_contract_address : hco_erc_fallback_swap_contract_address;
break;
}
case CoinType::SmartBCH:
{
j["swap_contract_address"] = in.is_testnet.value_or(false) ? sbch_erc_testnet_swap_contract_address : sbch_erc_swap_contract_address;
j["fallback_swap_contract"] = in.is_testnet.value_or(false) ? sbch_erc_testnet_fallback_swap_contract_address : sbch_erc_fallback_swap_contract_address;
break;
}
case CoinType::EthereumClassic:
{
j["swap_contract_address"] = in.is_testnet.value_or(false) ? etc_erc_testnet_swap_contract_address : etc_erc_swap_contract_address;
j["fallback_swap_contract"] = in.is_testnet.value_or(false) ? etc_erc_testnet_fallback_swap_contract_address : etc_erc_fallback_swap_contract_address;
break;
}
case CoinType::RSK:
{
j["swap_contract_address"] = in.is_testnet.value_or(false) ? rsk_erc_testnet_swap_contract_address : rsk_erc_swap_contract_address;
j["fallback_swap_contract"] = in.is_testnet.value_or(false) ? rsk_erc_testnet_fallback_swap_contract_address : rsk_erc_fallback_swap_contract_address;
break;
}
default:
break;
}
}

void to_json(nlohmann::json& j, const enable_eth_with_tokens_request_rpc::erc20_token_request_t& in)
{
j["ticker"] = in.ticker;
if (in.required_confirmations)
j["required_confirmations"] = in.required_confirmations.value();
}

void from_json(const nlohmann::json& json, enable_eth_with_tokens_result_rpc& out)
{
out.current_block = json["current_block"];
out.eth_addresses_infos = json["eth_addresses_infos"].get<typeof(out.eth_addresses_infos)>();
out.erc20_addresses_infos = json["erc20_addresses_infos"].get<typeof(out.erc20_addresses_infos)>();
}

void from_json(const nlohmann::json& json, enable_eth_with_tokens_result_rpc::derivation_method_t& out)
{
out.type = json["type"];
}

void from_json(const nlohmann::json& json, enable_eth_with_tokens_result_rpc::eth_address_infos_t& out)
{
out.derivation_method = json["derivation_method"];
out.pubkey = json["pubkey"];
out.balances = json["balances"];
}

void from_json(const nlohmann::json& json, enable_eth_with_tokens_result_rpc::erc20_address_infos_t& out)
{
out.derivation_method = json["derivation_method"];
out.pubkey = json["pubkey"];
out.balances = json["balances"].get<typeof(out.balances)>();
}
}
94 changes: 94 additions & 0 deletions src/core/atomicdex/api/mm2/rpc2.enable_eth_with_tokens.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/******************************************************************************
* Copyright © 2013-2021 The Komodo Platform Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* Komodo Platform software, including this file may be copied, modified, *
* propagated or distributed except according to the terms contained in the *
* LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/

#pragma once

#include <vector>

#include "rpc.hpp"
#include "balance_info.hpp"
#include "atomicdex/config/enable.cfg.hpp"
#include "atomicdex/constants/qt.coins.enums.hpp"
#include "atomicdex/constants/erc.constants.hpp"

namespace atomic_dex::mm2
{
struct enable_eth_with_tokens_rpc
{
static constexpr auto endpoint = "enable_eth_with_tokens";
static constexpr bool is_v2 = true;

struct expected_request_type
{
struct erc20_token_request_t
{
std::string ticker;
std::optional<int> required_confirmations;
};

std::string ticker;
CoinType coin_type;
std::optional<std::string> gas_station_url;
std::string swap_contract_address;
std::string fallback_swap_contract;
bool tx_history{true};
std::optional<bool> is_testnet{false};
std::optional<size_t> gas_station_decimals;
std::optional<int> required_confirmations;
std::optional<bool> requires_notarization;
std::vector<node> nodes;
std::vector<erc20_token_request_t> erc20_tokens_requests;
};

struct expected_result_type
{
struct derivation_method_t { std::string type; };
struct eth_address_infos_t
{
derivation_method_t derivation_method;
std::string pubkey;
balance_info balances;
};
struct erc20_address_infos_t
{
derivation_method_t derivation_method;
std::string pubkey;
std::unordered_map<std::string, balance_info> balances;
};

std::size_t current_block;
std::unordered_map<std::string, eth_address_infos_t> eth_addresses_infos;
std::unordered_map<std::string, erc20_address_infos_t> erc20_addresses_infos;
};

using expected_error_type = rpc_basic_error_type;

expected_request_type request;
std::optional<expected_result_type> result;
std::optional<expected_error_type> error;
};

using enable_eth_with_tokens_request_rpc = enable_eth_with_tokens_rpc::expected_request_type;
using enable_eth_with_tokens_result_rpc = enable_eth_with_tokens_rpc::expected_result_type;
using enable_eth_with_tokens_error_rpc = enable_eth_with_tokens_rpc::expected_error_type;

void to_json(nlohmann::json& j, const enable_eth_with_tokens_request_rpc& in);
void to_json(nlohmann::json& j, const enable_eth_with_tokens_request_rpc::erc20_token_request_t& in);
void from_json(const nlohmann::json& json, enable_eth_with_tokens_result_rpc& out);
void from_json(const nlohmann::json& json, enable_eth_with_tokens_result_rpc::derivation_method_t& out);
void from_json(const nlohmann::json& json, enable_eth_with_tokens_result_rpc::eth_address_infos_t& out);
void from_json(const nlohmann::json& json, enable_eth_with_tokens_result_rpc::erc20_address_infos_t& out);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <nlohmann/json.hpp>

#include "enable_slp_rpc.hpp"
#include "rpc2.enable_slp.hpp"

namespace atomic_dex::mm2
{
Expand Down
Loading
Loading