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

refactor deposit_and_call and deposit_spl_token_and_call #35

Merged
merged 8 commits into from
Oct 3, 2024

Conversation

brewmaster012
Copy link
Contributor

@brewmaster012 brewmaster012 commented Oct 2, 2024

  • refactor deposit spl token into two functions, one just deposit, and the other deposit and call.

  • Refactor deposit_and_call and deposit_spl_token_and_call to reuse the deposit and deposit_spl_token.

  • added some comments on the instruction processors.

@brewmaster012 brewmaster012 marked this pull request as ready for review October 2, 2024 15:44
@codecov-commenter
Copy link

codecov-commenter commented Oct 2, 2024

Codecov Report

Attention: Patch coverage is 0% with 17 lines in your changes missing coverage. Please review.

Project coverage is 8.60%. Comparing base (2989d9a) to head (0d81e93).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
programs/protocol-contracts-solana/src/lib.rs 0.00% 17 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main     #35      +/-   ##
========================================
+ Coverage   8.43%   8.60%   +0.17%     
========================================
  Files          1       1              
  Lines        249     244       -5     
========================================
  Hits          21      21              
+ Misses       228     223       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@brewmaster012 brewmaster012 force-pushed the deposit-spl-and-call branch 2 times, most recently from 6316158 to 1c8c70c Compare October 2, 2024 19:17
Copy link
Contributor

@skosito skosito left a comment

Choose a reason for hiding this comment

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

looks good, just minor comments

message,
);

deposit(ctx, amount, receiver)?;
Ok(())
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this Ok(()) here since there is one in deposit, probably redundant here

Copy link
Contributor

Choose a reason for hiding this comment

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

also why some methods have #[allow(unused)]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we want to get rid of the Ok(()) at the end, it would look something like:

        Ok(deposit_spl_token(ctx, amount, receiver)?)

at the end; not sure i like this better than with the Ok(()) at the end; natuarally all instructions should have Ok(()) at the end.

Copy link
Contributor Author

@brewmaster012 brewmaster012 Oct 3, 2024

Choose a reason for hiding this comment

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

for the #[allow(unused)], it's for the unused paramter message or receiver
These two are not useful in this solana program; they are just instructions for zetachain cctx processing.
As Solana does not really have typed event, we'll just use instruction parameter instead. At least they are typed.
I don't want to precede them with _message, _receiver, hence #[allow(unused)] for silencing warning.

Copy link
Contributor

Choose a reason for hiding this comment

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

got it, thanks for info
regarding Ok, i thought the one in deposit will finish instruction and return to caller and this one would never be reached, but i dont know if that is true when one instruction is called from another, its ok to keep it here anyways

receiver: [u8; 20],
message: Vec<u8>,
) -> Result<()> {
require!(message.len() <= 512, Errors::MemoLengthExceeded);
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want old memo.len() >= 20 condition as well? if not and MemoLengthTooShort is not used anymore we can remove it

Copy link
Contributor

Choose a reason for hiding this comment

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

also is this message length check something we need on GatewayEVM as well, to be compatible or is it solana specific?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

message could be less than 20 bytes. I guess we could remove the error MemoLengthTooShort

There is a restriction on size of Solana tx (1023B??). Might as well have a limit in the instruction.
Not sure we want to have the same limit across all networks though.

Copy link
Contributor

Choose a reason for hiding this comment

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

got it, yes limit is 1232
we can maybe write a test to break this condition and test upper bound edge case, to be sure if limit can be this number

Ok(())
}

// require tss address signature on the internal message defined in the following
Copy link
Contributor

Choose a reason for hiding this comment

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

i think we can add issue to write comments in same format for all functions, something like

// description...
// param1 explanation
...
// paramN explanation

in solidity there is natspec, but couldnt find same for solana contracts, but we can make some format

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea. let me try something.

// deposit SOL into this program and the `receiver` on ZetaChain zEVM
// will get corresponding ZRC20 credit. The `receiver` should be a contract
// on zEVM and the `message` will be used as input data for the contract call.
// The `receiver` contract on zEVM will get the SOL ZRC20 credit and receive the `message`.
pub fn deposit_and_call(
ctx: Context<Deposit>,
amount: u64,
receiver: [u8; 20],
message: Vec<u8>,
) -> Result<()> {
require!(message.len() <= 512, Errors::MemoLengthExceeded);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check also for message.len too short?

Copy link
Contributor

Choose a reason for hiding this comment

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

there is comment above saying it can be smaller than 20, but maybe we can check for 0 value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

0 size message seems to be no problem; the app contract can expect empty message; maybe there is use case for that. Let's not be too pedantic here.

message,
);

deposit(ctx, amount, receiver)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

How/where do we emit the message so zEVM receives it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the function parameter

@brewmaster012
Copy link
Contributor Author

going to merge this PR, and do more regimented documentation in another PR.

@brewmaster012 brewmaster012 merged commit 98bd5c3 into main Oct 3, 2024
13 checks passed
@brewmaster012 brewmaster012 deleted the deposit-spl-and-call branch October 3, 2024 17:13
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.

4 participants