-
Notifications
You must be signed in to change notification settings - Fork 15
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
Changes from 20 commits
228cbef
6add0fc
ab416fe
269745f
f6a2ec8
693b992
8d07d54
b6b62ae
c607c8e
fab6ad1
01455b6
ba6fe7b
7a3b94a
1e6a3da
5ebde8a
3dde9e2
44736e6
22967a2
575915f
2930e68
d807601
53d82dd
2d44dfb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
use cf_chains::{CcmAdditionalData, ChannelRefundParameters}; | ||
use cf_primitives::{AffiliateShortId, BasisPoints, Beneficiaries, DcaParameters}; | ||
use cf_primitives::{ | ||
AccountId, AffiliateAndFee, BasisPoints, Beneficiary, DcaParameters, MAX_AFFILIATES, | ||
}; | ||
use codec::{Decode, Encode, MaxEncodedLen}; | ||
use scale_info::TypeInfo; | ||
use sp_core::ConstU32; | ||
use sp_runtime::BoundedVec; | ||
|
||
#[derive(Encode, Decode, MaxEncodedLen, TypeInfo, Clone, PartialEq, Debug)] | ||
pub enum VersionedCfParameters<CcmData = ()> { | ||
|
@@ -21,19 +25,27 @@ pub type VersionedCcmCfParameters = VersionedCfParameters<CcmAdditionalData>; | |
pub struct VaultSwapParameters { | ||
pub refund_params: ChannelRefundParameters, | ||
pub dca_params: Option<DcaParameters>, | ||
pub boost_fee: Option<BasisPoints>, | ||
pub broker_fees: Beneficiaries<AffiliateShortId>, | ||
pub boost_fee: BasisPoints, | ||
pub broker_fee: Beneficiary<AccountId>, | ||
pub affiliate_fees: BoundedVec<AffiliateAndFee, ConstU32<MAX_AFFILIATES>>, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use cf_chains::MAX_CCM_ADDITIONAL_DATA_LENGTH; | ||
use cf_chains::{ChannelRefundParameters, ForeignChainAddress, MAX_CCM_ADDITIONAL_DATA_LENGTH}; | ||
|
||
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] = &[ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
0, 1, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | ||
3, 3, 3, 4, 0, 0, | ||
]; | ||
|
||
#[test] | ||
fn test_cf_parameters_max_length() { | ||
assert!( | ||
|
@@ -44,4 +56,41 @@ mod tests { | |
MAX_VAULT_SWAP_PARAMETERS_LENGTH as usize >= VaultSwapParameters::max_encoded_len() | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_versioned_cf_parameters() { | ||
let vault_swap_parameters = VaultSwapParameters { | ||
refund_params: ChannelRefundParameters { | ||
retry_duration: 1, | ||
refund_address: ForeignChainAddress::Eth(sp_core::H160::from([2; 20])), | ||
min_price: Default::default(), | ||
}, | ||
dca_params: None, | ||
boost_fee: 0, | ||
broker_fee: Beneficiary { account: AccountId::new([3; 32]), bps: 4 }, | ||
affiliate_fees: sp_core::bounded_vec![], | ||
}; | ||
|
||
let cf_parameters = CfParameters::<()> { | ||
ccm_additional_data: (), | ||
vault_swap_parameters: vault_swap_parameters.clone(), | ||
}; | ||
|
||
let mut encoded = VersionedCfParameters::V0(cf_parameters).encode(); | ||
|
||
assert_eq!(encoded, REFERENCE_EXPECTED_ENCODED); | ||
|
||
let ccm_cf_parameters = CfParameters { | ||
ccm_additional_data: CcmAdditionalData::default(), | ||
vault_swap_parameters, | ||
}; | ||
|
||
encoded = VersionedCcmCfParameters::V0(ccm_cf_parameters).encode(); | ||
|
||
// Extra byte for the empty ccm metadata | ||
let mut expected_encoded = vec![0]; | ||
expected_encoded.extend_from_slice(REFERENCE_EXPECTED_ENCODED); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I believe you can just convert to Vec with |
||
|
||
assert_eq!(encoded, expected_encoded); | ||
} | ||
} |
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.
How come refund params are optional on the extrinsic but we never use None?
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 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
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.
Yeah, let's remove
Option
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.
Done