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: Expose vault swaps from ingress-egress-tracker #5463

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

j4m1ef0rd
Copy link
Contributor

@j4m1ef0rd j4m1ef0rd commented Dec 4, 2024

Pull Request

Closes: PRO-1825

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

  • Refactored the tracker code to use proper traits instead of exploiting the from/into impls.
  • Added a new data enum VaultDeposit that gets stored in the database. It is stored using the key vault_deposit:{chain}:{tx_id}.
  • Added a unit test for the vault deposit.
  • For every vault deposit the tracker will call an RPC to get the brokers registered affiliates and map them to the short id's in the vault deposit data.
  • New Wrapper TrackerStateChainClient to assist with mocking RPC calls.

@j4m1ef0rd j4m1ef0rd requested a review from kylezs December 4, 2024 00:17
@j4m1ef0rd j4m1ef0rd self-assigned this Dec 4, 2024
Base automatically changed from feat/vault-swap-boost to main December 4, 2024 07:33
@j4m1ef0rd j4m1ef0rd force-pushed the feat/vault-swaps-in-tracker2 branch from 7c874b8 to 753fb2d Compare December 5, 2024 03:03
Copy link

codecov bot commented Dec 5, 2024

Codecov Report

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

Project coverage is 71%. Comparing base (1a6856c) to head (85dc30d).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
state-chain/chains/src/address.rs 48% 11 Missing ⚠️
...ne/src/state_chain_observer/client/base_rpc_api.rs 25% 3 Missing ⚠️
state-chain/chains/src/dot/serializable_address.rs 0% 3 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main   #5463    +/-   ##
======================================
- Coverage     72%     71%    -0%     
======================================
  Files        495     500     +5     
  Lines      88168   88263    +95     
  Branches   88168   88263    +95     
======================================
- Hits       63149   62889   -260     
- Misses     22450   22796   +346     
- Partials    2569    2578     +9     

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

@j4m1ef0rd j4m1ef0rd force-pushed the feat/vault-swaps-in-tracker2 branch 2 times, most recently from b6f28c0 to bc331f7 Compare December 5, 2024 05:45
@j4m1ef0rd j4m1ef0rd marked this pull request as ready for review December 9, 2024 00:09
@j4m1ef0rd j4m1ef0rd requested a review from a team as a code owner December 9, 2024 00:09
@j4m1ef0rd j4m1ef0rd requested review from zoheb391 and removed request for a team December 9, 2024 00:09
Copy link
Contributor

@niklasnatter niklasnatter 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 to me from a product perspective otherwise!

deposit_metadata: Option<CcmDepositMetadata>,
deposit_details: Option<DepositDetails>,
broker_fee: Beneficiary<AccountId32>,
affiliate_fees: Affiliates<AffiliateShortId>,
Copy link
Contributor

Choose a reason for hiding this comment

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

would be great to have the account ids instead of the short ids here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is turning out to be a non-trivial change. Can we leave this for a later update?

Copy link
Contributor

Choose a reason for hiding this comment

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

unfortunately we will need to do a separate rpc call to handle the short ids on our side, so i would really prefer to have them in redis

Copy link
Contributor

Choose a reason for hiding this comment

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

its fine for me to do that in a follow up pr obv, but that follow up should land before we start using 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.

I managed to get it working. Not the nicest, but it will do. At least we are one step closer to storing all swap data in redis. Shouldn't be too hard now to fetch the deposit channel data and get it in the db.

expression: "store.storage.get(\"vault_deposit:Ethereum:b5c8bd9430b6cc87a0e2fe110ece6bf527fa4f170a4bc8cd032f768fc5219838\").unwrap()"
snapshot_kind: text
---
{"affiliate_fees":[],"amount":"0x64","boost_fee":0,"broker_fee":{"account":"5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM","bps":0},"dca_params":null,"deposit_chain_block_height":1,"deposit_details":null,"deposit_metadata":null,"destination_address":{"Eth":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},"input_asset":{"asset":"ETH","chain":"Ethereum"},"output_asset":{"asset":"FLIP","chain":"Ethereum"},"refund_params":{"min_price":"0x0","refund_address":{"Eth":"0x541f563237a309b3a61e33bdf07a8930bdba8d99"},"retry_duration":0}}
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like the destination_address is formatted differently than the refund_adress here. think it would make sense to have them both exposed as string

Copy link
Contributor

Choose a reason for hiding this comment

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

would be cool to have some affiliates, dca params, ccm params in here to see the encoding

Copy link
Contributor

Choose a reason for hiding this comment

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

and the account id uses the substrate ss58 prefix instead of the cf prefix

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks fixed now

@j4m1ef0rd j4m1ef0rd force-pushed the feat/vault-swaps-in-tracker2 branch 2 times, most recently from 9a868fe to 0443269 Compare December 13, 2024 05:46
@kylezs kylezs self-assigned this Dec 16, 2024
@kylezs kylezs marked this pull request as draft December 16, 2024 04:16
@kylezs kylezs changed the title Expose vault swaps from ingress-egress-tracker feat: Expose vault swaps from ingress-egress-tracker Dec 16, 2024
@kylezs kylezs marked this pull request as ready for review December 16, 2024 05:09
@kylezs kylezs force-pushed the feat/vault-swaps-in-tracker2 branch from 5a92f35 to 536a354 Compare December 16, 2024 05:11
@dandanlen dandanlen force-pushed the feat/vault-swaps-in-tracker2 branch from bed8ed2 to c3da775 Compare December 16, 2024 10:29
Comment on lines +163 to +172
TransactionInIdForAnyChain::Bitcoin(hash) => hex::encode(hash.as_bytes()),
TransactionInIdForAnyChain::Evm(hash) => hex::encode(hash.as_bytes()),
TransactionInIdForAnyChain::Polkadot(transaction_id) => format!(
"{}-{}",
transaction_id.block_number, transaction_id.extrinsic_index
),
TransactionInIdForAnyChain::Solana((address, id)) => format!("{address}-{id}",),
TransactionInIdForAnyChain::MockEthereum(_) |
TransactionInIdForAnyChain::None => {
return Err(anyhow!("Invalid transaction id: {tx_id:?}"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should just impl Display for TransactionInIdForAnyChain ?

Comment on lines 212 to 222
#[async_trait]
trait DepositIntoWitnessInformation<C: Chain> {
async fn into_witness_information<StateChainClient>(
self,
height: <C as Chain>::ChainBlockNumber,
network: NetworkEnvironment,
state_chain_client: Arc<StateChainClient>,
) -> anyhow::Result<WitnessInformation>
where
StateChainClient: StorageApi + ChainApi + TrackerApi + 'static + Send + Sync;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like it can be simplified - no need for async or sc client? (Or result??)

Suggested change
#[async_trait]
trait DepositIntoWitnessInformation<C: Chain> {
async fn into_witness_information<StateChainClient>(
self,
height: <C as Chain>::ChainBlockNumber,
network: NetworkEnvironment,
state_chain_client: Arc<StateChainClient>,
) -> anyhow::Result<WitnessInformation>
where
StateChainClient: StorageApi + ChainApi + TrackerApi + 'static + Send + Sync;
}
trait DepositIntoWitnessInformation<C: Chain> {
async fn into_witness_information<StateChainClient>(
self,
height: <C as Chain>::ChainBlockNumber,
network: NetworkEnvironment,
) -> WitnessInformation;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

(Also, not sure we really need a macro)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually - this is pretty confusing - we have two macros for implementing the same trait 😅

impl_vault_deposit_into_witness_information!(Polkadot);
impl_vault_deposit_into_witness_information!(Arbitrum);

impl BroadcastIntoWitnessInformation for BroadcastDetails<Ethereum> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

... but no macro for this?

}
}

async fn save_deposit_witnesses<
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like we could simplify a lot if we query for a map of affiliate IDs in this method, and then pass that through, rather than threading the sc client (and attendant type constraints and async-ness) down through the whole call stack.

Comment on lines +408 to +411
if let Some(broadcast_details) =
get_broadcast_id::<I, StateChainClient>(state_chain_client, &tx_out_id)
.await
.map(|broadcast_id| BroadcastDetails::<I> { broadcast_id, tx_out_id, tx_ref })
Copy link
Collaborator

Choose a reason for hiding this comment

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

(...A bit like this approach)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants