Skip to content

Commit

Permalink
feat(solana-swap): solana swap protocol v1 POC (#2091)
Browse files Browse the repository at this point in the history
This commit Implementats the following SwapOps trait methods for SolanaCoin:
- send_maker_payment
- send_taker_spends_maker_payment
- send_maker_refunds_payment

It also adds Tests for sending, spending and refunding of maker payments.
  • Loading branch information
r2st authored Jun 24, 2024
1 parent d9d1229 commit 2e0b3ca
Show file tree
Hide file tree
Showing 7 changed files with 498 additions and 66 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion mm2src/coins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ enable-solana = [
"dep:solana-sdk",
"dep:solana-transaction-status",
"dep:spl-token",
"dep:spl-associated-token-account"
"dep:spl-associated-token-account",
"dep:satomic-swap"
]
enable-sia = [
"dep:reqwest",
Expand Down Expand Up @@ -92,6 +93,7 @@ rlp = { version = "0.5" }
rmp-serde = "0.14.3"
rpc = { path = "../mm2_bitcoin/rpc" }
rpc_task = { path = "../rpc_task" }
satomic-swap = { git = "https://github.com/KomodoPlatform/satomic-swap.git", rev = "413e472", optional = true }
script = { path = "../mm2_bitcoin/script" }
secp256k1 = { version = "0.20" }
ser_error = { path = "../derives/ser_error" }
Expand Down
34 changes: 31 additions & 3 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ use std::time::Duration;
use std::{fmt, iter};
use utxo_signer::with_key_pair::UtxoSignWithKeyPairError;
use zcash_primitives::transaction::Transaction as ZTransaction;

cfg_native! {
use crate::lightning::LightningCoin;
use crate::lightning::ln_conf::PlatformCoinConfirmationTargets;
Expand Down Expand Up @@ -125,6 +124,29 @@ macro_rules! try_f {
};
}

#[cfg(feature = "enable-solana")]
macro_rules! try_tx_fus_err {
($err: expr) => {
return Box::new(futures01::future::err(crate::TransactionErr::Plain(ERRL!(
"{:?}", $err
))))
};
}

#[cfg(feature = "enable-solana")]
macro_rules! try_tx_fus_opt {
($e: expr, $err: expr) => {
match $e {
Some(ok) => ok,
None => {
return Box::new(futures01::future::err(crate::TransactionErr::Plain(ERRL!(
"{:?}", $err
))))
},
}
};
}

/// `TransactionErr` compatible `try_fus` macro.
macro_rules! try_tx_fus {
($e: expr) => {
Expand Down Expand Up @@ -276,7 +298,7 @@ pub use solana::spl::SplToken;
not(target_os = "android"),
not(target_arch = "wasm32")
))]
pub use solana::{SolanaActivationParams, SolanaCoin, SolanaFeeDetails};
pub use solana::{SolTransaction, SolanaActivationParams, SolanaCoin, SolanaFeeDetails};

pub mod utxo;
use utxo::bch::{bch_coin_with_policy, BchActivationRequest, BchCoin};
Expand Down Expand Up @@ -607,6 +629,8 @@ pub trait Transaction: fmt::Debug + 'static {
pub enum TransactionEnum {
UtxoTx(UtxoTx),
SignedEthTx(SignedEthTx),
#[cfg(all(feature = "enable-solana", not(target_arch = "wasm32")))]
SolTransaction(SolTransaction),
ZTransaction(ZTransaction),
CosmosTransaction(CosmosTransaction),
#[cfg(not(target_arch = "wasm32"))]
Expand All @@ -615,6 +639,8 @@ pub enum TransactionEnum {

ifrom!(TransactionEnum, UtxoTx);
ifrom!(TransactionEnum, SignedEthTx);
#[cfg(all(feature = "enable-solana", not(target_arch = "wasm32")))]
ifrom!(TransactionEnum, SolTransaction);
ifrom!(TransactionEnum, ZTransaction);
#[cfg(not(target_arch = "wasm32"))]
ifrom!(TransactionEnum, LightningPayment);
Expand All @@ -638,6 +664,8 @@ impl Deref for TransactionEnum {
TransactionEnum::CosmosTransaction(ref t) => t,
#[cfg(not(target_arch = "wasm32"))]
TransactionEnum::LightningPayment(ref p) => p,
#[cfg(all(feature = "enable-solana", not(target_arch = "wasm32")))]
TransactionEnum::SolTransaction(ref s) => s,
}
}
}
Expand Down Expand Up @@ -4843,7 +4871,7 @@ pub async fn my_tx_history(ctx: MmArc, req: Json) -> Result<Response<Vec<u8>>, S
}

/// `get_trade_fee` rpc implementation.
/// There is some consideration about this rpc:
/// There is some consideration about this rpc:
/// for eth coin this rpc returns max possible trade fee (estimated for maximum possible gas limit for any kind of swap).
/// However for eth coin, as part of fixing this issue https://github.com/KomodoPlatform/komodo-defi-framework/issues/1848,
/// `max_taker_vol' and `trade_preimage` rpc now return more accurate required gas calculations.
Expand Down
Loading

0 comments on commit 2e0b3ca

Please sign in to comment.