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
Solana #1109
Solana #1109
Conversation
- Add a unit tests for the basis regarding the wallet - Add a skeleton SolanaCoin and SolanaCoinImpl that compiles - Had to modify one of the dependencies to compile locally, CI will not pass - Add base58 in the crate - Add ed25519 helpers - Add solana-sdk and solana-client 1.7.12
- Implement my_address()
# Conflicts: # Cargo.lock # mm2src/mm2_libp2p/Cargo.toml
mm2src/coins/solana/solana_common.rs
Outdated
let sol_required = lamports_to_sol(fees); | ||
if base_balance < sol_required { | ||
return MmError::err(SufficientBalanceError::NotSufficientBalance { | ||
coin: coin.ticker().to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add a method like base_coin_ticker
to either MarketCoinOps
or SolanaCommonOps
, because we check the balance of the base coin.
I wanted to add this method to MarketCoinOps
, but don't remember why I haven't done it.
Could you please investigate if we can add MarketCoinOps::base_coin_ticker
, and if it's impossible, add SolanaCommonOps::base_coin_ticker
.
It should work like MarketCoinOps::base_coin_balance
.
mm2src/coins/solana/solana_common.rs
Outdated
return MmError::err(SufficientBalanceError::NotSufficientBalance { | ||
coin: coin.ticker().to_string(), | ||
available: base_balance.clone(), | ||
required: &sol_required - &base_balance, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NotSufficientBalance::required
means the threshold, the minimum amount that we must have to perform this transfer.
So it should be required: sol_required
.
mm2src/coins/solana/solana_common.rs
Outdated
if to_send < sol_required && !coin.is_token() { | ||
return MmError::err(SufficientBalanceError::AmountTooLow { | ||
amount: to_send.clone(), | ||
threshold: &sol_required - &to_send, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the same :)
mm2src/coins/solana/solana_common.rs
Outdated
return MmError::err(SufficientBalanceError::NotSufficientBalance { | ||
coin: coin.ticker().to_string(), | ||
available: my_balance.clone(), | ||
required: &to_check - &my_balance, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
mm2src/coins/solana/solana_tests.rs
Outdated
let expected_spent_by_me = &request_amount + &sol_required; | ||
assert_eq!(valid_tx_details.spent_by_me, expected_spent_by_me); | ||
assert_eq!(valid_tx_details.received_by_me, request_amount); | ||
assert_eq!(valid_tx_details.total_amount, request_amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understood correctly, TransactionDetails::total_amount
has to be equal to TransactionDetails::spent_by_me
:
For UTXO, total_amount
is a sum of inputs
https://github.com/KomodoPlatform/atomicDEX-API/blob/03b0910362709eae9c2c0124932bfc295692da94/mm2src/coins/utxo/utxo_common.rs#L2430
For ETH, it's equal to spent_by_me
:
https://github.com/KomodoPlatform/atomicDEX-API/blob/03b0910362709eae9c2c0124932bfc295692da94/mm2src/coins/eth.rs#L629-L643
mm2src/coins/solana/solana_tests.rs
Outdated
valid_tx_details.received_by_me, | ||
BigDecimal::from_str("0.000095").unwrap() | ||
); | ||
assert_eq!(valid_tx_details.total_amount, BigDecimal::from_str("0.000105").unwrap()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This conclusion is wrong. total_amount
should equal to spent_by_me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more changes please :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last few things :)
mm2src/coins/lightning.rs
Outdated
@@ -387,6 +387,8 @@ impl MarketCoinOps for LightningCoin { | |||
Box::new(self.platform_coin().my_balance().map(|res| res.spendable)) | |||
} | |||
|
|||
fn base_coin_ticker(&self) -> &str { self.ticker() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with Lightning integration, but I think the ticker of LightningCoin
may be different from its base coin.
@shamardy could you please confirm or deny this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with Lightning integration, but I think the ticker of LightningCoin may be different from its base coin.
This is correct. this should be self.platform_coin().ticker()
mm2src/coins/test_coin.rs
Outdated
@@ -39,6 +39,8 @@ impl MarketCoinOps for TestCoin { | |||
|
|||
fn base_coin_balance(&self) -> BalanceFut<BigDecimal> { unimplemented!() } | |||
|
|||
fn base_coin_ticker(&self) -> &str { self.ticker() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified as unimplemented :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fixes! LGTM 🔥
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one non-blocker comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approve
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
This is my first attempt to implement a protocol at AtomicDEX, there may be a lot of errors.
Example of conf:
enable request:
enable answer:
Some information before reviewing
solana_decode_tx_helpers.rs
41XkzDsUKr9xE5JWCnLqYGBUUCsZqEpDaAc2fp1HuVwn926PXC81VfqgE2FxTo6UGSFdDWiGDai8J5zYrfHTS3Ke
(2 solutions for that I transformed tx_hash to be a String.account[0]
before [feature request] HD Wallet (multi-account) #740 is implemented: https://github.com/KomodoPlatform/atomicDEX-API/blob/4ab8e4c089cead9a9f3ec9d685306d1dca6e2789/mm2src/coins/solana/spl.rs#L148-L158withdraw
for SLP tokens use the instructiontransfer_checked
because this one gives more information when parsing transaction history and simplify the generation of transaction_details.withdraw
prerequisites for both SPL and Solana, would be nice if I can write a common function that can be used from both sides.What's implemented:
my_balance
: ✅base_coin_balance
: ✅withdraw
: ✅current_block
: ✅validate_address
: ✅decimals
: ✅is_asset_chain
: ✅display_priv_key
: ✅my_address
: ✅ticker
: ✅send_raw_tx
: ✅