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

Feat: EVM Vault swaps support for Broker and affiliates #5408

Merged
merged 23 commits into from
Nov 14, 2024

Conversation

albert-llimos
Copy link
Contributor

@albert-llimos albert-llimos commented Nov 11, 2024

Checklist

Please conduct a thorough self-review before opening the PR.

  • I am confident that the code works.
  • I have written sufficient tests.
  • I have written and tested required migrations.
  • I have updated documentation where appropriate.

Summary

Add affiliates and broker account support for EVM Vault Swaps as a followup of #5389 .
Updates in SDK:
chainflip-io/chainflip-sdk-monorepo@e928861
chainflip-io/chainflip-sdk-monorepo@cbf09e2

@albert-llimos albert-llimos changed the title Feat/cf parameters broker affiliates Feat: EVM Vault swaps support for Broker and affiliates Nov 11, 2024
Copy link

codecov bot commented Nov 11, 2024

Codecov Report

Attention: Patch coverage is 59.57447% with 38 lines in your changes missing coverage. Please review.

Project coverage is 72%. Comparing base (66b295b) to head (2d44dfb).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
engine/src/witness/arb.rs 0% 17 Missing ⚠️
engine/src/witness/eth.rs 0% 12 Missing ⚠️
engine/src/witness/evm/vault.rs 0% 4 Missing ⚠️
state-chain/pallets/cf-ingress-egress/src/lib.rs 50% 4 Missing ⚠️
state-chain/primitives/src/lib.rs 0% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main   #5408    +/-   ##
======================================
- Coverage     72%     72%    -0%     
======================================
  Files        489     489            
  Lines      86812   86691   -121     
  Branches   86812   86691   -121     
======================================
- Hits       62339   62187   -152     
- Misses     21555   21578    +23     
- Partials    2918    2926     +8     

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

Copy link
Collaborator

@dandanlen dandanlen left a comment

Choose a reason for hiding this comment

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

LGTM but would like @msgmaxim to look over it too.

@@ -22,18 +26,26 @@ pub struct VaultSwapParameters {
pub refund_params: ChannelRefundParameters,
pub dca_params: Option<DcaParameters>,
pub boost_fee: Option<BasisPoints>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unrelated to this PR but just noticed this is Option<BasisPoints> - should it not just be BasisPoints? We can save a byte 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally when I wrote this my thought was that 1 byte makes no difference in any chain (not BTC as we don't use that there) and that it actually makes more sense to use None instead of boost of zero. However seeing that the extrinsic doesn't take an option it makes sense to remove that for consistency.
I'll change that, I can push it on top of this now that I'm also modifying the SDK.

Copy link
Contributor Author

@albert-llimos albert-llimos Nov 13, 2024

Choose a reason for hiding this comment

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

Technically the option saves one byte compared to using BasisPoints when boost is not being used, which is actually for all swaps as we don't support boost for any of these chains (EVM/SOL).
Makes sense to change it anyway for consistency as 1 byte makes no difference as per my previous comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or you could just use a single byte (u8) like we did for BTC 🙂

.expect("runtime supports at least as many affiliates as we allow in cf_parameters encoding"),
boost_fee: vault_swap_parameters.boost_fee.unwrap_or_default(),
dca_params: vault_swap_parameters.dca_params,
refund_params: Some(Box::new(vault_swap_parameters.refund_params)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

How come refund params are optional on the extrinsic but we never use None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess it's because we wanted to have some flexibility as we've been going back and forth between making this mandatory or not. I think we could consider removing the option since we are now enforcing it in Vault swaps. Wdyt? @dandanlen @msgmaxim

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, let's remove Option

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


const MAX_VAULT_SWAP_PARAMETERS_LENGTH: u32 = 1_000;
const MAX_CF_PARAM_LENGTH: u32 =
MAX_CCM_ADDITIONAL_DATA_LENGTH + MAX_VAULT_SWAP_PARAMETERS_LENGTH;

const REFERENCE_EXPECTED_ENCODED: &[u8] = &[
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe subjective, but I kind of like the way I broke down individual fields in check_utxo_encoding (https://github.com/chainflip-io/chainflip-backend/blob/main/state-chain/chains/src/btc/vault_swap_encoding.rs#L144) so we could see which bytes correspond to which field. Probably more important for BTC though where we were trying to compress the encoding.


// Extra byte for the empty ccm metadata
let mut expected_encoded = vec![0];
expected_encoded.extend_from_slice(REFERENCE_EXPECTED_ENCODED);
Copy link
Contributor

@msgmaxim msgmaxim Nov 14, 2024

Choose a reason for hiding this comment

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

Nit: I believe you can just convert to Vec with Vec::from (or alternatively compare slices with &encoded[..] or something like that)

Copy link
Contributor

@msgmaxim msgmaxim left a comment

Choose a reason for hiding this comment

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

Left some suggestions, but looks good, and happy to merge this either way.

@albert-llimos albert-llimos added this pull request to the merge queue Nov 14, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 14, 2024
@albert-llimos albert-llimos added this pull request to the merge queue Nov 14, 2024
Merged via the queue into main with commit 60d59a0 Nov 14, 2024
49 checks passed
@albert-llimos albert-llimos deleted the feat/cf-parameters-broker-affiliates branch November 14, 2024 11:24
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.

3 participants