feat(solana-swap): Implement basic maker functionality for SOL swaps#1
feat(solana-swap): Implement basic maker functionality for SOL swaps#1
Conversation
laruh
left a comment
There was a problem hiding this comment.
Thanks a lot for this feature!
I have some notes and questions.
PS: please commit Cargo.lock file, so security team (and devs actually) can see the whole deps tree. and it helps to be sure that all contributors have same deps.
shamardy
left a comment
There was a problem hiding this comment.
Thanks for the PR! First review iteration where the purpose is to make the code more readable to better review it in subsequent iterations.
src/satomic_swap.rs
Outdated
| { | ||
| let create_instruction = system_instruction::create_account( | ||
| sender_account.key, | ||
| vault_pda_data.key, | ||
| rent_exemption_lamports, | ||
| 41, | ||
| program_id, | ||
| ); | ||
|
|
||
| let account_infos = vec![ | ||
| sender_account.clone(), | ||
| vault_pda_data.clone(), | ||
| system_program_account.clone(), | ||
| ]; | ||
|
|
||
| invoke_signed(&create_instruction, &account_infos, &[vault_seeds_data])?; | ||
|
|
||
| let data = &mut vault_pda_data.try_borrow_mut_data()?; | ||
| if data.len() < payment_bytes.len() { | ||
| msg!("Error: Account data buffer too small"); | ||
| return Err(ProgramError::AccountDataTooSmall); | ||
| } | ||
|
|
||
| data[..payment_bytes.len()].copy_from_slice(&payment_bytes); | ||
| } |
There was a problem hiding this comment.
Why do you need this inner scope? I dont have compilation errors moving this inner scope operations to the outer.
To improve readability and maintainability please break the code into smaller well named functions, like Omer suggested.
Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas+instead@blockydevs.com>
…e transfer operation. Only sender and receiver are involved. Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas+instead@blockydevs.com>
Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas+instead@blockydevs.com>
* feat: Solana Swap with all of previous PR suggestions applied. * feat: Providing system_program_account should not be necessary for the transfer operation. Only sender and receiver are involved. * feat: Max line width fixed with cargo fmt
|
The latest commit does the following as stated by @mj-blockydevs
@mj-blockydevs @laruh let's continue the review here since @mj-blockydevs now has access to the repo. |
Will cover it in next review if there are any problems.
Code looks much better this way, thanks for this refactor.
Looks good on first look, will check it extensively in the next review iteration.
Will check them case by case in the review.
Unit tests for each module would be great to have but not necessary at this stage, it's up to you if you want to add them if there are no other higher priority items to finish first. |
shamardy
left a comment
There was a problem hiding this comment.
Thanks you for the fixes! Next review iteration!
| } | ||
|
|
||
| impl AtomicSwapInstruction { | ||
| pub fn unpack( |
There was a problem hiding this comment.
We should look into using borsh crate for serialization and deserialization instead of pack/unpack, maybe it will provide better performance but if not and the performance difference is negligible, using borsh will lead to less errors. This is not required in this PR but we should look into it in the future when completing the swap program for v1 and v2 swaps.
| vault_seeds_data, | ||
| payment_bytes, | ||
| )?; | ||
|
|
There was a problem hiding this comment.
I guess we need to transfer the tokens here.
There was a problem hiding this comment.
Yes, I'll leave comments in the code to remind us about it. However, it is out of scope for now. We will address this issue in a separate PR.
| if token_program != Pubkey::new_from_array([0; 32]) { | ||
| return Err(ProgramError::Custom(NOT_SUPPORTED)); | ||
| } | ||
| transfer_lamports(vault_pda, receiver_account, vault_seeds, amount)?; |
There was a problem hiding this comment.
We need also to add the case of tokens transfer here
| if token_program != Pubkey::new_from_array([0; 32]) { | ||
| return Err(ProgramError::Custom(NOT_SUPPORTED)); | ||
| } | ||
| transfer_lamports(vault_pda, sender_account, vault_seeds, amount)?; |
| use crate::error_code::{INVALID_PAYMENT_HASH, INVALID_PAYMENT_STATE, SWAP_ACCOUNT_NOT_FOUND}; | ||
| use crate::payment::{Payment, PaymentState}; | ||
| use solana_program::{ | ||
| account_info::AccountInfo, entrypoint::ProgramResult, program::invoke_signed, | ||
| program_error::ProgramError, system_instruction, | ||
| }; |
There was a problem hiding this comment.
I suppose there is a lack of spl_token crate usage to provide transfer_spl_tokens implementation
There was a problem hiding this comment.
Yes, it will be necessary to support token transfers. This will be implemented later.
Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas+instead@blockydevs.com>
Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas+instead@blockydevs.com>
Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas+instead@blockydevs.com>
Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas+instead@blockydevs.com>
There was a problem hiding this comment.
AtomicSwapInstruction/pack/unpack and the error codes are duplicated/used here GLEECBTC/komodo-defi-framework#2091, I suggest removing them from #2091 once this PR is merged and import them from this repo/crate. Then we would need to edit them only in one place in the future if the need arises.
Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas+instead@blockydevs.com>
Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas+instead@blockydevs.com>
Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas+instead@blockydevs.com>
Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas+instead@blockydevs.com>
No description provided.