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

Solana #1109

Merged
merged 117 commits into from Mar 31, 2022
Merged

Solana #1109

merged 117 commits into from Mar 31, 2022

Conversation

Milerius
Copy link

@Milerius Milerius commented Oct 15, 2021

This is my first attempt to implement a protocol at AtomicDEX, there may be a lot of errors.


Example of conf:

{
      "coin": "TSOL",
      "name": "solana testnet",
      "fname": "Solana testnet",
      "mm2": 1,
      "decimals": 8,
      "wallet_only": true,
      "protocol": {
        "type": "SOLANA"
      }
  },

enable request:

{
    "coin": "TSOL",
    "commitment_level": "Finalized",
    "method": "enable",
    "tx_history": false,
    "urls": [
        "https://api.testnet.solana.com"
    ],
    "userpass": "simplepassword123"
}

enable answer:

 {
        "result": "success",
        "address": "FJktmyjV9aBHEShT4hfnLpr9ELywdwVtEL1w1rSWgbVf",
        "balance": "1.999860000000000",
        "unspendable_balance": "0",
        "coin": "TSOL",
        "required_confirmations": 1,
        "requires_notarization": false
}

Some information before reviewing

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: ✅

- 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
# Conflicts:
#	Cargo.lock
#	mm2src/mm2_libp2p/Cargo.toml
let sol_required = lamports_to_sol(fees);
if base_balance < sol_required {
return MmError::err(SufficientBalanceError::NotSufficientBalance {
coin: coin.ticker().to_string(),

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.

return MmError::err(SufficientBalanceError::NotSufficientBalance {
coin: coin.ticker().to_string(),
available: base_balance.clone(),
required: &sol_required - &base_balance,

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.

if to_send < sol_required && !coin.is_token() {
return MmError::err(SufficientBalanceError::AmountTooLow {
amount: to_send.clone(),
threshold: &sol_required - &to_send,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the same :)

return MmError::err(SufficientBalanceError::NotSufficientBalance {
coin: coin.ticker().to_string(),
available: my_balance.clone(),
required: &to_check - &my_balance,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

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);

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

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());

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

Copy link

@sergeyboyko0791 sergeyboyko0791 left a 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 :)

Copy link

@sergeyboyko0791 sergeyboyko0791 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last few things :)

@@ -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() }

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?

Copy link
Collaborator

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()

@@ -39,6 +39,8 @@ impl MarketCoinOps for TestCoin {

fn base_coin_balance(&self) -> BalanceFut<BigDecimal> { unimplemented!() }

fn base_coin_ticker(&self) -> &str { self.ticker() }

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 :)

Copy link

@sergeyboyko0791 sergeyboyko0791 left a 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 🔥

Copy link
Collaborator

@shamardy shamardy left a 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

mm2src/coins/utxo/slp.rs Outdated Show resolved Hide resolved
Copy link

@sergeyboyko0791 sergeyboyko0791 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve

Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Protocol Integration]: Solana
4 participants