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: Affiliate Broker Registration and Lookup for Vault Swaps #5389

Merged
merged 15 commits into from
Nov 13, 2024

Conversation

msgmaxim
Copy link
Contributor

@msgmaxim msgmaxim commented Nov 7, 2024

Pull Request

Closes: PRO-1750, PRO-1751

Summary

  • Brokers can register affiliates through the swapping pallet to assign them short ids. Brokers are expected to provide short id that they want to use (rather than SC deciding on their behalf), which also means that they can overwrite existing entries if they want (this can be useful since we only support 256 entries). The new AffiliateRegistrationUpdated event includes (among other things) Option<AccountId> for the entry that is being replaced (most likely to be used as a sanity check to see that they haven't overwritten anything).

  • vault_swap_request extrinsic now takes Option<(Beneficiary<T::AccountId>, Affiliates<AffiliateShortId>)> where the primary broker is AccountId and affiliate brokers are "short ids" (u8). Short affialite ids are converted to full AccountIds using affiliate registry (added a new trait for this).

  • BTC witnesser now passes decoded broker id and affiliate short ids into the vault_swap_request call. This hasn't been done for other chains, but should be trivial to add ones primary broker id can be decoded there (I believe @albert-llimos is working on this).

  • A small refactor in the testing/mock code: moved mock_eth and mock_btc under the new mocks module so that they can share code in a more sensible way (they now share the new MockAffiliateRegistry, which I didn't put under cf_traits sincie it is unlikely that it will be used by any other pallet).

Copy link

codecov bot commented Nov 8, 2024

Codecov Report

Attention: Patch coverage is 81.36095% with 63 lines in your changes missing coverage. Please review.

Project coverage is 71%. Comparing base (420429c) to head (d20abf6).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
state-chain/pallets/cf-swapping/src/weights.rs 0% 18 Missing ⚠️
engine/src/witness/btc/deposits.rs 0% 17 Missing ⚠️
state-chain/pallets/cf-swapping/src/lib.rs 71% 10 Missing ⚠️
engine/src/witness/arb.rs 0% 6 Missing ⚠️
engine/src/witness/eth.rs 0% 6 Missing ⚠️
state-chain/pallets/cf-ingress-egress/src/lib.rs 91% 3 Missing ⚠️
state-chain/pallets/cf-swapping/src/mock.rs 0% 3 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main   #5389    +/-   ##
======================================
- Coverage     72%     71%    -0%     
======================================
  Files        487     489     +2     
  Lines      86183   86508   +325     
  Branches   86183   86508   +325     
======================================
+ Hits       61633   61768   +135     
- Misses     21636   21828   +192     
+ Partials    2914    2912     -2     

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

@msgmaxim msgmaxim marked this pull request as ready for review November 8, 2024 04:55
@albert-llimos
Copy link
Contributor

albert-llimos commented Nov 8, 2024

BTC witnesser now passes decoded broker id and affiliate short ids into the vault_swap_request call. This hasn't been done for other chains, but should be trivial to add ones primary broker id can be decoded there (I believe @albert-llimos is working on this).

Yes, I'll get that done.

engine/src/witness/btc/deposits.rs Outdated Show resolved Hide resolved
engine/src/witness/btc/vault_swaps.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines 104 to 105
pub type AffiliateShortId = u8;

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can use define_wrapper_type now to make this a bit more type-safe.

Comment on lines 85 to 86
// TODO: provide broker id (along with broker fees) in the call
for (_maybe_broker_id, vault_address) in vault_addresses {
for (maybe_broker_id, vault_address) in vault_addresses {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The TODO comment can be removed now?

state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-ingress-egress/src/mocks.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-swapping/src/lib.rs Outdated Show resolved Hide resolved
@msgmaxim
Copy link
Contributor Author

msgmaxim commented Nov 12, 2024

Addressed all comments now @dandanlen. I also added a check that primary broker is registered as a broker. I chose to just ignore broker fields if the broker is unknown (after emitting a new event), which seems like a reasonable fallback behaviour. If we decide to refund instead, I think this can probably done separately.

@albert-llimos
Copy link
Contributor

If we decide to refund instead, I think this can probably done separately.

For now I'd use the fallback as there doesn't seem to be any strong argument (or anyone) pushing for refunding instead. The current behavior sounds good to me.

@dandanlen dandanlen changed the title Feat: Affiliate Broker Registration and Lookup for Vault Swaps feat: Affiliate Broker Registration and Lookup for Vault Swaps Nov 12, 2024
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.

👌

state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +2237 to +2238
// In case the entry not found, we ignore the entry, but process the
// swap (to avoid having to refund it).
Copy link
Collaborator

Choose a reason for hiding this comment

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

👌

Comment on lines 2252 to 2255
Self::deposit_event(Event::<T, I>::UnknownPrimaryBroker {
broker_id: primary_broker,
});
Default::default()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have a Linear issue to deal with this ie. what to do as fallback? We should probably store the data somewhere so we can reject the deposit / trigger a swap.

Copy link
Contributor Author

@msgmaxim msgmaxim Nov 13, 2024

Choose a reason for hiding this comment

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

But we already do trigger a swap. We can consider refunding of course, but I figured this needs some discussion first. Storing which data are you talking about tough?

Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed I've opened a triage issue PRO-1804

I think we might be able to take the same path as we do for transaction screening.

@msgmaxim msgmaxim added this pull request to the merge queue Nov 13, 2024
Merged via the queue into main with commit 1ee66a6 Nov 13, 2024
49 checks passed
@msgmaxim msgmaxim deleted the feat/affiliate-registration branch November 13, 2024 02:36
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