-
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: New vault swap encoding RPC & bouncer test #5384
Conversation
@@ -86,20 +84,6 @@ pub trait Rpc { | |||
asset: Asset, | |||
destination_address: AddressString, | |||
) -> RpcResult<WithdrawFeesDetail>; | |||
|
|||
#[method(name = "request_swap_parameter_encoding", aliases = ["broker_requestSwapParameterEncoding"])] | |||
async fn request_swap_parameter_encoding( |
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 think we want to keep this in the broker api, and pass it through to the custom rpc.
state-chain/custom-rpc/src/lib.rs
Outdated
#[derive(Clone, Serialize, Deserialize)] | ||
pub enum EncodedVaultSwapParamsBytes { |
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 think it would be nice to use internally tagged enum variants here.
#[derive(Clone, Serialize, Deserialize)] | |
pub enum EncodedVaultSwapParamsBytes { | |
#[derive(Clone, Serialize, Deserialize)] | |
#[serde(tag = "chain")] | |
pub enum EncodedVaultSwapParamsBytes { |
state-chain/custom-rpc/src/lib.rs
Outdated
@@ -68,6 +69,33 @@ use std::{ | |||
pub mod monitoring; | |||
pub mod order_fills; | |||
|
|||
#[derive(Clone, Serialize, Deserialize)] | |||
pub struct VaultSwapDetailsHumanreadable { | |||
pub deposit_address: ForeignChainAddressHumanreadable, |
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.
We won't need to return an address for every chain - it's only for bitcoin where it depends on the broker_id and current epoch. For other chains there is a vault contract, which is static. We can still return this static address I suppose but calling it a deposit_address is not always accurate.
I would suggest putting this inside the enum's bitcoin variant.
|
||
#[derive(PartialEq, Eq, Clone, Encode, Decode, TypeInfo, Serialize, Deserialize)] | ||
pub enum EncodedVaultSwapParams { | ||
Bitcoin { nulldata_utxo: Vec<u8> }, |
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.
Let's just use Bytes
everywhere?
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.
Bytes does not have TypeInfo, which the runtime apis need for some reason.
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.
Oh yeah... helpful.
I had a dig, we can do this:
Bitcoin {
#[serde(with = "sp_core::bytes")]
nulldata_utxo: Vec<u8> },
}
type VanityName = Vec<u8>; | ||
|
||
#[derive(PartialEq, Eq, Clone, Encode, Decode, TypeInfo, Serialize, Deserialize)] | ||
pub struct VaultSwapDetails { | ||
pub deposit_address: ForeignChainAddress, |
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.
We can do the conversion in the runtime so we don't need separate types here vs in the rpc layer.
Take a look at chainflip::ChainAddressConverter
.
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 was unable to find a easy way to output the address as hex without using 2 structs or changing EncodedAddress
.
state-chain/runtime/src/lib.rs
Outdated
output_address: to_encoded_address( | ||
destination_address, | ||
Environment::network_environment, | ||
), |
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.
output_address: to_encoded_address( | |
destination_address, | |
Environment::network_environment, | |
), | |
output_address: ChainAddressConverter::to_encoded_address( | |
destination_address, | |
), |
state-chain/runtime/src/lib.rs
Outdated
.unwrap_or(1) | ||
.try_into() | ||
.map_err(|_| { | ||
Into::<DispatchErrorWithMessage>::into(DispatchError::from( |
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.
These error conversions are quite repetitive - maybe we just need to write the correct From
implementation for DispatchErrorWithMessage?
At the very least we could write a struct method to make this more readable. Something like this might do the trick:
impl DispatchErrorWithMessage {
pub fn from_pallet_error(e: impl Into<DispatchError>) {
Self::from(e.into())
}
}
state-chain/runtime/src/lib.rs
Outdated
chunk_interval: dca_parameters | ||
.as_ref() | ||
.map(|params| params.chunk_interval) | ||
.unwrap_or(2) |
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.
Can we avoid using a magic number here? Isn't there a constant defined in the swapping pallet?
state-chain/runtime/src/lib.rs
Outdated
let btc_key = pallet_cf_threshold_signature::Pallet::<Runtime, BitcoinInstance>::keys( | ||
pallet_cf_threshold_signature::Pallet::<Runtime, BitcoinInstance>::current_key_epoch().unwrap()).unwrap(); |
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.
If you import the KeyProvider trait you can use BitcoinThresholdSigner::active_epoch_key()
for this.
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.
This code will get removed when i hook it up to the private channels, so i will leave it for now.
state-chain/runtime/src/lib.rs
Outdated
let deposit_address = ForeignChainAddress::Btc( | ||
cf_chains::btc::deposit_address::DepositAddress::new(btc_key.current, 0) | ||
.script_pubkey(), | ||
); |
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.
We can convert to an EncodedAddress here.
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.
If I output as EncodedAddress
it will not be a hex string.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5384 +/- ##
======================================
- Coverage 72% 71% -0%
======================================
Files 486 486
Lines 85973 85977 +4
Branches 85973 85977 +4
======================================
- Hits 61526 61383 -143
- Misses 21586 21662 +76
- Partials 2861 2932 +71 ☔ View full report in Codecov by Sentry. |
LGTM now, but I made some changes/refactors:
|
state-chain/runtime/src/lib.rs
Outdated
.script_pubkey(), | ||
); | ||
let EpochKey { key, .. } = BitcoinThresholdSigner::active_epoch_key() | ||
.expect("We should always have a for the current epoch."); |
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.
We should always have a key for the current epoch.
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.
even before vault setup on a localnet?
Main reason was that it breaks the new vault swap bouncer test. I have another PR with this all working. |
Pull Request
Closes: PRO-1754 & PRO-1752
Checklist
Please conduct a thorough self-review before opening the PR.
Summary
TODO
RpcError: -32603: {error}
.